Skip to content

Python: Fix FHA session ID translation - #7608

Merged
Tao Chen (TaoChenOSU) merged 6 commits into
mainfrom
taochen/issue-7503
Aug 11, 2026
Merged

Python: Fix FHA session ID translation#7608
Tao Chen (TaoChenOSU) merged 6 commits into
mainfrom
taochen/issue-7503

Conversation

@TaoChenOSU

@TaoChenOSU Tao Chen (TaoChenOSU) commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Motivation & Context

Addresses #7503

Previously we were using the Foundry agent_session_id as the continuation handle of a conversation for Foundry Hosted Agent. That's only partially correct because the Foundry agent_session_id is not an identified of a conversation but rather an identifier of the infrastructure that is running the hosted agent code. To continue a conversation (whether that's via a conversation_id or a previous_response_id, we first need to send the request to the same Foundry session, which means we have to send both IDs (agent_session_id and conversation_id or previous_response_id) to continue a conversation.

Read more about Foundry's agent_session_id here: https://learn.microsoft.com/en-us/azure/foundry/agents/concepts/hosted-agents#isolation-model

Description & Review Guide

  • What are the major changes?
    • Add logic to extract the agent_session_id from the FHA response and save the id in the state bag of the MAF session.
    • Remove logic that was previously used to override the MAF service_session_id with the FHA agent_session_id. The MAF service_session_id is supposed to be the continuation handle.
    • Remove logic to lazily create a session because Foundry automatically creates one if none is specified.
    • Deprecate isolation_key as isolation is handled automatically by the platform.
    • Add logic to send the agent_session_id is the state bag of the MAF session as part of the request to FHA.
  • What is the impact of these changes?
    • Fix an urgent bug from customer
    • Improve the code on session handling for FHA
  • What do you want reviewers to focus on?
    • The request shaping in FoundryAgent and FoundryChatClient

Related Issue

Fixes #7503

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

@TaoChenOSU Tao Chen (TaoChenOSU) self-assigned this Aug 10, 2026
Copilot AI balanced review requested due to automatic review settings August 10, 2026 21:25
@TaoChenOSU Tao Chen (TaoChenOSU) added python Usage: [Issues, PRs], Target: Python foundry Usage: [Issues, PRs], Target: all Foundry integrations hosting Usage: [Issues, PRs], Target: all hosting related solutions labels Aug 10, 2026
@github-actions github-actions Bot changed the title Fix FHA session ID traslation Python: Fix FHA session ID traslation Aug 10, 2026
@agent-framework-automation agent-framework-automation Bot added the documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs label Aug 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Separates Foundry hosted-agent session IDs from Responses API continuation IDs so hosted sessions persist across turns.

Changes:

  • Persists hosted session IDs in AgentSession.state.
  • Propagates provider-specific continuation metadata through streaming and function loops.
  • Updates tests, exports, documentation, and the hosted-agent sample.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
python/samples/04-hosting/foundry-hosted-agents/responses/using_deployed_agent.py Uses service-created sessions.
python/packages/foundry/tests/foundry/test_foundry_agent.py Tests separate session and continuation IDs.
python/packages/foundry/README.md Documents session persistence.
python/packages/foundry/agent_framework_foundry/_agent.py Implements Foundry session translation.
python/packages/foundry/agent_framework_foundry/__init__.py Exports the session-state key.
python/packages/core/tests/core/test_foundry_namespace.py Tests namespace exposure.
python/packages/core/agent_framework/foundry/__init__.pyi Adds the typed export.
python/packages/core/agent_framework/foundry/__init__.py Adds lazy namespace mapping.
python/packages/core/agent_framework/_tools.py Adds extensible function-loop continuation handling.
python/packages/core/agent_framework/_agents.py Adds extensible session-update hooks.
docs/specs/004-python-function-calling-loop.md Documents the continuation hook.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread python/packages/foundry/agent_framework_foundry/_agent.py
Comment thread python/packages/foundry/agent_framework_foundry/_agent.py

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent Framework Review — Iteration 1

Completed passes: 5 | Result: No high-severity findings

Scope: full PR (1 commit(s)): bbe15c58ef40

Review passes

  • Correctness (gpt-5.6-sol) — No issues found in this pass.
  • Security Reliability (claude-opus-4.8) — No issues found in this pass.
  • Test Coverage (gpt-5.6-sol) — No issues found in this pass.
  • Failure Modes (claude-opus-4.8) — No issues found in this pass.
  • Design Approach (claude-opus-4.8) — No issues found in this pass.

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _agents.py4564590%565, 577, 632, 1202, 1247, 1318–1322, 1421, 1451, 1488, 1580, 1608, 1621, 1673, 1675, 1684–1689, 1694, 1696, 1702–1703, 1710, 1712–1713, 1721–1722, 1725–1727, 1737–1742, 1746, 1751, 1753
   _tools.py13767894%231–232, 409, 411, 424, 449–451, 459, 477, 491, 498, 505, 528, 530, 537, 545, 680, 719–721, 729, 780–782, 807, 833, 837, 875–877, 881, 1054, 1066, 1073–1076, 1097, 1105, 1119–1121, 1491, 1574, 1624, 1684–1685, 1742, 1789, 1796–1797, 1887, 1928–1929, 1959, 2055, 2069, 2072, 2085, 2088, 2111, 2118, 2127, 2131, 2156, 2190, 2258, 2287–2288, 2385, 2413, 2453, 2456, 2513, 2666, 2755, 3270
packages/foundry/agent_framework_foundry
   _agent.py2571893%130, 133, 253, 258, 267, 378, 481–482, 506, 509, 518–519, 744–745, 748, 869, 874, 878
TOTAL45620423490% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
9244 36 💤 0 ❌ 0 🔥 2m 28s ⏱️

Comment thread python/packages/foundry/agent_framework_foundry/_agent.py

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent Framework Review — Iteration 2

Completed passes: 5 | Result: No high-severity findings

Scope: 4 net-new commit(s): aa6afd0d5181, b817149b66e6, fbff74822e4a, 10f44cee0207

Review passes

  • Correctness (gpt-5.6-sol) — No issues found in this pass.
  • Security Reliability (claude-opus-4.8) — No issues found in this pass.
  • Test Coverage (gpt-5.6-sol) — No issues found in this pass.
  • Failure Modes (claude-opus-4.8) — No issues found in this pass.
  • Design Approach (claude-opus-4.8) — No issues found in this pass.

Comment thread python/packages/foundry/agent_framework_foundry/_agent.py
Comment thread python/packages/foundry/agent_framework_foundry/_agent.py
@moonbox3 Evan Mattson (moonbox3) changed the title Python: Fix FHA session ID traslation Python: Fix FHA session ID translation Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs foundry Usage: [Issues, PRs], Target: all Foundry integrations hosting Usage: [Issues, PRs], Target: all hosting related solutions python Usage: [Issues, PRs], Target: Python

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

4 participants