Skip to content

Commit c77015b

Browse files
Parse tool call arguments as dict (#330)
parse tool call arguments as dict
1 parent 78f0b2c commit c77015b

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

lagent/adapters/proxy.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,25 @@ async def _handle_request(self, request: web.Request) -> web.Response:
242242

243243
for field in allowed_fields:
244244
if raw_msg.get(field) is not None:
245-
assistant_msg[field] = raw_msg[field]
245+
val = copy.deepcopy(raw_msg[field])
246+
if field == "tool_calls":
247+
for tc in val:
248+
if tc.get("type") == "function" and "function" in tc:
249+
args = tc["function"].get("arguments")
250+
if isinstance(args, str):
251+
try:
252+
tc["function"]["arguments"] = json.loads(args)
253+
except json.JSONDecodeError:
254+
pass
255+
elif field == "function_call":
256+
args = val.get("arguments")
257+
if isinstance(args, str):
258+
try:
259+
val["arguments"] = json.loads(args)
260+
except json.JSONDecodeError:
261+
pass
262+
263+
assistant_msg[field] = val
246264

247265
# Keep the latest conversation history
248266
messages = list(request_data['messages'])

0 commit comments

Comments
 (0)