Skip to content

Python: [Bug]: Current AG-UI AgentSession Construction Prevents Developers from Controlling session_id Assignment #5357

@lixiaoqiang

Description

@lixiaoqiang

Description

Current code in _agent_run.py, method run_agent_stream, lines 781~786:

    # Create session (with service session support)
    if config.use_service_session:
        supplied_thread_id = input_data.get("thread_id") or input_data.get("threadId")
        session = AgentSession(service_session_id=supplied_thread_id)
    else:
        session = AgentSession()

This constructs the AgentSession in a rigid way, and developers have no control over the session_id assignment.

When the AG-UI client provides a thread_id, we need to assign this thread_id to AgentSession.session_id to ensure session consistency.

However, the current implementation always generates a new session_id each time, which causes mapping issues between the session_id in the historical message records stored by the Agent's HistoryProvider and the client's thread_id.

Could we consider providing an AgentSessionBuilder with a default implementation?
This would allow developers to flexibly construct the AgentSession based on their requirements, making the framework more flexible and extensible.

Code Sample

Error Messages / Stack Traces

Package Versions

agent-framework:1.0.1

Python Version

Python 3.13

Additional Context

No response

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions