File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -168,11 +168,7 @@ async def deliberate(
168168 obs = "OBSERVATIONS:\n "
169169 for call in calls :
170170 p_name , f_name , args_str = call
171- args = {}
172- arg_pairs = re .findall (r'(\w+)\s*=\s*["\']?([^"\',]+)["\']?' , args_str )
173- for k , v in arg_pairs :
174- args [k ] = utils .from_string_arg (v )
175-
171+ args = utils .parse_args_string (args_str )
176172 result = self .execute_call (p_name , f_name , args )
177173
178174 # Results are usually json, but not always
Original file line number Diff line number Diff line change @@ -16,6 +16,26 @@ def format_calls(calls_block):
1616 return calls
1717
1818
19+ import ast
20+ import re
21+
22+
23+ def parse_args_string (args_str ):
24+ flattened = args_str .replace ("\n " , " " ).replace ("\r " , " " )
25+ flattened = re .sub (r"\s+" , " " , flattened ).strip ()
26+ try :
27+ tree = ast .parse (f"f({ flattened } )" )
28+
29+ kwargs = {}
30+ for kw in tree .body [0 ].value .keywords :
31+ kwargs [kw .arg ] = ast .literal_eval (kw .value )
32+
33+ return kwargs
34+ except SyntaxError as e :
35+ print (f"Syntax error in agent output: { e } " )
36+ return {}
37+
38+
1939def ensure_command (command ):
2040 """
2141 Ensure the command if provided as string is split into list.
You can’t perform that action at this time.
0 commit comments