From 3cb45f1e9b15f4f4c9f3bfa530b4605091c1facd Mon Sep 17 00:00:00 2001 From: Dillon DuPont Date: Thu, 28 Aug 2025 18:35:44 -0400 Subject: [PATCH] Loop agent proxy --- libs/python/computer-server/computer_server/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/python/computer-server/computer_server/main.py b/libs/python/computer-server/computer_server/main.py index 1cfd30d8..85e5935b 100644 --- a/libs/python/computer-server/computer_server/main.py +++ b/libs/python/computer-server/computer_server/main.py @@ -646,7 +646,7 @@ async def agent_response_endpoint( total_output: List[Any] = [] total_usage: Dict[str, Any] = {} - turns = 0 + pending_computer_call_ids = set() try: async for result in agent.run(messages): total_output += result["output"] @@ -658,8 +658,13 @@ async def agent_response_endpoint( total_usage[k] = total_usage.get(k, 0) + v else: total_usage[k] = v - turns += 1 - if turns > 2: + for msg in result.get("output", []): + if msg.get("type") == "computer_call": + pending_computer_call_ids.add(msg["call_id"]) + elif msg.get("type") == "computer_call_output": + pending_computer_call_ids.discard(msg["call_id"]) + # exit if no pending computer calls + if not pending_computer_call_ids: break except Exception as e: logger.error(f"Error running agent: {str(e)}")