The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: managed worker answers clarify with main's questions[] batch contract
Tekniumb6976ed14901
diff --git a/agent/managed_worker.py b/agent/managed_worker.pyindex 1bf3b02cad4..419adab0bc7 100644--- a/agent/managed_worker.py+++ b/agent/managed_worker.py@@ -88,6 +88,9 @@ class WorkerChannel:self.stream.flush()+_INTERRUPTED = object()++class WorkerControls:def __init__(self, channel, route):self.channel, self.route = channel, route@@ -105,7 +108,7 @@ class WorkerControls:self.agent.interrupt()with self.lock:for state in self.clarifications.values():- state['answer'] = '[Interrupted]'+ state['answer'] = _INTERRUPTEDstate['event'].set()def read(self):@@ -143,13 +146,30 @@ class WorkerControls:self.channel.send('approval', data={k: v for k, v in data.items() if k in fields})ack_gateway_approval(self.route, data['request_id'])- def clarify(self, question, choices, multi_select=False):+ def clarify(self, questions):+ """clarify_tool's batch contract: ``callback(questions) -> {answers, outcome, notice?}``.+ One owner prompt per question, stopping at the first that is interrupted or unanswered;+ an empty answer is a skip (``None``), as on the other surfaces."""+ answers = {}+ reply = {'answers': answers, 'outcome': 'submitted'}+ for entry in questions:+ answer = self._ask(entry['question'], entry['choices'], entry['multi_select'])+ if answer is _INTERRUPTED:+ reply['outcome'] = 'cancelled'+ break+ if answer is None:+ reply['outcome'] = 'timed_out'+ break+ answers[entry['qid']] = answer.strip() or None+ return reply++ def _ask(self, question, choices, multi_select):import uuidprompt_id = uuid.uuid4().hex- state = {'event': threading.Event(), 'answer': '[No response]'}+ state = {'event': threading.Event(), 'answer': None}with self.lock:if self.stopped.is_set() or len(self.clarifications) >= 16:- return '[Interrupted]'+ return _INTERRUPTEDself.clarifications[prompt_id] = statetry:self.channel.send('clarify', prompt_id=prompt_id, question=question,diff --git a/tests/gateway/test_api_pending_daemon.py b/tests/gateway/test_api_pending_daemon.pyindex 5da59fb36b3..698c91eecf4 100644--- a/tests/gateway/test_api_pending_daemon.py+++ b/tests/gateway/test_api_pending_daemon.py@@ -28,7 +28,7 @@ class PromptPeer(BaseHTTPRequestHandler):approval = 'ASK_APPROVAL' in textname = 'terminal' if approval else 'clarify'args = {'command': 'rm -rf ' + str(self.server.target)} if approval else {- 'question': 'Choose the answer', 'choices': ['BLUE', 'GREEN']}+ 'questions': [{'question': 'Choose the answer', 'choices': ['BLUE', 'GREEN']}]}message = {'role': 'assistant', 'content': None, 'tool_calls': [{'id': 'call_control', 'type': 'function', 'function': {'name': name, 'arguments': json.dumps(args)}}]}finish = 'tool_calls' if 'tool_calls' in message else 'stop'diff --git a/tests/gateway/test_managed_worker_launch.py b/tests/gateway/test_managed_worker_launch.pyindex 503371bfb71..482bcac642d 100644--- a/tests/gateway/test_managed_worker_launch.py+++ b/tests/gateway/test_managed_worker_launch.py@@ -30,7 +30,7 @@ class Model(BaseHTTPRequestHandler):self.server.requests.append(body)message = {'role': 'assistant', 'content': None, 'tool_calls': [{'id': 'managed-clarify', 'type': 'function', 'function': {'name': 'clarify',- 'arguments': json.dumps({'question': 'Choose managed answer', 'choices': ['Alpha', 'Beta']})}}]}+ 'arguments': json.dumps({'questions': [{'question': 'Choose managed answer', 'choices': ['Alpha', 'Beta']}]})}}]}elif any(m['role'] == 'tool' for m in body['messages']):self.server.requests.append(body)self.server.blocked.set()