Skip to content

Python: Fix Foundry hosted session SDK calls - #6862

Closed
ekkoitac (ekkoitac) wants to merge 1 commit into
microsoft:mainfrom
ekkoitac:fix/issue-6857-foundry-session-sdk
Closed

Python: Fix Foundry hosted session SDK calls#6862
ekkoitac (ekkoitac) wants to merge 1 commit into
microsoft:mainfrom
ekkoitac:fix/issue-6857-foundry-session-sdk

Conversation

@ekkoitac

Copy link
Copy Markdown

Motivation & Context

Hosted FoundryAgent sessions currently fail against azure-ai-projects==2.2.0 when allow_preview=True and an isolation_key is provided. The Foundry SDK no longer exposes the agent-name .get(...) lookup used by get_agent_version(), and create_session(...) expects user_isolation_key instead of isolation_key.

Description & Review Guide

  • What are the major changes?
    • Stop looking up a hosted agent version through the missing project_client.beta.agents.get(...) API when no explicit agent_version is configured.
    • Pass user_isolation_key to project_client.beta.agents.create_session(...).
    • Add a regression test for SDK objects without the removed lookup method and update the session creation assertion.
  • What is the impact of these changes?
    • Hosted session creation can proceed with the current Azure SDK shape while preserving explicit agent_version behavior when callers provide one.
    • Checked with:
      • uv run pytest tests/foundry/test_foundry_agent.py::test_raw_foundry_agent_chat_client_get_agent_version_skips_sdk_lookup tests/foundry/test_foundry_agent.py::test_raw_foundry_agent_prepare_run_context_creates_service_session_from_isolation_key -q
      • uv run pytest tests/foundry/test_foundry_agent.py -q
      • uv run poe test -P foundry -m "not integration"
      • uv run ruff check packages/foundry/agent_framework_foundry/_agent.py packages/foundry/tests/foundry/test_foundry_agent.py
      • uv run ruff format --check packages/foundry/agent_framework_foundry/_agent.py packages/foundry/tests/foundry/test_foundry_agent.py
      • uv run pyright packages/foundry/agent_framework_foundry/_agent.py
  • What do you want reviewers to focus on?
    • Whether hosted sessions should continue omitting version_indicator when callers do not pass agent_version.

Related Issue

Fixes #6857

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.

Copilot AI review requested due to automatic review settings July 1, 2026 15:40
@giles17 Giles Odigwe (giles17) added the python Usage: [Issues, PRs], Target: Python label Jul 1, 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

Fixes Python Foundry hosted-session creation against azure-ai-projects==2.2.0 by removing reliance on an SDK agent-name lookup API that no longer exists and by aligning the session creation kwargs with the SDK’s current parameter name.

Changes:

  • Removed the preview-only SDK agent lookup from get_agent_version() when no explicit agent_version is configured (now returns None unless agent_version is set).
  • Updated hosted session creation to pass user_isolation_key (instead of isolation_key) to project_client.beta.agents.create_session(...).
  • Added/updated unit tests to validate the new behavior (no SDK lookup required; updated session creation kwargs assertion).

Reviewed changes

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

File Description
python/packages/foundry/agent_framework_foundry/_agent.py Stops SDK-based agent-name version resolution and updates hosted session creation to use user_isolation_key.
python/packages/foundry/tests/foundry/test_foundry_agent.py Adds regression coverage for missing SDK lookup method and updates the hosted session kwargs assertion to user_isolation_key.

raise TypeError("Foundry agent details did not include a latest version string.")
self.agent_version = agent_version
return agent_version
return None

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.

Could we keep resolving a version through project_client.agents.get(...), or otherwise always supply a valid VersionIndicator here? With the pinned azure-ai-projects==2.2.0, beta.agents.create_session() treats version_indicator as required and raises TypeError("missing required argument: version_indicator") before sending a request, so the reported HostedAgent path with no explicit agent_version still crashes. The new test stops at get_agent_version(), while the session-creation test supplies agent_version="1.0", so neither exercises this failure path.

@moonbox3

Copy link
Copy Markdown
Contributor

Tao Chen (@TaoChenOSU) is this PR still required?

@moonbox3

Copy link
Copy Markdown
Contributor

There's been a lot of churn in the Foundry related projects these days. Tao Chen (@TaoChenOSU) will be checking if this is still needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: FoundryAgent crashes when initializing HostedAgent sessions due to incompatible Azure SDK calls

4 participants