{"record":{"id":"36baea9acd20a148","repo":"microsoft/autogen","slug":"failed-to-get-user-input-str-e","errorCode":null,"errorMessage":"Failed to get user input: {str(e)}","messagePattern":"Failed to get user input: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/agents/_user_proxy_agent.py","lineNumber":202,"sourceCode":"        return None\n\n    async def _get_input(self, prompt: str, cancellation_token: Optional[CancellationToken]) -> str:\n        \"\"\"Handle input based on function signature.\"\"\"\n        try:\n            if self._is_async:\n                # Cast to AsyncInputFunc for proper typing\n                async_func = cast(AsyncInputFunc, self.input_func)\n                return await async_func(prompt, cancellation_token)\n            else:\n                # Cast to SyncInputFunc for proper typing\n                sync_func = cast(SyncInputFunc, self.input_func)\n                loop = asyncio.get_event_loop()\n                return await loop.run_in_executor(None, sync_func, prompt)\n\n        except asyncio.CancelledError:\n            raise\n        except Exception as e:\n            raise RuntimeError(f\"Failed to get user input: {str(e)}\") from e\n\n    async def on_messages(self, messages: Sequence[BaseChatMessage], cancellation_token: CancellationToken) -> Response:\n        async for message in self.on_messages_stream(messages, cancellation_token):\n            if isinstance(message, Response):\n                return message\n        raise AssertionError(\"The stream should have returned the final result.\")\n\n    async def on_messages_stream(\n        self, messages: Sequence[BaseChatMessage], cancellation_token: CancellationToken\n    ) -> AsyncGenerator[BaseAgentEvent | BaseChatMessage | Response, None]:\n        \"\"\"Handle incoming messages by requesting user input.\"\"\"\n        try:\n            # Check for handoff first\n            handoff = self._get_latest_handoff(messages)\n            prompt = (\n                f\"Handoff received from {handoff.source}. Enter your response: \" if handoff else \"Enter your response: \"\n            )\n","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_user_proxy_agent.py#L184-L220","documentation":"UserProxyAgent wraps any exception raised by the configured input_func (async or sync) in this RuntimeError. It re-raises asyncio.CancelledError untouched, so genuine failures come from the callback itself: wrong signature, missing runtime dependency, or an error in the input UI code.","triggerScenarios":"input_func raising because its signature doesn't match how it's invoked — async callbacks are awaited as f(prompt, cancellation_token), sync ones run in an executor as f(prompt); or the console/UI code inside the callback throwing (KeyboardInterrupt handling, EOF on stdin, missing widget).","commonSituations":"Callbacks declared def input(prompt: str, cancellation_token) that also try to accept extra args, or async def input(prompt) that internally breaks; stdin EOF in non-interactive CI; UI library not installed in the runtime environment.","solutions":["Run the input_func standalone with a prompt (and cancellation token for async) to see the original exception; the message embeds str(e).","Match the expected signature: async callbacks take (prompt, cancellation_token); sync callbacks take (prompt).","Handle EOF/stdin-closed cases inside the callback (e.g. sys.stdin reading guarded) for non-interactive environments.","Ensure any UI/console dependency the callback uses is installed where the agent runs."],"exampleFix":"// before\ndef input(prompt: str, cancellation_token) -> str:  # sync: token not passed -> TypeError\n    return input(prompt)\n\n// after\ndef read_input(prompt: str) -> str:\n    return builtins_input(prompt)\n\nagent = UserProxyAgent(name=\"user\", input_func=read_input)","handlingStrategy":"try-catch","validationCode":"import inspect\n\ndef input_callback_ok(fn) -> bool:\n    params = list(inspect.signature(fn).parameters)\n    if inspect.iscoroutinefunction(fn):\n        return len(params) == 2  # (prompt, cancellation_token)\n    return len(params) == 1  # (prompt,)\n\nassert input_callback_ok(input_func), \"input_func signature mismatch\"","typeGuard":"import inspect\nfrom autogen_agentchat.agents import UserProxyAgent\n\ndef matches_input_contract(fn) -> bool:\n    if inspect.iscoroutinefunction(fn):\n        try:\n            inspect.signature(fn).bind(\"prompt\", None)\n            return True\n        except TypeError:\n            return False\n    try:\n        inspect.signature(fn).bind(\"prompt\")\n        return True\n    except TypeError:\n        return False","tryCatchPattern":"try:\n    async for msg in user_proxy.on_messages_stream(msgs, ct):\n        ...\nexcept RuntimeError as e:\n    if \"Failed to get user input\" in str(e):\n        # str(e) embeds the original callback error; log and surface to user\n        log.error(\"input callback failed: %s\", e.__cause__)\n    raise","preventionTips":["Match the callback contract: async (prompt, cancellation_token) or sync (prompt).","Test input_func standalone before wiring it into the agent.","Guard stdin/UI reads against EOF and closed channels inside the callback."],"tags":["user-proxy","input-callback","exception-wrapping","signature-mismatch"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}