Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit 440f6e3

Browse files
authored
docs: cleanup from TS scan. Add missing prose and examples. Remove in… (#849)
1 parent ade7d78 commit 440f6e3

21 files changed

Lines changed: 367 additions & 28 deletions

src/content/docs/user-guide/concepts/agents/conversation-management.mdx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,14 @@ agent = Agent(
304304
</Tab>
305305
<Tab label="TypeScript">
306306

307-
```ts
308-
// Not supported in TypeScript
307+
Pass a custom `model` to `SummarizingConversationManager` to override the model used for summarization. This enables using a different model, such as a faster or more cost-effective one, without affecting the agent's primary model. Injecting a full `Agent` (with its own tools, hooks, or plugins) for summarization is not currently supported in TypeScript.
308+
309+
```typescript
310+
--8<-- "user-guide/concepts/agents/conversation-management_imports.ts:summarizing_conversation_manager_advanced_imports"
311+
312+
--8<-- "user-guide/concepts/agents/conversation-management.ts:summarizing_conversation_manager_advanced"
309313
```
314+
310315
</Tab>
311316
</Tabs>
312317

src/content/docs/user-guide/concepts/agents/conversation-management.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
SummarizingConversationManager,
88
BedrockModel,
99
} from '@strands-agents/sdk'
10+
import { AnthropicModel } from '@strands-agents/sdk/models/anthropic'
1011
import type { LocalAgent, ConversationManagerReduceOptions } from '@strands-agents/sdk'
1112

1213
async function nullConversationManagerAgent() {
@@ -98,6 +99,27 @@ async function summarizingCustom() {
9899
// --8<-- [end:summarizing_conversation_manager_custom]
99100
}
100101

102+
async function summarizingAdvanced() {
103+
// --8<-- [start:summarizing_conversation_manager_advanced]
104+
// Use a cheaper, faster model for summarization tasks
105+
const summarizationModel = new AnthropicModel({
106+
modelId: 'claude-haiku-4-5-20251001',
107+
maxTokens: 1000,
108+
params: { temperature: 0.1 }, // Low temperature for consistent summaries
109+
})
110+
111+
const conversationManager = new SummarizingConversationManager({
112+
model: summarizationModel,
113+
summaryRatio: 0.4,
114+
preserveRecentMessages: 8,
115+
})
116+
117+
const agent = new Agent({
118+
conversationManager,
119+
})
120+
// --8<-- [end:summarizing_conversation_manager_advanced]
121+
}
122+
101123
async function summarizingSystemPrompt() {
102124
// --8<-- [start:summarizing_conversation_manager_system_prompt]
103125
// Custom system prompt for technical conversations

src/content/docs/user-guide/concepts/agents/conversation-management_imports.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ import { Agent, SummarizingConversationManager, BedrockModel } from '@strands-ag
3838
import { Agent, SummarizingConversationManager } from '@strands-agents/sdk'
3939
// --8<-- [end:summarizing_conversation_manager_system_prompt_imports]
4040

41+
// --8<-- [start:summarizing_conversation_manager_advanced_imports]
42+
import { Agent, SummarizingConversationManager } from '@strands-agents/sdk'
43+
import { AnthropicModel } from '@strands-agents/sdk/models/anthropic'
44+
// --8<-- [end:summarizing_conversation_manager_advanced_imports]
45+
4146
// --8<-- [start:proactive_sliding_window_imports]
4247
import {
4348
Agent,

src/content/docs/user-guide/concepts/model-providers/amazon-bedrock.mdx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -883,10 +883,12 @@ Strands allows you to enable and configure reasoning capabilities with your [`Be
883883
884884
### Structured Output
885885

886+
Amazon Bedrock models support structured output through their tool calling capabilities. Pass a schema to the agent, and Strands converts it to Bedrock's tool specification format and validates the response.
887+
886888
<Tabs>
887889
<Tab label="Python">
888890

889-
Amazon Bedrock models support structured output through their tool calling capabilities. When you use `Agent.structured_output()`, the Strands SDK converts your schema to Bedrock's tool specification format.
891+
Define a Pydantic model and pass it to `agent.structured_output()`:
890892

891893
```python
892894
from pydantic import BaseModel, Field
@@ -924,12 +926,18 @@ print(f"Rating: {result.rating}")
924926
</Tab>
925927
<Tab label="TypeScript">
926928

927-
```ts
928-
// Structured output is not yet supported in the TypeScript SDK
929+
Define a Zod schema and pass it as `structuredOutputSchema`. Validated output is on `result.structuredOutput`:
930+
931+
```typescript
932+
--8<-- "user-guide/concepts/model-providers/amazon-bedrock_imports.ts:structured_output_imports"
933+
934+
--8<-- "user-guide/concepts/model-providers/amazon-bedrock.ts:structured_output"
929935
```
930936
</Tab>
931937
</Tabs>
932938

939+
For schema patterns, error handling, and per-invocation overrides, see [Structured Output](../agents/structured-output/).
940+
933941
### Token Counting
934942

935943
Token counting is used by context management strategies to estimate input tokens before each model call.

src/content/docs/user-guide/concepts/model-providers/amazon-bedrock.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
CachePointBlock,
1313
Message,
1414
} from '@strands-agents/sdk'
15+
import { z } from 'zod'
1516

1617
// Basic usage examples
1718
async function basicUsageDefault() {
@@ -440,3 +441,36 @@ async function requestTimeoutExample() {
440441
}
441442

442443
void requestTimeoutExample
444+
445+
async function structuredOutputExample() {
446+
// --8<-- [start:structured_output]
447+
const ProductAnalysis = z.object({
448+
name: z.string().describe('Product name'),
449+
category: z.string().describe('Product category'),
450+
price: z.number().describe('Price in USD'),
451+
features: z.array(z.string()).describe('Key product features'),
452+
rating: z.number().min(1).max(5).optional().describe('Customer rating 1-5'),
453+
})
454+
455+
const bedrockModel = new BedrockModel()
456+
const agent = new Agent({
457+
model: bedrockModel,
458+
structuredOutputSchema: ProductAnalysis,
459+
})
460+
461+
const result = await agent.invoke(
462+
`Analyze this product: The UltraBook Pro is a premium laptop computer
463+
priced at $1,299. It features a 15-inch 4K display, 16GB RAM, 512GB SSD,
464+
and 12-hour battery life. Customer reviews average 4.5 stars.`
465+
)
466+
467+
const product = result.structuredOutput as z.infer<typeof ProductAnalysis>
468+
console.log(`Product: ${product.name}`)
469+
console.log(`Category: ${product.category}`)
470+
console.log(`Price: $${product.price}`)
471+
console.log(`Features: ${product.features.join(', ')}`)
472+
console.log(`Rating: ${product.rating}`)
473+
// --8<-- [end:structured_output]
474+
}
475+
476+
void structuredOutputExample

src/content/docs/user-guide/concepts/model-providers/amazon-bedrock_imports.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ import { BedrockModel } from '@strands-agents/sdk/models/bedrock'
1616
// --8<-- [start:request_timeout_imports]
1717
import { BedrockModel } from '@strands-agents/sdk/models/bedrock'
1818
// --8<-- [end:request_timeout_imports]
19+
20+
// --8<-- [start:structured_output_imports]
21+
import { Agent } from '@strands-agents/sdk'
22+
import { BedrockModel } from '@strands-agents/sdk/models/bedrock'
23+
import { z } from 'zod'
24+
// --8<-- [end:structured_output_imports]

src/content/docs/user-guide/concepts/model-providers/anthropic.mdx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,65 @@ The Python SDK does not currently support passing a pre-configured client. Use `
141141
</Tab>
142142
</Tabs>
143143

144+
### Structured Output
145+
146+
Anthropic models support structured output through tool use. Pass a schema to the agent, and Strands generates a tool from it that the model calls to return validated, type-safe data.
147+
148+
<Tabs>
149+
<Tab label="Python">
150+
151+
Define a Pydantic model and pass it to [`agent.structured_output()`](@api/python/strands.agent.agent#Agent.structured_output):
152+
153+
```python
154+
from pydantic import BaseModel, Field
155+
from strands import Agent
156+
from strands.models.anthropic import AnthropicModel
157+
158+
class MovieReview(BaseModel):
159+
"""Analyze a movie review."""
160+
title: str = Field(description="Movie title")
161+
rating: int = Field(description="Rating from 1-10", ge=1, le=10)
162+
genre: str = Field(description="Primary genre")
163+
sentiment: str = Field(description="Overall sentiment: positive, negative, or neutral")
164+
summary: str = Field(description="Brief summary of the review")
165+
166+
model = AnthropicModel(
167+
client_args={"api_key": "<KEY>"},
168+
max_tokens=1028,
169+
model_id="claude-sonnet-4-6",
170+
)
171+
172+
agent = Agent(model=model)
173+
174+
result = agent.structured_output(
175+
MovieReview,
176+
"""
177+
Just watched "The Matrix" - what an incredible sci-fi masterpiece!
178+
The groundbreaking visual effects and philosophical themes make this
179+
a must-watch. Keanu Reeves delivers a solid performance. 9/10!
180+
"""
181+
)
182+
183+
print(f"Movie: {result.title}")
184+
print(f"Rating: {result.rating}/10")
185+
print(f"Genre: {result.genre}")
186+
print(f"Sentiment: {result.sentiment}")
187+
```
188+
</Tab>
189+
<Tab label="TypeScript">
190+
191+
Define a Zod schema and pass it as `structuredOutputSchema`. Validated output is on `result.structuredOutput`:
192+
193+
```typescript
194+
--8<-- "user-guide/concepts/model-providers/anthropic_imports.ts:structured_output_imports"
195+
196+
--8<-- "user-guide/concepts/model-providers/anthropic.ts:structured_output"
197+
```
198+
</Tab>
199+
</Tabs>
200+
201+
For schema patterns, error handling, and per-invocation overrides, see [Structured Output](../agents/structured-output/).
202+
144203
### Token Counting
145204

146205
Token counting is used by context management strategies to estimate input tokens before each model call.

src/content/docs/user-guide/concepts/model-providers/anthropic.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import Anthropic from '@anthropic-ai/sdk'
77
import { Agent } from '@strands-agents/sdk'
88
import { AnthropicModel } from '@strands-agents/sdk/models/anthropic'
9+
import { z } from 'zod'
910

1011
// Basic usage
1112
async function basicUsage() {
@@ -41,3 +42,38 @@ async function customClient() {
4142
console.log(response)
4243
// --8<-- [end:custom_client]
4344
}
45+
46+
// Structured output
47+
async function structuredOutputExample() {
48+
// --8<-- [start:structured_output]
49+
const MovieReview = z.object({
50+
title: z.string().describe('Movie title'),
51+
rating: z.number().min(1).max(10).describe('Rating from 1-10'),
52+
genre: z.string().describe('Primary genre'),
53+
sentiment: z.enum(['positive', 'negative', 'neutral']).describe('Overall sentiment'),
54+
summary: z.string().describe('Brief summary of the review'),
55+
})
56+
57+
const model = new AnthropicModel({
58+
apiKey: '<KEY>',
59+
modelId: 'claude-sonnet-4-6',
60+
maxTokens: 1028,
61+
})
62+
63+
const agent = new Agent({ model, structuredOutputSchema: MovieReview })
64+
65+
const result = await agent.invoke(
66+
`Just watched "The Matrix" - what an incredible sci-fi masterpiece!
67+
The groundbreaking visual effects and philosophical themes make this
68+
a must-watch. Keanu Reeves delivers a solid performance. 9/10!`
69+
)
70+
71+
const review = result.structuredOutput as z.infer<typeof MovieReview>
72+
console.log(`Movie: ${review.title}`)
73+
console.log(`Rating: ${review.rating}/10`)
74+
console.log(`Genre: ${review.genre}`)
75+
console.log(`Sentiment: ${review.sentiment}`)
76+
// --8<-- [end:structured_output]
77+
}
78+
79+
void structuredOutputExample

src/content/docs/user-guide/concepts/model-providers/anthropic_imports.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ import Anthropic from '@anthropic-ai/sdk'
1010
import { Agent } from '@strands-agents/sdk'
1111
import { AnthropicModel } from '@strands-agents/sdk/models/anthropic'
1212
// --8<-- [end:custom_client_imports]
13+
14+
// --8<-- [start:structured_output_imports]
15+
import { Agent } from '@strands-agents/sdk'
16+
import { AnthropicModel } from '@strands-agents/sdk/models/anthropic'
17+
import { z } from 'zod'
18+
// --8<-- [end:structured_output_imports]

src/content/docs/user-guide/concepts/model-providers/google.mdx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,13 @@ except ModelThrottledException as e:
256256

257257
### Structured Output
258258

259-
Gemini models support structured output through their native JSON schema capabilities. When you use [`Agent.structured_output()`](@api/python/strands.agent.agent#Agent.structured_output), the Strands SDK automatically converts your Pydantic models to Gemini's JSON schema format.
259+
Gemini models support structured output through their native JSON schema capabilities. Pass a schema to the agent, and Strands converts it to Gemini's JSON schema format and validates the response.
260260

261261
<Tabs>
262262
<Tab label="Python">
263263

264+
Define a Pydantic model and pass it to [`agent.structured_output()`](@api/python/strands.agent.agent#Agent.structured_output):
265+
264266
```python
265267
from pydantic import BaseModel, Field
266268
from strands import Agent
@@ -303,12 +305,18 @@ print(f"Sentiment: {result.sentiment}")
303305
</Tab>
304306
<Tab label="TypeScript">
305307

306-
```ts
307-
// Structured output is not yet supported for Gemini in the TypeScript SDK
308+
Define a Zod schema and pass it as `structuredOutputSchema`. Validated output is on `result.structuredOutput`:
309+
310+
```typescript
311+
--8<-- "user-guide/concepts/model-providers/google_imports.ts:structured_output_imports"
312+
313+
--8<-- "user-guide/concepts/model-providers/google.ts:structured_output"
308314
```
309315
</Tab>
310316
</Tabs>
311317

318+
For schema patterns, error handling, and per-invocation overrides, see [Structured Output](../agents/structured-output/).
319+
312320
### Custom client
313321

314322
Users can pass their own custom Gemini client to the GeminiModel for Strands Agents to use directly. Users are responsible for handling the lifecycle (e.g., closing) of the client.

0 commit comments

Comments
 (0)