Skip to content

Python: workflow.run(session=...) collides with AgentExecutor session argument #4295

@moonbox3

Description

@moonbox3

Description

Passing session via workflow.run(..., session=...) causes a runtime collision in AgentExecutor.

AgentExecutor always calls:

agent.run(..., session=self._session, options=options, **run_kwargs)

If workflow kwargs include session, Python receives two values for the session argument and raises TypeError.

Expected behavior:

  • either reserve/filter session from workflow kwargs, or
  • validate early and raise a clear workflow-level error.

Steps To Reproduce

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

class SimpleAgent:
    id = "simple-agent"
    name = "Simple Agent"

    async def run(self, messages=None, *, stream=False, session: AgentSession | None = None, options=None, **kwargs):
        return AgentResponse(messages=[Message(role="assistant", contents=[Content.from_text("ok")])])

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

async def main():
    wf = WorkflowBuilder(start_executor=AgentExecutor(SimpleAgent(), id="a")).build()
    await wf.run("hello", session="user-passed")

asyncio.run(main())

Error Messages / Stack Traces

TypeError: <Agent>.run() got multiple values for keyword argument 'session'

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/_agent_executor.py (_prepare_agent_run_args, _run_agent, _run_agent_streaming)

Potentially similar collisions can happen for other reserved run params if passed through workflow kwargs.

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