You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Sync Python 1.0.0 docs
Update the Agent Framework docs to reflect the final Python 1.0.0 changes, including the stable package installs, final Message(contents=...) construction change, and the latest breaking-change guidance.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Fix OpenAI provider tab IDs
Resolve the duplicate DocFX tab-id warning in the OpenAI provider page by giving the configuration and creation tab groups distinct IDs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@@ -40,13 +40,13 @@ The `Agent` class builds a pipeline through class composition with two main comp
40
40
**Agent** (outer component):
41
41
42
42
1.**Agent Middleware + Telemetry** - the `AgentMiddlewareLayer` and `AgentTelemetryLayer` classes handle middleware invocation and OpenTelemetry instrumentation
43
-
2.**RawAgent** - Core agent logic that invokes context providers
44
-
3.**Context Providers** - Unified `context_providers` list manages history and additional context
43
+
2.**RawAgent** - Core agent logic that invokes context providers and collects provider-added middleware
44
+
3.**Context Providers** - Unified `context_providers` list manages history, additional context, and per-run chat/function middleware
45
45
46
46
**ChatClient** (separate and interchangeable component):
47
47
48
48
1.**FunctionInvocation** - Handles tool calling loop, invoking Function Middleware + Telemetry per tool call
49
-
2.**Chat Middleware + Telemetry** - Optional middleware chain and instrumentation layers, running per model call
49
+
2.**Chat Middleware + Telemetry** - Optional middleware chain and instrumentation layers, including any chat middleware added by context providers, running per model call
50
50
3.**RawChatClient** - Provider-specific implementation (Azure OpenAI, OpenAI, Anthropic, etc.) that communicates with the LLM
51
51
52
52
When you call `run()`, your request flows through the Agent layers, then into the ChatClient pipeline for LLM communication.
@@ -144,6 +144,8 @@ agent = Agent(
144
144
)
145
145
```
146
146
147
+
Context providers can also attach chat or function middleware to a single invocation via `SessionContext.extend_middleware()`. The agent flattens those additions in provider order before entering the ChatClient pipeline.
148
+
147
149
::: zone-end
148
150
149
151
For detailed context provider patterns, see [Context Providers](./conversations/context-providers.md).
@@ -228,14 +230,14 @@ When you invoke an agent, the request flows through the pipeline:
228
230
**Agent pipeline:**
229
231
230
232
1.**Agent Middleware + Telemetry** executes middleware (if configured) and records spans
231
-
2.**RawAgent** invokes context providers to load history and add context
233
+
2.**RawAgent** invokes context providers to load history, add context, and collect provider-added chat/function middleware
232
234
3. Request is passed to the ChatClient
233
235
234
236
**ChatClient pipeline:**
235
237
236
238
4.**FunctionInvocation** manages the tool calling loop
237
-
- For each tool call, **Function Middleware + Telemetry** executes
238
-
5.**Chat Middleware + Telemetry** executes per model call (if configured)
239
+
- For each tool call, **Function Middleware + Telemetry** executes, including any function middleware added by context providers
240
+
5.**Chat Middleware + Telemetry** executes per model call (if configured), including any chat middleware added by context providers
239
241
6.**RawChatClient** handles provider-specific LLM communication
240
242
7. Response flows back through the same layers
241
243
8.**Context providers** are notified of new messages for storage
@@ -276,6 +278,16 @@ var copilotAgent = originalCopilotAgent
276
278
::: zone-end
277
279
278
280
::: zone pivot="programming-language-python"
281
+
282
+
## Other agent types
283
+
284
+
Not every Python agent uses the full `Agent` + `ChatClient` pipeline. `GitHubCopilotAgent`, for example, sends requests through the GitHub Copilot CLI instead of a local chat client.
285
+
286
+
Even so, Python `GitHubCopilotAgent` still supports agent middleware and now runs `context_providers` around each invocation. Provider-added messages and instructions are included in the prompt sent to Copilot, and providers receive the matching `after_run` callback once a response is available.
287
+
288
+
> [!NOTE]
289
+
> Because `GitHubCopilotAgent` does not use a local chat client, chat client middleware still does not apply.
290
+
279
291
::: zone-end
280
292
281
293
## Next steps
@@ -287,4 +299,4 @@ var copilotAgent = originalCopilotAgent
287
299
288
300
-[Middleware](./middleware/index.md) - Add cross-cutting behavior to your agents
289
301
-[Context Providers](./conversations/context-providers.md) - Detailed patterns for history and context injection
290
-
-[Running Agents](./running-agents.md) - How to invoke agents
302
+
-[Running Agents](./running-agents.md) - How to invoke agents
> `ContextProvider` and `HistoryProvider` are the canonical Python base classes. `BaseContextProvider` and `BaseHistoryProvider` still exist as deprecated aliases for compatibility, but new providers should inherit from the new names.
319
+
>
320
+
> Context providers can also add chat or function middleware for the current invocation by calling `context.extend_middleware(self.source_id, middleware)`. The agent flattens those additions with `context.get_middleware()` and applies them in provider order before invoking the chat client.
321
+
317
322
:::zone-end
318
323
319
324
:::zone pivot="programming-language-python"
@@ -326,10 +331,10 @@ History providers are context providers specialized for loading/storing messages
326
331
from collections.abc import Sequence
327
332
from typing import Any
328
333
329
-
from agent_framework importBaseHistoryProvider, Message
334
+
from agent_framework importHistoryProvider, Message
@@ -365,6 +370,7 @@ class DatabaseHistoryProvider(BaseHistoryProvider):
365
370
> [!IMPORTANT]
366
371
> In Python, you can configure multiple history providers, but **only one** should use `load_messages=True`.
367
372
> Use additional providers for diagnostics/evals with `load_messages=False` and `store_context_messages=True` so they capture context from other providers alongside input/output.
373
+
> If you need local history to persist around each model call in a tool loop, see [Storage](./storage.md#per-service-call-local-history-persistence).
Tool-calling runs can make multiple model calls before a single `agent.run()` completes. By default, local history providers persist once after the full run. If you want local history to mirror service-managed conversations more closely, set `require_per_service_call_history_persistence=True` so history providers run around each model call instead.
126
+
127
+
:::zone pivot="programming-language-python"
128
+
129
+
```python
130
+
from agent_framework import Agent, InMemoryHistoryProvider
131
+
from agent_framework.openai import OpenAIChatClient
> Use this mode only for framework-managed local history. If the run is already bound to a service-managed conversation (for example via `session.service_session_id` or `options={"conversation_id": ...}`), Agent Framework raises an error instead of mixing the two persistence models.
144
+
>
145
+
> This mode is especially useful when middleware can terminate immediately after a tool call: persisting per model call keeps local history aligned with what a service-managed conversation would keep.
146
+
147
+
:::zone-end
148
+
123
149
## Third-party/Custom storage pattern
124
150
125
151
For database/Redis/blob-backed history, implement a custom history provider.
0 commit comments