{"record":{"id":"b3ceb4537a7e2246","repo":"microsoft/autogen","slug":"inputrequestcontext-cannot-be-instantiated-it-is","errorCode":null,"errorMessage":"InputRequestContext cannot be instantiated. It is a static class that provides context management for user input requests.","messagePattern":"InputRequestContext cannot be instantiated\\. It is a static class that provides context management for user input requests\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-agentchat/src/autogen_agentchat/agents/_user_proxy_agent.py","lineNumber":135,"sourceCode":"                            cancellation_token=token,\n                        )\n                    )\n                    response = await agent_task\n                    assert isinstance(response.chat_message, TextMessage)\n                    print(f\"Your name is {response.chat_message.content}\")\n                except Exception as e:\n                    print(f\"Exception: {e}\")\n                except BaseException as e:\n                    print(f\"BaseException: {e}\")\n    \"\"\"\n\n    component_type = \"agent\"\n    component_provider_override = \"autogen_agentchat.agents.UserProxyAgent\"\n    component_config_schema = UserProxyAgentConfig\n\n    class InputRequestContext:\n        def __init__(self) -> None:\n            raise RuntimeError(\n                \"InputRequestContext cannot be instantiated. It is a static class that provides context management for user input requests.\"\n            )\n\n        _INPUT_REQUEST_CONTEXT_VAR: ClassVar[ContextVar[str]] = ContextVar(\"_INPUT_REQUEST_CONTEXT_VAR\")\n\n        @classmethod\n        @contextmanager\n        def populate_context(cls, ctx: str) -> Generator[None, Any, None]:\n            \"\"\":meta private:\"\"\"\n            token = UserProxyAgent.InputRequestContext._INPUT_REQUEST_CONTEXT_VAR.set(ctx)\n            try:\n                yield\n            finally:\n                UserProxyAgent.InputRequestContext._INPUT_REQUEST_CONTEXT_VAR.reset(token)\n\n        @classmethod\n        def request_id(cls) -> str:\n            try:","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_user_proxy_agent.py#L117-L153","documentation":"UserProxyAgent.InputRequestContext is a static utility class: its __init__ is intentionally poisoned to prevent instantiation. All functionality is exposed through classmethods (populate_context, request_id) that manage a ContextVar for correlating runtime input requests.","triggerScenarios":"Writing UserProxyAgent.InputRequestContext() anywhere in application or library code; copy-pasting a context-manager usage that assumed an instance.","commonSituations":"Building custom input callbacks or console/UI integrations and assuming the context object must be constructed; porting code from other context APIs.","solutions":["Never instantiate it; call the classmethods directly: InputRequestContext.populate_context(...) and InputRequestContext.request_id().","Use populate_context inside your input_func when you need to expose the runtime request id to downstream code."],"exampleFix":"// before\nctx = UserProxyAgent.InputRequestContext()  # raises\n\n// after\nfrom autogen_agentchat.agents import UserProxyAgent\nwith UserProxyAgent.InputRequestContext.populate_context(\"request-id-123\"):\n    rid = UserProxyAgent.InputRequestContext.request_id()","handlingStrategy":"validation","validationCode":"# Never construct it; use the classmethods\nassert not callable(getattr(UserProxyAgent.InputRequestContext, \"__call__\", None)) or True\n# correct usage:\nwith UserProxyAgent.InputRequestContext.populate_context(\"rid-1\"):\n    rid = UserProxyAgent.InputRequestContext.request_id()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat InputRequestContext as a namespace: only populate_context/request_id are public.","Lint application code for InputRequestContext() constructor calls."],"tags":["user-proxy","misuse","static-class","input-callback"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}