@@ -15,6 +15,26 @@ class WorkerBase:
1515 ask secretary. We provide it here so that a hub can use it to generate
1616 its dual mode (acting as worker AND hub.)
1717 """
18+ def jsonify_response (self , response ):
19+ """
20+ Ensure we get the text, and separate and parse tool calls,
21+ which the agent will return in a verbose mode.
22+ """
23+ result = response .content [0 ].text
24+
25+ # Audit the tool calls (Did the agent just get lucky?)
26+ calls = []
27+ if "CALLS" in result :
28+ try :
29+ result , calls_block = result .split ("CALLS" )
30+ calls = utils .format_calls (calls_block )
31+ except :
32+ print (f"Issue parsing calls, agent had malformed response: { result } " )
33+ pass
34+
35+ result = json .loads (utils .extract_code_block (result ))
36+ result ["calls" ] = calls
37+ return result
1838
1939 def init_providers (self , mock = False ):
2040 """
@@ -73,9 +93,9 @@ async def receive_job(request: str) -> dict:
7393 agent = SecretaryAgent (active_providers , verbose = self .verbose )
7494 raw_result = await agent .submit (request )
7595 try :
76- receipt = json . loads ( utils . extract_code_block ( raw_result ) )
77- except :
78- receipt = {"status" : "FAILED" , "reasoning" : raw_result }
96+ receipt = self . jsonify_response ( raw_result )
97+ except Exception as e :
98+ receipt = {"status" : "FAILED" , "reasoning" : raw_result , "error" : str ( e ) }
7999
80100 return {"worker_id" : self .worker_id , "receipt" : receipt }
81101
0 commit comments