From fb27ea64404df7286dc32506cc5ad8c40a126373 Mon Sep 17 00:00:00 2001 From: aifanatic Date: Tue, 27 Oct 2026 07:41:31 -0500 Subject: [PATCH] Python: fix declarative external-input docstring examples The AgentExternalInputRequest example imported a nonexistent run_context, passed ctx= to Workflow.run and mixed up ExternalInput* and AgentExternalInput* names. Show the request_info / responses= loop the customer_support sample uses, and import AgentExternalInputResponse in the response examples. Co-Authored-By: Claude Opus 5.5 --- .../_workflows/_executors_agents.py | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/python/packages/declarative/agent_framework_declarative/_workflows/_executors_agents.py b/python/packages/declarative/agent_framework_declarative/_workflows/_executors_agents.py index 30de4b7eb00..fc261593125 100644 --- a/python/packages/declarative/agent_framework_declarative/_workflows/_executors_agents.py +++ b/python/packages/declarative/agent_framework_declarative/_workflows/_executors_agents.py @@ -402,28 +402,34 @@ class AgentExternalInputRequest: Examples: .. code-block:: python - from agent_framework import run_context from agent_framework_declarative import ( - ExternalInputRequest, - ExternalInputResponse, + AgentExternalInputRequest, + AgentExternalInputResponse, WorkflowFactory, ) - factory = WorkflowFactory() + factory = WorkflowFactory(agents={"Helper": agent}) workflow = factory.create_workflow_from_yaml_path("hitl_workflow.yaml") - async def run_with_hitl(): - # Set up external input handler - async def on_request(request: AgentExternalInputRequest) -> ExternalInputResponse: - print(f"Agent '{request.agent_name}' needs input:") - print(f" Response: {request.agent_response}") - user_input = input("Your response: ") - return AgentExternalInputResponse(user_input=user_input) - - async with run_context(request_handler=on_request) as ctx: - async for event in workflow.run(ctx=ctx, stream=True): - print(event) + async def run_with_hitl(user_input: str) -> None: + stream = workflow.run(user_input, stream=True) + while True: + responses: dict[str, AgentExternalInputResponse] = {} + async for event in stream: + if event.type == "request_info" and isinstance(event.data, AgentExternalInputRequest): + request = event.data + print(f"Agent '{request.agent_name}' needs input:") + print(f" Response: {request.agent_response}") + responses[event.request_id] = AgentExternalInputResponse( + user_input=input("Your response: ") + ) + elif event.type == "output": + print(event.data) + if not responses: + break + # Resume the paused workflow with the user's answers. + stream = workflow.run(stream=True, responses=responses) """ request_id: str @@ -436,7 +442,7 @@ async def on_request(request: AgentExternalInputRequest) -> ExternalInputRespons @dataclass class AgentExternalInputResponse: - """Response to an ExternalInputRequest. + """Response to an AgentExternalInputRequest. Provided by the caller to resume agent execution with new user input. This is the response type expected by the response_handler. @@ -444,14 +450,14 @@ class AgentExternalInputResponse: Examples: .. code-block:: python - from agent_framework_declarative import ExternalInputResponse + from agent_framework_declarative import AgentExternalInputResponse # Basic response with user text input response = AgentExternalInputResponse(user_input="Yes, please proceed with the order.") .. code-block:: python - from agent_framework_declarative import ExternalInputResponse + from agent_framework_declarative import AgentExternalInputResponse # Response with additional message history response = AgentExternalInputResponse(