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,7 +168,7 @@ async def deliberate(
168168 obs = "OBSERVATIONS:\n "
169169 for call in calls :
170170 p_name , f_name , args_str = call
171- args = utils .parse_args_string (args_str )
171+ args = utils .parse_args (args_str )
172172 result = self .execute_call (p_name , f_name , args )
173173
174174 # Results are usually json, but not always
Original file line number Diff line number Diff line change @@ -16,26 +16,6 @@ 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-
3919def ensure_command (command ):
4020 """
4121 Ensure the command if provided as string is split into list.
@@ -45,6 +25,23 @@ def ensure_command(command):
4525 return command
4626
4727
28+ import ast
29+ import re
30+
31+
32+ def parse_args (args_str ):
33+ pattern = r"(\w+)\s*=\s*(\{.*?\}|'[^']*'|\"[^\"]*\"|[^,]+)"
34+ matches = re .findall (pattern , args_str )
35+ result = {}
36+ for key , value in matches :
37+ value = value .strip ()
38+ try :
39+ result [key ] = ast .literal_eval (value )
40+ except :
41+ result [key ] = value .strip ("'\" " )
42+ return result
43+
44+
4845def from_string_arg (val ):
4946 """
5047 When we parse a call (from string) we need to convert into Python types.
You can’t perform that action at this time.
0 commit comments