Skip to content

Python: [Bug]: Hosted agents: Agent Framework does not persist and reuse hosted agent_session_id across turns (conversation_id differs per request) #7503

Description

@djw-bsn

Description

What happened

For hosted agents, first turn succeeds, but follow-up turns through Agent Framework do not reliably reuse the same hosted agent session.
In Foundry, conversation_id changes per request, while agent_session_id is the durable session handle.
Agent Framework continuation plumbing appears to rely on conversation_id-style state instead of persisting hosted agent_session_id as first-class continuation state.
Result: second request can incur cold startup because a new hosted agent session/container path is used.

What we expected

On first hosted turn, when service returns agent_session_id or session.id, framework should persist that value.
On later turns, framework should send that persisted value back as extra_body.agent_session_id.
This should keep follow-up turns in the same hosted runtime session and avoid second-turn cold startup.

Steps to repro

Minimal code sample path A (direct SDK, expected behavior)

  1. Create OpenAI client from AIProjectClient with agent_name.
  2. First turn without agent_session_id.
  3. Extract agent_session_id from first response payload.
  4. Second turn with extra_body containing that same agent_session_id.
  5. Observe same hosted session reused and no second-turn cold startup.

Minimal code sample path B (Agent Framework, current behavior)

  1. Configure Foundry hosted agent through Agent Framework.
  2. Send two turns on same logical chat thread.
  3. Observe continuation does not reliably reuse hosted agent_session_id.
  4. Observe new hosted session startup behavior on follow-up turn.

Code Sample

Error Messages / Stack Traces

Package Versions

agent-framework-core 1.13.0 agent-framework-foundry 1.10.4 agent-framework-openai 1.12.0 agent-framework-ag-ui 1.0.1 azure-ai-projects 2.3.0 openai 2.51.0

Python Version

Python 3.12

Additional Context

No response

Metadata

Metadata

Assignees

Labels

pythonUsage: [Issues, PRs], Target: Python

Type

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions