mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(backend/copilot): capture tool results in transcript
Tool results (StreamToolOutputAvailable) were being added to session.messages but NOT to transcript_builder, causing the transcript to miss tool executions. This made the copilot claim '(no tool used)' when tools were actually called. Now tool results are captured as user messages with tool_result content blocks, matching the Claude API transcript format and ensuring --resume has complete conversation history including all tool interactions.
This commit is contained in:
@@ -1355,17 +1355,28 @@ async def stream_chat_completion_sdk(
|
||||
has_appended_assistant = True
|
||||
|
||||
elif isinstance(response, StreamToolOutputAvailable):
|
||||
tool_result_content = (
|
||||
response.output
|
||||
if isinstance(response.output, str)
|
||||
else str(response.output)
|
||||
)
|
||||
session.messages.append(
|
||||
ChatMessage(
|
||||
role="tool",
|
||||
content=(
|
||||
response.output
|
||||
if isinstance(response.output, str)
|
||||
else str(response.output)
|
||||
),
|
||||
content=tool_result_content,
|
||||
tool_call_id=response.toolCallId,
|
||||
)
|
||||
)
|
||||
# Capture tool result in transcript as user message with tool_result content
|
||||
transcript_builder.add_user_message(
|
||||
content=[
|
||||
{
|
||||
"type": "tool_result",
|
||||
"tool_use_id": response.toolCallId,
|
||||
"content": tool_result_content,
|
||||
}
|
||||
]
|
||||
)
|
||||
has_tool_results = True
|
||||
|
||||
elif isinstance(response, StreamFinish):
|
||||
|
||||
Reference in New Issue
Block a user