@@ -128,15 +128,24 @@ async def forward(self, message, **kwargs):
128128 )
129129 async def _inner_func (tool_call ):
130130 tool_call = deepcopy (tool_call )
131+ tool_name = tool_call ['function' ].get ('name' )
131132 try :
132- if tool_call [ 'function' ][ 'name' ] .split ('.' , 1 )[0 ] not in self .actions :
133+ if tool_name .split ('.' , 1 )[0 ] not in self .actions :
133134 return ActionReturn (
134- valid = ActionValidCode .INVALID , errmsg = f"Tool { tool_call ['function' ]['name' ]} Not Found"
135+ type = tool_name ,
136+ args = tool_call ['function' ].get ('arguments' ),
137+ valid = ActionValidCode .INVALID ,
138+ errmsg = f"Tool { tool_name } Not Found" ,
135139 )
136140 if isinstance (tool_call ['function' ]['arguments' ], str ):
137141 tool_call ['function' ]['arguments' ] = json .loads (tool_call ['function' ]['arguments' ])
138142 except Exception as e :
139- return ActionReturn (valid = ActionValidCode .INVALID , errmsg = str (e ))
143+ return ActionReturn (
144+ type = tool_name ,
145+ args = tool_call ['function' ].get ('arguments' ),
146+ valid = ActionValidCode .INVALID ,
147+ errmsg = str (e ),
148+ )
140149 tool_response : ActionReturn = (
141150 await self .actions (
142151 AgentMessage (
@@ -151,30 +160,29 @@ async def _inner_func(tool_call):
151160
152161 tasks = [_inner_func (tool_call ) for tool_call in message .tool_calls ]
153162 responses = await asyncio .gather (* tasks )
154- for i , resp in enumerate (responses ):
155- if resp .valid != ActionValidCode .OPEN :
156- return AgentMessage (
157- sender = self .name ,
158- content = f'Tool Call Error: { resp .errmsg } in tool call '
159- f'{ json .dumps (message .tool_calls [i ], ensure_ascii = False )} ' ,
160- )
161- if resp .state != ActionStatusCode .SUCCESS :
162- return AgentMessage (
163- sender = self .name ,
164- content = f'Tool Call Error: { resp .errmsg } in tool call '
165- f'{ json .dumps (message .tool_calls [i ], ensure_ascii = False )} ' ,
166- reward = - 1 if resp .state == ActionStatusCode .ARGS_ERROR else 0 ,
167- )
168163 # Pair each ActionReturn with its tool_call_id for proper LLM API formatting
169164 tool_results = []
170- for tc , r in zip (message .tool_calls , responses ):
171- result_dict = asdict (r )
165+ reward = 0.0
166+ for tc , resp in zip (message .tool_calls , responses ):
167+ result_dict = asdict (resp )
172168 result_dict ['tool_call_id' ] = tc .get ('id' , '' )
169+ if resp .valid != ActionValidCode .OPEN :
170+ result_dict ['errmsg' ] = (
171+ f'Tool Call Error: { resp .errmsg } in tool call '
172+ f'{ json .dumps (tc , ensure_ascii = False )} '
173+ )
174+ elif resp .state != ActionStatusCode .SUCCESS :
175+ result_dict ['errmsg' ] = (
176+ f'Tool Call Error: { resp .errmsg } in tool call '
177+ f'{ json .dumps (tc , ensure_ascii = False )} '
178+ )
179+ if resp .state == ActionStatusCode .ARGS_ERROR :
180+ reward = - 1
173181 tool_results .append (result_dict )
174182 return_message = AgentMessage (
175183 sender = self .name ,
176184 content = tool_results ,
177- reward = 0.0 ,
185+ reward = reward ,
178186 env_info = await self .get_env_info (),
179187 )
180188
0 commit comments