Python: Align ModeProvider tool names and instructions#6071
Conversation
There was a problem hiding this comment.
Pull request overview
Aligns AgentModeProvider tool naming and injected mode instructions across Python and .NET so clients can render mode tools consistently regardless of agent language.
Changes:
- Renamed mode tools to
mode_set/mode_getin both Python and .NET implementations (and updated corresponding tests). - Updated Python default mode instructions and available-mode rendering to match the .NET heading-based format.
- Updated the .NET console sample formatter to recognize the new
mode_settool name (but needs an additional fix; see comment).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| python/packages/core/tests/core/test_harness_mode.py | Updates assertions for new tool names and revised instruction formatting. |
| python/packages/core/agent_framework/_harness/_mode.py | Renames exposed tools to mode_set/mode_get and aligns default instructions + mode list formatting. |
| dotnet/tests/Microsoft.Agents.AI.UnitTests/Harness/AgentMode/AgentModeProviderTests.cs | Updates unit tests to use the new tool names. |
| dotnet/src/Microsoft.Agents.AI/Harness/AgentMode/AgentModeProvider.cs | Renames the generated tool names and updates docs/instructions references. |
| dotnet/samples/02-agents/Harness/Harness_Shared_Console/ToolFormatters/ModeToolFormatter.cs | Switches formatting to mode_set (but CanFormat still uses legacy prefix). |
Comments suppressed due to low confidence (1)
python/packages/core/agent_framework/_harness/_mode.py:318
- This comment still refers to the agent's "set_mode" tool call, but the tool was renamed to "mode_set" in this PR. Update the wording to match the new tool name to avoid confusing future maintainers.
context.extend_tools(self.source_id, [mode_set, mode_get])
if isinstance(previous_mode, str) and previous_mode != current_mode:
# Inject a user-role message announcing the external mode change. System instructions
# always render first in the chat history, so the agent can otherwise stay anchored to
# the most recent ``set_mode`` tool call rather than the new mode.
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 96%
✓ Correctness
This PR is a straightforward, consistent renaming of tool names from
AgentMode_Set/AgentMode_Get(dotnet) andset_mode/get_mode(Python) to the alignedmode_set/mode_getin both. All functional code references (tool definitions, instruction strings, tests, and the sample formatter) are updated correctly. No logical correctness issues found.
✓ Security Reliability
The PR correctly renames mode tools for cross-language alignment and maintains input validation in both implementations. However, the ModeToolFormatter sample has an incomplete rename: the
CanFormatmethod (line 13) still checkscall.Name.StartsWith("AgentMode_", ...), which will never match the newmode_set/mode_getnames—making theFormatDetailchange on line 18 dead code and the formatter entirely non-functional.
✓ Test Coverage
The PR correctly renames tools and updates tests for both Python and .NET providers. However,
ModeToolFormatter.cshas an incomplete rename:CanFormatstill checks for the old"AgentMode_"prefix whileFormatDetailwas updated to"mode_set", making the formatter dead code. No test coversModeToolFormatter, so this regression goes undetected. The core provider test coverage is adequate — both Python and .NET tests validate the new tool names and instruction content.
✓ Design Approach
I found one design-level gap in the rename: the .NET sample console formatter was only updated in its
FormatDetailswitch, but itsCanFormatgate still recognizes the oldAgentMode_prefix. That means renamedmode_set/mode_getcalls will no longer take the specialized formatting path in the sample client, which directly undercuts the PR’s stated goal of aligning names so clients can render them consistently.
Automated review by westey-m's agents
Motivation and Context
It's important to have similar tool names so that when rendering names in the client, we don't need different code depending on the agent language.
Description
Contribution Checklist