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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user