1919 get_last_response ,
2020 tools_caller ,
2121)
22+ from amrita_core .tools .models import ToolFunctionSchema
2223from amrita_core .types import (
2324 CONTENT_LIST_TYPE_ITEM ,
2425 Function ,
5657)
5758
5859
60+ def _resolve_tool_name (tool : ToolFunctionSchema | dict ) -> str :
61+ """Resolve the function name from a tool schema (object or dict form)."""
62+ if isinstance (tool , dict ):
63+ return tool .get ("function" , {}).get ("name" , "" )
64+ return tool .function .name
65+
66+
5967class BaseReActAgentStrategy (AgentStrategy , ABC ):
6068 """
6169 Abstract base class for ReAct agent strategies with common execution logic.
@@ -93,7 +101,7 @@ class BaseReActAgentStrategy(AgentStrategy, ABC):
93101
94102 agent_last_step : str | None = None
95103 call_count = 1
96- tools : list [Any ]
104+ tools : list [ToolFunctionSchema ]
97105 origin_msg : str = ""
98106 origin_instruction : str = ""
99107 reasoning_pc = 0
@@ -112,8 +120,8 @@ def __init__(self, ctx: StrategyContext):
112120 self .origin_instruction = self .chat_object .train .content
113121 config = self .chat_object .config
114122 if config .builtin .tool_calling_mode == "agent" :
115- self .tools .append (STOP_TOOL . model_dump () )
116- self .tools .extend (self .tools_manager .tools_meta_dict ().values ())
123+ self .tools .append (STOP_TOOL )
124+ self .tools .extend (self .tools_manager .tools_meta ().values ())
117125 # Initialize reasoning enhancement state
118126 self ._predicted_tools = []
119127 self .origin_msg : str = (
@@ -131,8 +139,8 @@ async def _generate_reasoning_content(
131139 ) -> UniResponse [str , None ]:
132140 tools = [
133141 {
134- "name" : tool [ " function" ][ " name" ] ,
135- "description" : tool [ " function" ][ " description" ] ,
142+ "name" : tool . function . name ,
143+ "description" : tool . function . description ,
136144 }
137145 for tool in self .tools
138146 ]
@@ -362,7 +370,7 @@ async def _run_reflection(
362370
363371 tool_response = await tools_caller (
364372 msg_list ,
365- [REFLECTION_TOOL . model_dump () ],
373+ [REFLECTION_TOOL ],
366374 tool_choice = REFLECTION_TOOL ,
367375 preset = self .ctx .chat_object .preset ,
368376 )
@@ -421,7 +429,7 @@ async def _run_reflection(
421429
422430 async def _generate_reasoning_msg (
423431 self ,
424- tools_ctx : list [dict [ str , Any ] ],
432+ tools_ctx : list [ToolFunctionSchema ],
425433 / ,
426434 then : Callable [
427435 [
@@ -447,7 +455,7 @@ async def _generate_reasoning_msg(
447455 ]
448456 tool_response : UniResponse [None , list [ToolCall ] | None ] = await tools_caller (
449457 reasoning_trigger_msg ,
450- [REASONING_TOOL . model_dump () , * tools_ctx ],
458+ [REASONING_TOOL , * tools_ctx ],
451459 tool_choice = REASONING_TOOL ,
452460 preset = self .ctx .chat_object .preset ,
453461 )
@@ -840,7 +848,9 @@ async def _handle_tool_error_common(
840848 Returns:
841849 Error message string
842850 """
843- logger .error (f"Function { function_name } execution failed: { err } " )
851+ logger .opt (exception = err , colors = True ).error (
852+ f"Function { function_name } execution failed: { err } "
853+ )
844854 config = self .chat_object .config
845855 if (
846856 config .builtin .tool_calling_mode == "agent"
@@ -886,6 +896,7 @@ def get_category(
886896 ) -> Literal ["workflow" ]:
887897 return "workflow"
888898
899+
889900class HybridReActAgentStrategy (BaseReActAgentStrategy ):
890901 """**Hybrid ReAct Agent Strategy optimized for Mixture of Experts (MoE) architecture models.**
891902
@@ -1087,7 +1098,7 @@ async def single_execute(
10871098 return False
10881099 tools = self .tools .copy ()
10891100 if config .builtin .agent_thought_mode .startswith ("reasoning" ):
1090- tools .append (REASONING_TOOL . model_dump () )
1101+ tools .append (REASONING_TOOL )
10911102
10921103 if (
10931104 self ._predicted_tools
@@ -1096,15 +1107,16 @@ async def single_execute(
10961107 and config .builtin .react_config .reasoning_aware_tools
10971108 ):
10981109 prioritized = [
1099- t for t in tools if t [ "function" ][ "name" ] in self ._predicted_tools
1110+ t for t in tools if _resolve_tool_name ( t ) in self ._predicted_tools
11001111 ]
11011112 others = [
1102- t for t in tools if t [ "function" ][ "name" ] not in self ._predicted_tools
1113+ t for t in tools if _resolve_tool_name ( t ) not in self ._predicted_tools
11031114 ]
11041115 tools = prioritized + others
11051116 logger .debug (
1106- f"Reasoning-aware tools: { [t ['function' ]['name' ] for t in prioritized ]} "
1107- f"ahead of { len (others )} others"
1117+ f"Reasoning-aware tools:"
1118+ f" { [_resolve_tool_name (t ) for t in prioritized ]} "
1119+ f" ahead of { len (others )} others"
11081120 )
11091121
11101122 response_msg : UniResponse [None , list [ToolCall ] | None ] = await tools_caller (
@@ -1320,7 +1332,7 @@ async def single_execute(
13201332 return False
13211333 tools = self .tools .copy ()
13221334 if config .builtin .agent_thought_mode .startswith ("reasoning" ):
1323- tools .append (REASONING_TOOL . model_dump () )
1335+ tools .append (REASONING_TOOL )
13241336
13251337 if (
13261338 self ._predicted_tools
@@ -1329,15 +1341,16 @@ async def single_execute(
13291341 and config .builtin .react_config .reasoning_aware_tools
13301342 ):
13311343 prioritized = [
1332- t for t in tools if t [ "function" ][ "name" ] in self ._predicted_tools
1344+ t for t in tools if _resolve_tool_name ( t ) in self ._predicted_tools
13331345 ]
13341346 others = [
1335- t for t in tools if t [ "function" ][ "name" ] not in self ._predicted_tools
1347+ t for t in tools if _resolve_tool_name ( t ) not in self ._predicted_tools
13361348 ]
13371349 tools = prioritized + others
13381350 logger .debug (
1339- f"Reasoning-aware tools: { [t ['function' ]['name' ] for t in prioritized ]} "
1340- f"ahead of { len (others )} others"
1351+ f"Reasoning-aware tools:"
1352+ f" { [_resolve_tool_name (t ) for t in prioritized ]} "
1353+ f" ahead of { len (others )} others"
13411354 )
13421355
13431356 response_msg : UniResponse [None , list [ToolCall ] | None ] = await tools_caller (
0 commit comments