Python: Core: add experimental session-mode harness context provider#5611
Python: Core: add experimental session-mode harness context provider#5611eavanvalkenburg merged 5 commits intomicrosoft:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces the first experimental Python harness context provider in agent_framework: a session-backed mode provider that exposes get_mode / set_mode tools and helper APIs for reading and updating the current session mode. It extends the existing feature-staging system with a new HARNESS experimental feature and wires the new symbols into the package surface.
Changes:
- Add
SessionModeContextProviderplus session-mode helper APIs/constants under the new_harnessnamespace. - Export the new harness symbols from
agent_framework.__init__and addExperimentalFeature.HARNESS. - Add focused tests for helper behavior, provider configuration, and tool-driven session mode updates; also refactor
_sessions.pyto usecontextlib.suppress(ImportError).
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
python/packages/core/tests/core/test_harness_mode.py |
Adds tests for session-mode helpers, experimental metadata, and provider tools. |
python/packages/core/agent_framework/_sessions.py |
Minor cleanup replacing try/except ImportError with suppress(ImportError). |
python/packages/core/agent_framework/_harness/_mode.py |
Implements the new session-mode helpers and SessionModeContextProvider. |
python/packages/core/agent_framework/_harness/__init__.py |
Creates the new harness package namespace. |
python/packages/core/agent_framework/_feature_stage.py |
Adds the HARNESS experimental feature enum member. |
python/packages/core/agent_framework/__init__.py |
Re-exports the new harness symbols from the public package API. |
374da8d to
bfb0e97
Compare
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||||||||||||
49d26f4 to
a6831c5
Compare
Introduces the _harness namespace and the first context provider: SessionModeContextProvider, with get_session_mode / set_session_mode helpers and a DEFAULT_MODE_SOURCE_ID constant. Behind @experimental(ExperimentalFeature.HARNESS). Also folds in a small _sessions.py cleanup (try/except ImportError -> contextlib.suppress) touched while developing the harness. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Mirror the default mode descriptions and instruction template used by the .NET AgentModeProvider so the cross-language harness UX is consistent. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- json.dumps tool outputs to stay valid for arbitrary mode names - normalize configured mode keys (lower+strip) so custom-cased configs work - raise TypeError instead of silently replacing non-dict session state - mark get_session_mode/set_session_mode as @experimental(HARNESS) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Match the .NET AgentModeProvider class name for cross-language consistency. Helpers renamed accordingly: get_session_mode -> get_agent_mode, set_session_mode -> set_agent_mode. The default source_id is now "agent_mode". Construction pattern stays Pythonic (kwargs, not an options object). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- default_mode now defaults to None and falls back to the first configured mode, decoupling the kwarg from the built-in 'plan'/'execute' set. - get_agent_mode catches ValueError when a previously persisted mode is no longer in available_modes and resets to the default mode (matching the non-string recovery branch). Added regression coverage for both behaviors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
a6831c5 to
f3ddb88
Compare
|
Addressed reviewer feedback about external mode changes confusing the agent. When the user changes the mode externally (e.g., via a slash-command), the chat history still shows a prior Aligned with the .NET
Tests cover: external change injects exactly one notification and clears the flag; a follow-up run without further changes does not re-inject; the agent's own |
Motivation and Context
Part of the experimental Agent Harness feature, mirroring the .NET work shipped in PR #5310 (.NET: Harness Feature branch) and follow-ups #5404, #5365, #5540. The harness is a set of context providers that make it easier to build long-running, plan-and-execute agents with persistent session state.
This PR introduces the Python counterpart of
AgentModeProviderfromdotnet/src/Microsoft.Agents.AI/Harness/AgentMode/.Description
Adds the experimental
_harnessnamespace and the first context provider in it:AgentModeProvider, withget_agent_mode/set_agent_modehelpers and aDEFAULT_MODE_SOURCE_IDconstant. NewHARNESSvalue added to theExperimentalFeatureenum; all new public symbols decorated with@experimental(ExperimentalFeature.HARNESS).AgentModeProviderAgentModeProviderAgentModeProviderOptions.Modesavailable_modes/mode_descriptionskwargsAgentMode_Get/AgentMode_Settoolsget_mode/set_modesnake_case tools registered via@toolGetMode/SetModehelpersget_agent_mode/set_agent_modemodule-level helpersThe provider class name now matches .NET exactly as a refinement for cross-language consistency. The remaining differences are deliberate to match each language's conventions:
"plan","execute") and the default instruction template are aligned with .NET so cross-language behavior matches.Also folds in a tiny cosmetic refactor of
_sessions.py(try/except ImportError: pass→contextlib.suppress(ImportError)) that was made while developing the harness.This PR is the first of three splitting the
_harnesspackage work apart for review:AgentModeProviderTodoProviderFileMemoryProviderThe three modules are independent. They share only the
HARNESSenum entry and the (empty)_harness/__init__.py. Whichever lands first creates those; the others rebase trivially.Contribution Checklist
@experimental(ExperimentalFeature.HARNESS).