fix(subagent): preserve reasoning fields across tool turns

Share assistant message construction between the main agent and subagents, and add a regression test to keep reasoning_content and thinking_blocks in follow-up tool rounds.
This commit is contained in:
Re-bin
2026-03-11 03:47:24 +00:00
parent 1d611f9bf3
commit ddccf25bb1
4 changed files with 74 additions and 23 deletions
+7 -9
View File
@@ -10,7 +10,7 @@ from typing import Any
from nanobot.agent.memory import MemoryStore
from nanobot.agent.skills import SkillsLoader
from nanobot.utils.helpers import detect_image_mime
from nanobot.utils.helpers import build_assistant_message, detect_image_mime
class ContextBuilder:
@@ -182,12 +182,10 @@ Reply directly with text for conversations. Only use the 'message' tool to send
thinking_blocks: list[dict] | None = None,
) -> list[dict[str, Any]]:
"""Add an assistant message to the message list."""
msg: dict[str, Any] = {"role": "assistant", "content": content}
if tool_calls:
msg["tool_calls"] = tool_calls
if reasoning_content is not None:
msg["reasoning_content"] = reasoning_content
if thinking_blocks:
msg["thinking_blocks"] = thinking_blocks
messages.append(msg)
messages.append(build_assistant_message(
content,
tool_calls=tool_calls,
reasoning_content=reasoning_content,
thinking_blocks=thinking_blocks,
))
return messages
+7 -14
View File
@@ -16,6 +16,7 @@ from nanobot.bus.events import InboundMessage
from nanobot.bus.queue import MessageBus
from nanobot.config.schema import ExecToolConfig
from nanobot.providers.base import LLMProvider
from nanobot.utils.helpers import build_assistant_message
class SubagentManager:
@@ -133,7 +134,6 @@ class SubagentManager:
)
if response.has_tool_calls:
# Add assistant message with tool calls
tool_call_dicts = [
{
"id": tc.id,
@@ -145,19 +145,12 @@ class SubagentManager:
}
for tc in response.tool_calls
]
assistant_msg: dict[str, Any] = {
"role": "assistant",
"content": response.content or "",
"tool_calls": tool_call_dicts,
}
# Preserve reasoning_content for providers that require it
# (e.g. Deepseek Reasoner mandates this field on every
# assistant message when thinking mode is active).
if response.reasoning_content is not None:
assistant_msg["reasoning_content"] = response.reasoning_content
if response.thinking_blocks:
assistant_msg["thinking_blocks"] = response.thinking_blocks
messages.append(assistant_msg)
messages.append(build_assistant_message(
response.content or "",
tool_calls=tool_call_dicts,
reasoning_content=response.reasoning_content,
thinking_blocks=response.thinking_blocks,
))
# Execute tools
for tool_call in response.tool_calls: