55
66from typing_extensions import override
77
8+ from ...tools import tool
9+ from ...tools .registry import ToolRegistry
810from ...types .content import Message
911from ...types .exceptions import ContextWindowOverflowException
1012from .conversation_manager import ConversationManager
2325- You MUST create a structured and concise summary in bullet-point format.
2426- You MUST NOT respond conversationally.
2527- You MUST NOT address the user directly.
28+ - You MUST NOT comment on tool availability.
29+
30+ Assumptions:
31+ - You MUST NOT assume tool executions failed unless otherwise stated.
2632
2733Task:
2834Your task is to create a structured summary document:
@@ -182,9 +188,10 @@ def _generate_summary(self, messages: List[Message], agent: "Agent") -> Message:
182188 # Choose which agent to use for summarization
183189 summarization_agent = self .summarization_agent if self .summarization_agent is not None else agent
184190
185- # Save original system prompt and messages to restore later
191+ # Save original system prompt, messages, and tool registry to restore later
186192 original_system_prompt = summarization_agent .system_prompt
187193 original_messages = summarization_agent .messages .copy ()
194+ original_tool_registry = summarization_agent .tool_registry
188195
189196 try :
190197 # Only override system prompt if no agent was provided during initialization
@@ -197,6 +204,13 @@ def _generate_summary(self, messages: List[Message], agent: "Agent") -> Message:
197204 )
198205 # Temporarily set the system prompt for summarization
199206 summarization_agent .system_prompt = system_prompt
207+
208+ # Add no-op tool if agent has no tools to satisfy tool spec requirement
209+ if not summarization_agent .tool_names :
210+ tool_registry = ToolRegistry ()
211+ tool_registry .register_tool (self ._noop_tool )
212+ summarization_agent .tool_registry = tool_registry
213+
200214 summarization_agent .messages = messages
201215
202216 # Use the agent to generate summary with rich content (can use tools if needed)
@@ -207,6 +221,7 @@ def _generate_summary(self, messages: List[Message], agent: "Agent") -> Message:
207221 # Restore original agent state
208222 summarization_agent .system_prompt = original_system_prompt
209223 summarization_agent .messages = original_messages
224+ summarization_agent .tool_registry = original_tool_registry
210225
211226 def _adjust_split_point_for_tool_pairs (self , messages : List [Message ], split_point : int ) -> int :
212227 """Adjust the split point to avoid breaking ToolUse/ToolResult pairs.
@@ -249,3 +264,13 @@ def _adjust_split_point_for_tool_pairs(self, messages: List[Message], split_poin
249264 raise ContextWindowOverflowException ("Unable to trim conversation context!" )
250265
251266 return split_point
267+
268+ @tool (name = "noop" , description = "MUST NOT call or summarize" )
269+ def _noop_tool (self ) -> None :
270+ """No-op tool to satisfy tool spec requirement when tool messages are present.
271+
272+ Some model provides (e.g., Bedrock) will return an error response if tool uses and tool results are present in
273+ messages without any tool specs configured. Consequently, if the summarization agent has no registered tools,
274+ summarization will fail. As a workaround, we register the no-op tool.
275+ """
276+ pass
0 commit comments