Skip to content

Conversation

@NirajC-Microsoft
Copy link
Contributor

@NirajC-Microsoft NirajC-Microsoft commented Dec 16, 2025

Fix: RAI Agent Reuse Bug (#28329)

Problem

RAI agents were creating new instances on every validation call instead of reusing existing agents from the database.

Root Cause

  • Agents generated local IDs (e.g., asst_xyz123...) without creating actual Azure resources
  • Database stored phantom IDs that didn't exist on Azure Foundry
  • Subsequent retrieval attempts failed, forcing new agent creation

Changes

lifecycle.py

  • Added resolve_agent_id(): Dual-client fallback (Projects SDK → AgentsClient)
  • Enhanced get_database_team_agent(): Uses resolve_agent_id() for proper retrieval
  • Updated get_agent_id(): Fail-fast for RAI agents without valid IDs
  • Added save_database_team_agent() guards: Prevents duplicate saves
  • Initialized project_client: Projects SDK for RAI agent operations

foundry_agent.py

  • Added _create_mcp_agent_on_server(): Key fix - Creates real Azure agents via Projects SDK
  • Updated _after_open(): Calls server creation for RAI agents in MCP path
  • Initialized project_client: Ensures Projects SDK availability

Expected Outcome

  • First validation call: Creates agent on Azure, saves ID to database
  • Subsequent calls: Reuses existing agent from database
  • No duplicate agent creation
  • Improved performance (eliminates agent creation overhead)

Additional fix

In Select a Team, the “Legal Contract Review Team” was incorrectly treated as a non-default team. Since it is a default team, the Delete button should be disabled, similar to other default teams. A fix has been added in the TeamSelector.tsx file.

Does this introduce a breaking change?

  • Yes
  • No

How to Test

  • Get the code
git clone [repo-address]
cd [repo-name]
git checkout [branch-name]
npm install
  • Test the code

What to Check

Verify that the following are valid

  • ...

Other Information

@NirajC-Microsoft NirajC-Microsoft changed the title fix: fix for bug 28329 fix: Fixes for RAI agent path (rai_success) fails to reuse existing Foundry agents Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants