Skip to content

Commit b065a4c

Browse files
Python: [BREAKING] update context provider APIs, middleware, and per-service-call history persistence (microsoft#4992)
* Rename provider base APIs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Allow provider-added chat and function middleware Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Simulate service-stored history per model call Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix typing regressions in CI Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix response ID suppression review feedback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Rename per-service-call history persistence APIs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address context persistence review feedback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Stabilize markdown sample docs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Persist service continuation state per call Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 38de991 commit b065a4c

37 files changed

Lines changed: 1784 additions & 344 deletions

File tree

python/packages/a2a/agent_framework_a2a/_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
AgentResponseUpdate,
3636
AgentSession,
3737
BaseAgent,
38-
BaseHistoryProvider,
3938
Content,
4039
ContinuationToken,
40+
HistoryProvider,
4141
Message,
4242
ResponseStream,
4343
SessionContext,
@@ -353,7 +353,7 @@ async def _map_a2a_stream(
353353

354354
# Run before_run providers (forward order)
355355
for provider in self.context_providers:
356-
if isinstance(provider, BaseHistoryProvider) and not provider.load_messages:
356+
if isinstance(provider, HistoryProvider) and not provider.load_messages:
357357
continue
358358
if session is None:
359359
raise RuntimeError("Provider session must be available when context providers are configured.")

python/packages/a2a/tests/test_a2a_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
AgentResponse,
2525
AgentResponseUpdate,
2626
AgentSession,
27-
BaseContextProvider,
2827
Content,
28+
ContextProvider,
2929
Message,
3030
SessionContext,
3131
)
@@ -869,7 +869,7 @@ async def test_poll_task_completed(a2a_agent: A2AAgent, mock_a2a_client: MockA2A
869869
# region Context Provider Tests
870870

871871

872-
class TrackingContextProvider(BaseContextProvider):
872+
class TrackingContextProvider(ContextProvider):
873873
"""A context provider that records when before_run and after_run are called."""
874874

875875
def __init__(self) -> None:

python/packages/azure-ai-search/agent_framework_azure_ai_search/_context_provider.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright (c) Microsoft. All rights reserved.
22

3-
"""New-pattern Azure AI Search context provider using BaseContextProvider.
3+
"""New-pattern Azure AI Search context provider using ContextProvider.
44
55
This module provides ``AzureAISearchContextProvider``, built on the new
6-
:class:`BaseContextProvider` hooks pattern.
6+
:class:`ContextProvider` hooks pattern.
77
"""
88

99
from __future__ import annotations
@@ -17,8 +17,8 @@
1717
AGENT_FRAMEWORK_USER_AGENT,
1818
AgentSession,
1919
Annotation,
20-
BaseContextProvider,
2120
Content,
21+
ContextProvider,
2222
Message,
2323
SecretString,
2424
SessionContext,
@@ -154,8 +154,8 @@ class AzureAISearchSettings(TypedDict, total=False):
154154
api_key: SecretString | None
155155

156156

157-
class AzureAISearchContextProvider(BaseContextProvider):
158-
"""Azure AI Search context provider using the new BaseContextProvider hooks pattern.
157+
class AzureAISearchContextProvider(ContextProvider):
158+
"""Azure AI Search context provider using the new ContextProvider hooks pattern.
159159
160160
Retrieves relevant context from Azure AI Search using semantic or agentic search
161161
modes.

python/packages/azure-cosmos/agent_framework_azure_cosmos/_history_provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from typing import Any, ClassVar, TypedDict
1212

1313
from agent_framework import AGENT_FRAMEWORK_USER_AGENT, Message
14-
from agent_framework._sessions import BaseHistoryProvider
14+
from agent_framework._sessions import HistoryProvider
1515
from agent_framework._settings import SecretString, load_settings
1616
from azure.core.credentials import TokenCredential
1717
from azure.core.credentials_async import AsyncTokenCredential
@@ -32,8 +32,8 @@ class AzureCosmosHistorySettings(TypedDict, total=False):
3232
key: SecretString | None
3333

3434

35-
class CosmosHistoryProvider(BaseHistoryProvider):
36-
"""Azure Cosmos DB-backed history provider using BaseHistoryProvider hooks."""
35+
class CosmosHistoryProvider(HistoryProvider):
36+
"""Azure Cosmos DB-backed history provider using HistoryProvider hooks."""
3737

3838
DEFAULT_SOURCE_ID: ClassVar[str] = "azure_cosmos_history"
3939
_BATCH_OPERATION_LIMIT: ClassVar[int] = 100

python/packages/claude/agent_framework_claude/_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
AgentRunInputs,
1717
AgentSession,
1818
BaseAgent,
19-
BaseContextProvider,
2019
Content,
20+
ContextProvider,
2121
FunctionTool,
2222
Message,
2323
ResponseStream,
@@ -223,7 +223,7 @@ def __init__(
223223
id: str | None = None,
224224
name: str | None = None,
225225
description: str | None = None,
226-
context_providers: Sequence[BaseContextProvider] | None = None,
226+
context_providers: Sequence[ContextProvider] | None = None,
227227
middleware: Sequence[AgentMiddlewareTypes] | None = None,
228228
tools: ToolTypes | Callable[..., Any] | str | Sequence[ToolTypes | Callable[..., Any] | str] | None = None,
229229
default_options: OptionsT | MutableMapping[str, Any] | None = None,

python/packages/copilotstudio/agent_framework_copilotstudio/_agent.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
AgentResponseUpdate,
1212
AgentSession,
1313
BaseAgent,
14-
BaseContextProvider,
1514
Content,
15+
ContextProvider,
1616
Message,
1717
ResponseStream,
1818
normalize_messages,
@@ -60,7 +60,7 @@ def __init__(
6060
id: str | None = None,
6161
name: str | None = None,
6262
description: str | None = None,
63-
context_providers: Sequence[BaseContextProvider] | None = None,
63+
context_providers: Sequence[ContextProvider] | None = None,
6464
middleware: list[AgentMiddlewareTypes] | None = None,
6565
environment_id: str | None = None,
6666
agent_identifier: str | None = None,

python/packages/core/AGENTS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ agent_framework/
6161

6262
- **`AgentSession`** - Manages conversation state and session metadata
6363
- **`SessionContext`** - Context object for session-scoped data during agent runs
64-
- **`BaseContextProvider`** - Base class for context providers (RAG, memory systems)
65-
- **`BaseHistoryProvider`** - Base class for conversation history storage
64+
- **`ContextProvider`** - Base class for context providers (RAG, memory systems)
65+
- **`HistoryProvider`** - Base class for conversation history storage
6666

6767
### Skills (`_skills.py`)
6868

6969
- **`Skill`** - A skill definition bundling instructions (`content`) with metadata, resources, and scripts. Supports `@skill.resource` and `@skill.script` decorators for adding components.
7070
- **`SkillResource`** - Named supplementary content attached to a skill; holds either static `content` or a dynamic `function` (sync or async). Exactly one must be provided.
7171
- **`SkillScript`** - An executable script attached to a skill; holds either an inline `function` (code-defined, runs in-process) or a `path` to a file on disk (file-based, delegated to a runner). Exactly one must be provided.
7272
- **`SkillScriptRunner`** - Protocol for file-based script execution. Any callable matching `(skill, script, args) -> Any` satisfies it. Code-defined scripts do not use a runner.
73-
- **`SkillsProvider`** - Context provider (extends `BaseContextProvider`) that discovers file-based skills from `SKILL.md` files and/or accepts code-defined `Skill` instances. Follows progressive disclosure: advertise → load → read resources / run scripts.
73+
- **`SkillsProvider`** - Context provider (extends `ContextProvider`) that discovers file-based skills from `SKILL.md` files and/or accepts code-defined `Skill` instances. Follows progressive disclosure: advertise → load → read resources / run scripts.
7474

7575
### Workflows (`_workflows/`)
7676

python/packages/core/agent_framework/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@
102102
)
103103
from ._sessions import (
104104
AgentSession,
105-
BaseContextProvider,
106-
BaseHistoryProvider,
105+
BaseContextProvider, # type: ignore[reportDeprecated]
106+
BaseHistoryProvider, # type: ignore[reportDeprecated]
107+
ContextProvider,
108+
HistoryProvider,
107109
InMemoryHistoryProvider,
108110
SessionContext,
109111
register_state_type,
@@ -296,6 +298,7 @@
296298
"CompactionProvider",
297299
"CompactionStrategy",
298300
"Content",
301+
"ContextProvider",
299302
"ContinuationToken",
300303
"ConversationSplit",
301304
"ConversationSplitter",
@@ -331,6 +334,7 @@
331334
"FunctionTool",
332335
"GeneratedEmbeddings",
333336
"GraphConnectivityError",
337+
"HistoryProvider",
334338
"InMemoryCheckpointStorage",
335339
"InMemoryHistoryProvider",
336340
"InProcRunnerContext",

0 commit comments

Comments
 (0)