microsoft/autogen · error · RuntimeError
InputRequestContext cannot be instantiated. It is a static c
Error message
InputRequestContext cannot be instantiated. It is a static class that provides context management for user input requests.
What it means
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.
Source
Thrown at python/packages/autogen-agentchat/src/autogen_agentchat/agents/_user_proxy_agent.py:135
cancellation_token=token,
)
)
response = await agent_task
assert isinstance(response.chat_message, TextMessage)
print(f"Your name is {response.chat_message.content}")
except Exception as e:
print(f"Exception: {e}")
except BaseException as e:
print(f"BaseException: {e}")
"""
component_type = "agent"
component_provider_override = "autogen_agentchat.agents.UserProxyAgent"
component_config_schema = UserProxyAgentConfig
class InputRequestContext:
def __init__(self) -> None:
raise RuntimeError(
"InputRequestContext cannot be instantiated. It is a static class that provides context management for user input requests."
)
_INPUT_REQUEST_CONTEXT_VAR: ClassVar[ContextVar[str]] = ContextVar("_INPUT_REQUEST_CONTEXT_VAR")
@classmethod
@contextmanager
def populate_context(cls, ctx: str) -> Generator[None, Any, None]:
""":meta private:"""
token = UserProxyAgent.InputRequestContext._INPUT_REQUEST_CONTEXT_VAR.set(ctx)
try:
yield
finally:
UserProxyAgent.InputRequestContext._INPUT_REQUEST_CONTEXT_VAR.reset(token)
@classmethod
def request_id(cls) -> str:
try:View on GitHub (pinned to 027ecf0a37)
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.
Example fix
// before
ctx = UserProxyAgent.InputRequestContext() # raises
// after
from autogen_agentchat.agents import UserProxyAgent
with UserProxyAgent.InputRequestContext.populate_context("request-id-123"):
rid = UserProxyAgent.InputRequestContext.request_id() Defensive patterns
Strategy: validation
Validate before calling
# Never construct it; use the classmethods
assert not callable(getattr(UserProxyAgent.InputRequestContext, "__call__", None)) or True
# correct usage:
with UserProxyAgent.InputRequestContext.populate_context("rid-1"):
rid = UserProxyAgent.InputRequestContext.request_id() Prevention
- Treat InputRequestContext as a namespace: only populate_context/request_id are public.
- Lint application code for InputRequestContext() constructor calls.
When it happens
Trigger: Writing UserProxyAgent.InputRequestContext() anywhere in application or library code; copy-pasting a context-manager usage that assumed an instance.
Common situations: Building custom input callbacks or console/UI integrations and assuming the context object must be constructed; porting code from other context APIs.
Related errors
- InputRequestContext.runtime() must be called within the inpu
- Failed to get user input: {str(e)}
- Installing directory is not set
- Handoff message target does not match agent name: {messages[
- AgentInstantiationContext cannot be instantiated. It is a st
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/b3ceb4537a7e2246.
Report an issue: GitHub.