Skip to content

Python: Fix AzureAIAgentClient dropping agent instructions#3563

Merged
eavanvalkenburg merged 1 commit intomicrosoft:mainfrom
moonbox3:3507-fix
Feb 1, 2026
Merged

Python: Fix AzureAIAgentClient dropping agent instructions#3563
eavanvalkenburg merged 1 commit intomicrosoft:mainfrom
moonbox3:3507-fix

Conversation

@moonbox3
Copy link
Contributor

Motivation and Context

In AzureAIAgentClient._prepare_options(), the instructions key was in the exclude_keys set with a comment "handled via messages", but instructions from the options dict were never actually extracted and added to the final instructions list. Only instructions from system/developer messages were being included.

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

…flows

In _prepare_options(), the 'instructions' key was excluded from run_options
but never re-added. This caused instructions passed via as_agent(instructions=...)
to be silently dropped, making agents in sequential workflows ignore their
configured instructions.

Fixes microsoft#3507
@moonbox3 moonbox3 self-assigned this Jan 31, 2026
Copilot AI review requested due to automatic review settings January 31, 2026 18:10
@markwallace-microsoft
Copy link
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azure-ai/agent_framework_azure_ai
   _chat_client.py4806786%377, 638–639, 641, 644, 647, 650–655, 658, 660, 668, 680–682, 686, 689–690, 698–701, 711, 719–722, 724–725, 727–728, 735, 743–744, 752–753, 758–759, 763–770, 775, 778, 786, 792, 800–802, 805, 827–828, 961, 989, 1004, 1125, 1151, 1160, 1169, 1302
TOTAL16250198287% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3742 221 💤 0 ❌ 0 🔥 1m 8s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in AzureAIAgentClient where agent instructions passed via the instructions parameter to as_agent() were being silently dropped, causing agents in workflows to ignore their configured instructions.

Changes:

  • Added code to extract and include instructions from the options dictionary in _prepare_options()
  • Added unit tests verifying instructions are properly included from options alone and merged with system message instructions

Reviewed changes

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

File Description
python/packages/azure-ai/agent_framework_azure_ai/_chat_client.py Fixed _prepare_options() to extract and append instructions from options dict after processing system messages
python/packages/azure-ai/tests/test_azure_ai_agent_client.py Added two comprehensive unit tests for instruction handling from options and merging behavior

@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue Feb 1, 2026
Merged via the queue into microsoft:main with commit 184ee9d Feb 1, 2026
30 checks passed
eavanvalkenburg pushed a commit to eavanvalkenburg/agent-framework that referenced this pull request Feb 1, 2026
…flows (microsoft#3563)

In _prepare_options(), the 'instructions' key was excluded from run_options
but never re-added. This caused instructions passed via as_agent(instructions=...)
to be silently dropped, making agents in sequential workflows ignore their
configured instructions.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Agents in workflow do not follow instructions.

4 participants