@@ -125,6 +125,27 @@ def _print_banner(self):
125125 print (" Workers must use this secret to join the hub" )
126126 print (f" mcpserver start --join { self .registration_url } \n " )
127127
128+ def jsonify_response (self , response ):
129+ """
130+ Ensure we get the text, and separate and parse tool calls,
131+ which the agent will return in a verbose mode.
132+ """
133+ result = result .content [0 ].text
134+
135+ # Audit the tool calls (Did the agent just get lucky?)
136+ calls = []
137+ if "CALLS" in result :
138+ try :
139+ result , calls_block = result .split ("CALLS" )
140+ calls = utils .format_calls (calls_block )
141+ except :
142+ print (f"Issue parsing calls, agent had malformed response: { result } " )
143+ pass
144+
145+ result = json .loads (utils .extract_code_block (result ))
146+ result ["calls" ] = calls
147+ return result
148+
128149 async def run_on_fleet_parallel (self , action_fn ) -> Dict [str , Any ]:
129150 """
130151 Run parallel sessions across all workers.
@@ -209,7 +230,7 @@ async def dispatch_job(worker_id: str, prompt: str) -> dict:
209230
210231 async with info ["client" ] as sess :
211232 result = await sess .call_tool ("submit" , {"request" : prompt })
212- return json . loads ( utils . extract_code_block ( result . content [ 0 ]. text ) )
233+ return self . jsonify_response ( result )
213234
214235 @self .mcp .tool (name = "negotiate_job" )
215236 async def negotiate_job (prompt : str ) -> dict :
@@ -253,6 +274,7 @@ async def negotiate_handler(wid, sess):
253274 mcp_result = await sess .call_tool ("ask_secretary" , {"request" : prompt })
254275 raw_text = mcp_result .content [0 ].text
255276
277+ # TODO: vsoch: add support to parse the calls here too (like dispatch)
256278 try :
257279 # Parse and handle potential quote issues in LLM JSON
258280 proposal_data = json .loads (utils .extract_code_block (raw_text ))
0 commit comments