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:
Zamil Majdy
2026-03-06 22:35:12 +07:00
parent d56452898a
commit 89ed628609

View File

@@ -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):