Skip to content

Commit f30d9ba

Browse files
committed
docs: update middleware layering docs and add RawAnthropicClient to AGENTS.md
Fixes #4789 - Update python/packages/anthropic/AGENTS.md to document RawAnthropicClient and the layered client architecture - Add Chat Client Layer Architecture section to python/packages/core/AGENTS.md explaining the standard layer ordering (FunctionInvocationLayer -> ChatMiddlewareLayer -> ChatTelemetryLayer -> Raw/Base), per-call middleware routing via client_kwargs, and raw vs public client pattern
1 parent 100086a commit f30d9ba

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

python/packages/anthropic/AGENTS.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,24 @@ Integration with Anthropic's Claude API.
44

55
## Main Classes
66

7-
- **`AnthropicClient`** - Chat client for Anthropic Claude models
7+
- **`AnthropicClient`** - Full-featured chat client for Anthropic Claude models (includes middleware, telemetry, and function invocation support)
8+
- **`RawAnthropicClient`** - Low-level chat client without middleware, telemetry, or function invocation layers. Use this only when you need to compose custom layers manually.
89
- **`AnthropicChatOptions`** - Options TypedDict for Anthropic-specific parameters
910

11+
## Client Architecture
12+
13+
`AnthropicClient` composes the standard public layer stack around `RawAnthropicClient`:
14+
15+
```
16+
AnthropicClient
17+
└─ FunctionInvocationLayer ← owns the tool/function calling loop
18+
└─ ChatMiddlewareLayer ← applies chat middleware per model call
19+
└─ ChatTelemetryLayer ← per-call telemetry (inside middleware)
20+
└─ RawAnthropicClient ← raw Anthropic API calls
21+
```
22+
23+
Most users should use `AnthropicClient`. Use `RawAnthropicClient` only if you need to apply a custom subset of layers.
24+
1025
## Usage
1126

1227
```python
@@ -19,7 +34,7 @@ response = await client.get_response("Hello")
1934
## Import Path
2035

2136
```python
22-
from agent_framework.anthropic import AnthropicClient
37+
from agent_framework.anthropic import AnthropicClient, RawAnthropicClient
2338
# or directly:
24-
from agent_framework_anthropic import AnthropicClient
39+
from agent_framework_anthropic import AnthropicClient, RawAnthropicClient
2540
```

python/packages/core/AGENTS.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,28 @@ class LoggingMiddleware(AgentMiddleware):
129129
agent = Agent(..., middleware=[LoggingMiddleware()])
130130
```
131131

132+
### Chat Client Layer Architecture
133+
134+
Public chat clients (e.g., `OpenAIChatClient`, `AnthropicClient`) compose a standard stack of mixin layers on top of a raw/base client. The layer ordering from outermost to innermost is:
135+
136+
```
137+
PublicClient (e.g., OpenAIChatClient)
138+
└─ FunctionInvocationLayer ← owns the tool/function calling loop; routes function middleware
139+
└─ ChatMiddlewareLayer ← applies chat middleware per inner model call (outside telemetry)
140+
└─ ChatTelemetryLayer ← per-call OpenTelemetry spans (inside chat middleware)
141+
└─ Raw/BaseChatClient ← raw provider API calls
142+
```
143+
144+
**Key behaviors:**
145+
- **Chat middleware runs per inner model call** — within the function calling loop, so middleware sees each individual LLM call rather than only the outer request.
146+
- **Chat middleware is outside telemetry** — middleware latency does not skew per-call telemetry timings.
147+
- **Per-call middleware** can be passed via `client_kwargs={"middleware": [...]}` on `get_response()`. Mixed chat and function middleware is automatically categorized and routed to the appropriate layer.
148+
149+
**Raw vs Public clients:**
150+
- **Raw clients** (e.g., `RawOpenAIChatClient`, `RawAnthropicClient`) only extend `BaseChatClient` — no middleware, telemetry, or function invocation support.
151+
- **Public clients** compose all standard layers around the raw client and are what most users should use.
152+
- Use raw clients only when you need to compose a custom subset of layers.
153+
132154
### Custom Chat Client
133155

134156
```python

0 commit comments

Comments
 (0)