Skip to content

Python: Workflow run kwargs are dropped when continuing with run(responses=...) #4293

@moonbox3

Description

@moonbox3

Description

Workflow-level kwargs are cleared when continuing a paused workflow with run(responses=...).

What happens now:

  1. Initial run stores kwargs in workflow state (e.g., custom_data).
  2. Workflow pauses with pending request(s).
  3. Continuation call run(responses=...) executes with no kwargs.
  4. _run_workflow_with_tracing writes run_kwargs or {} again, overwriting prior kwargs to {}.
  5. Subsequent agent/tool invocation loses original run context.

Expected behavior:

  • Continuation via run(responses=...) should preserve existing run kwargs unless explicitly overridden.

Steps To Reproduce

import asyncio
from agent_framework import WorkflowBuilder, AgentExecutor, AgentResponse, AgentSession, Message, Content

class ApprovalAgent:
    id = "approval-agent"
    name = "Approval Agent"
    def __init__(self):
        self.calls = []
        self._asked = False

    async def run(self, messages=None, *, stream=False, session=None, options=None, **kwargs):
        self.calls.append(dict(kwargs))
        if not self._asked:
            self._asked = True
            call = Content.from_function_call(call_id="c1", name="do_thing", arguments="{}")
            req = Content.from_function_approval_request(id="r1", function_call=call)
            return AgentResponse(messages=[Message(role="assistant", contents=[req])])
        return AgentResponse(messages=[Message(role="assistant", contents=[Content.from_text("done")])])

    def create_session(self, **kwargs):
        return AgentSession()

async def main():
    agent = ApprovalAgent()
    wf = WorkflowBuilder(start_executor=AgentExecutor(agent, id="a")).build()

    r1 = await wf.run("go", custom_data={"token": "abc"})
    req = r1.get_request_info_events()[0]
    _ = await wf.run(responses={req.request_id: req.data.to_function_approval_response(True)})

    print(agent.calls)  # observed: [{'custom_data': {'token': 'abc'}}, {}]

asyncio.run(main())

Error Messages / Stack Traces

No exception is raised; behavior regression is visible in captured kwargs:

[{'custom_data': {'token': 'abc'}}, {}]

Package Versions

  • agent-framework-core: 1.0.0rc2
  • agent-framework-orchestrations: 1.0.0b260225
  • Source commit tested: 02ba27493 (main)

Python Version

Python 3.13.5

Additional Context

Likely area:

  • packages/core/agent_framework/_workflows/_workflow.py (run kwargs persistence during response-only runs)
  • packages/core/agent_framework/_workflows/_agent_executor.py (kwargs read via WORKFLOW_RUN_KWARGS_KEY)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpythonworkflowsRelated to Workflows in agent-framework

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions