Skip to content

Commit 588eaba

Browse files
author
Owen Kaplan
committed
feat: add 90 line max prettier rule for code snippets
1 parent 86bbbed commit 588eaba

26 files changed

Lines changed: 286 additions & 101 deletions

AGENTS.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ All checks must pass before commit is allowed.
124124
- No semicolons
125125
- Single quotes
126126
- Line length: 120 characters
127+
- Line length for doc snippet files under `src/content/docs/`: 90 characters
127128
- Tab width: 2 spaces
128129
- Trailing commas in ES5 style
130+
- Template literal contents in doc snippets must also stay under 90 characters per line. Prettier does not enforce this automatically.
129131

130132
**Example**:
131133
```typescript
@@ -288,8 +290,8 @@ const result = await agent.invoke('Hello')
288290
{
289291
"scripts": {
290292
"test": "tsc --noEmit",
291-
"format": "prettier --write docs",
292-
"format:check": "prettier --check docs"
293+
"format": "prettier --write docs 'src/content/docs/**/*.ts'",
294+
"format:check": "prettier --check docs 'src/content/docs/**/*.ts'"
293295
}
294296
}
295297
```

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"test": "vitest run",
1010
"typecheck": "tsc --noEmit",
1111
"typecheck:snippets": "npm run typecheck --prefix test-snippets",
12-
"format": "prettier --write docs",
13-
"format:check": "prettier --check docs",
12+
"format": "prettier --write docs 'src/content/docs/**/*.ts'",
13+
"format:check": "prettier --check docs 'src/content/docs/**/*.ts'",
1414
"clean": "rm -rf .build && rm -rf .astro",
1515
"preview": "astro preview",
1616
"cms:build": "npm run build:all",
@@ -76,6 +76,14 @@
7676
"singleQuote": true,
7777
"printWidth": 120,
7878
"tabWidth": 2,
79-
"trailingComma": "es5"
79+
"trailingComma": "es5",
80+
"overrides": [
81+
{
82+
"files": "src/content/docs/**/*.ts",
83+
"options": {
84+
"printWidth": 90
85+
}
86+
}
87+
]
8088
}
8189
}

src/content/docs/readme.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import { Agent } from '@strands-agents/sdk'
44

55
// Create an agent with default settings
6-
const agent = new Agent();
6+
const agent = new Agent()
77

88
// Ask the agent a question
9-
const response = await agent.invoke("Tell me about agentic AI");
10-
console.log(response.lastMessage);
9+
const response = await agent.invoke('Tell me about agentic AI')
10+
console.log(response.lastMessage)
1111
// --8<-- [end:basicAgent]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ agent = Agent(
302302
</Tab>
303303
</Tabs>
304304

305-
Key features:
305+
#### Key Features
306306

307307
- **Context Window Management**: Automatically reduces context when token limits are exceeded
308308
- **Intelligent Summarization**: Uses structured bullet-point summaries to capture key information

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { Agent, ConversationManager, AfterInvocationEvent, NullConversationManager, SlidingWindowConversationManager, SummarizingConversationManager, BedrockModel } from '@strands-agents/sdk'
1+
import {
2+
Agent,
3+
ConversationManager,
4+
AfterInvocationEvent,
5+
NullConversationManager,
6+
SlidingWindowConversationManager,
7+
SummarizingConversationManager,
8+
BedrockModel,
9+
} from '@strands-agents/sdk'
210
import type { LocalAgent, ConversationManagerReduceOptions } from '@strands-agents/sdk'
311

412
async function nullConversationManagerAgent() {
@@ -93,13 +101,16 @@ async function summarizingCustom() {
93101
async function summarizingSystemPrompt() {
94102
// --8<-- [start:summarizing_conversation_manager_system_prompt]
95103
// Custom system prompt for technical conversations
96-
const customSystemPrompt = `You are summarizing a technical conversation. Create a concise bullet-point summary that:
104+
const customSystemPrompt = `
105+
You are summarizing a technical conversation.
106+
Create a concise bullet-point summary that:
97107
- Focuses on code changes, architectural decisions, and technical solutions
98108
- Preserves specific function names, file paths, and configuration details
99109
- Omits conversational elements and focuses on actionable information
100110
- Uses technical terminology appropriate for software development
101111
102-
Format as bullet points without conversational language.`
112+
Format as bullet points without conversational language.
113+
`
103114

104115
const conversationManager = new SummarizingConversationManager({
105116
summarizationSystemPrompt: customSystemPrompt,

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,21 @@ import { Agent, SlidingWindowConversationManager } from '@strands-agents/sdk'
99
// --8<-- [end:sliding_window_conversation_manager_imports]
1010

1111
// --8<-- [start:custom_conversation_manager_imports]
12-
import { Agent, ConversationManager, type ConversationManagerReduceOptions } from '@strands-agents/sdk'
12+
import {
13+
Agent,
14+
ConversationManager,
15+
type ConversationManagerReduceOptions,
16+
} from '@strands-agents/sdk'
1317
// --8<-- [end:custom_conversation_manager_imports]
1418

1519
// --8<-- [start:custom_conversation_manager_proactive_imports]
16-
import { Agent, ConversationManager, AfterInvocationEvent, type AgentData, type ConversationManagerReduceOptions } from '@strands-agents/sdk'
20+
import {
21+
Agent,
22+
ConversationManager,
23+
AfterInvocationEvent,
24+
type AgentData,
25+
type ConversationManagerReduceOptions,
26+
} from '@strands-agents/sdk'
1727
// --8<-- [end:custom_conversation_manager_proactive_imports]
1828

1929
// --8<-- [start:summarizing_conversation_manager_basic_imports]

src/content/docs/user-guide/concepts/agents/hooks.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import {
99
AfterModelCallEvent,
1010
MessageAddedEvent,
1111
} from '@strands-agents/sdk'
12-
import { Graph, Swarm, BeforeNodeCallEvent, AfterNodeCallEvent } from '@strands-agents/sdk/multiagent'
12+
import {
13+
Graph,
14+
Swarm,
15+
BeforeNodeCallEvent,
16+
AfterNodeCallEvent,
17+
} from '@strands-agents/sdk/multiagent'
1318
import type { MultiAgent, MultiAgentPlugin } from '@strands-agents/sdk/multiagent'
1419

1520
// Mock tools for examples
@@ -108,7 +113,9 @@ async function resultModificationExample() {
108113
private processResult(event: AfterToolCallEvent): void {
109114
if (event.toolUse.name === 'calculator') {
110115
// Add formatting to calculator results
111-
const textContent = event.result.content.find((block) => block.type === 'textBlock')
116+
const textContent = event.result.content.find(
117+
(block) => block.type === 'textBlock'
118+
)
112119
if (textContent && textContent.type === 'textBlock') {
113120
// Note: In actual implementation, result modification may work differently
114121
console.log(`Would modify result: ${textContent.text}`)
@@ -162,7 +169,9 @@ async function loggingModificationsExample() {
162169

163170
private processResult(event: AfterToolCallEvent): void {
164171
if (event.toolUse.name === 'calculator') {
165-
const textContent = event.result.content.find((block) => block.type === 'textBlock')
172+
const textContent = event.result.content.find(
173+
(block) => block.type === 'textBlock'
174+
)
166175
if (textContent && textContent.type === 'textBlock') {
167176
const originalContent = textContent.text
168177
console.log(`Modifying calculator result: ${originalContent}`)
@@ -230,8 +239,14 @@ async function fixedToolArgumentsExample() {
230239

231240
async function orchestratorCallbackExample() {
232241
// --8<-- [start:orchestrator_callback]
233-
const researcher = new Agent({ id: 'researcher', systemPrompt: 'You are a research specialist.' })
234-
const writer = new Agent({ id: 'writer', systemPrompt: 'You are a writing specialist.' })
242+
const researcher = new Agent({
243+
id: 'researcher',
244+
systemPrompt: 'You are a research specialist.',
245+
})
246+
const writer = new Agent({
247+
id: 'writer',
248+
systemPrompt: 'You are a writing specialist.',
249+
})
235250

236251
const graph = new Graph({
237252
nodes: [researcher, writer],
@@ -251,9 +266,18 @@ async function orchestratorCallbackExample() {
251266

252267
async function conditionalNodeExecutionExample() {
253268
// --8<-- [start:conditional_node_execution]
254-
const researcher = new Agent({ id: 'researcher', systemPrompt: 'You are a research specialist.' })
255-
const writer = new Agent({ id: 'writer', systemPrompt: 'You are a writing specialist.' })
256-
const reviewer = new Agent({ id: 'reviewer', systemPrompt: 'You are a review specialist.' })
269+
const researcher = new Agent({
270+
id: 'researcher',
271+
systemPrompt: 'You are a research specialist.',
272+
})
273+
const writer = new Agent({
274+
id: 'writer',
275+
systemPrompt: 'You are a writing specialist.',
276+
})
277+
const reviewer = new Agent({
278+
id: 'reviewer',
279+
systemPrompt: 'You are a review specialist.',
280+
})
257281

258282
const graph = new Graph({
259283
nodes: [researcher, writer, reviewer],

src/content/docs/user-guide/concepts/agents/session-manager.ts

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { Agent, SessionManager, FileStorage } from '@strands-agents/sdk'
22
import { S3Storage } from '@strands-agents/sdk/session/s3-storage'
3-
import type { SnapshotStorage, SnapshotLocation, Snapshot, SnapshotManifest } from '@strands-agents/sdk'
3+
import type {
4+
SnapshotStorage,
5+
SnapshotLocation,
6+
Snapshot,
7+
SnapshotManifest,
8+
} from '@strands-agents/sdk'
49
import { S3Client } from '@aws-sdk/client-s3'
510

611
// =====================
@@ -61,8 +66,9 @@ async function s3StorageExample() {
6166
storage: {
6267
snapshot: new S3Storage({
6368
bucket: 'my-agent-sessions',
64-
prefix: 'production', // Optional key prefix
65-
s3Client: new S3Client({ // Optional pre-configured client
69+
prefix: 'production', // Optional key prefix
70+
s3Client: new S3Client({
71+
// Optional pre-configured client
6672
region: 'us-west-2',
6773
}),
6874
// Alternatively, use region directly (cannot be combined with s3Client):
@@ -104,8 +110,8 @@ async function snapshotTriggerExample() {
104110
})
105111

106112
const agent = new Agent({ sessionManager: session })
107-
await agent.invoke('First message') // 2 messages — no snapshot
108-
await agent.invoke('Second message') // 4 messages — immutable snapshot created
113+
await agent.invoke('First message') // 2 messages — no snapshot
114+
await agent.invoke('Second message') // 4 messages — immutable snapshot created
109115
// --8<-- [end:snapshot_trigger]
110116
}
111117

@@ -116,7 +122,11 @@ async function snapshotTriggerExample() {
116122
async function listAndRestoreExample() {
117123
// --8<-- [start:list_and_restore]
118124
const storage = new FileStorage('./sessions')
119-
const location = { sessionId: 'my-session', scope: 'agent' as const, scopeId: 'default' }
125+
const location = {
126+
sessionId: 'my-session',
127+
scope: 'agent' as const,
128+
scopeId: 'default',
129+
}
120130

121131
// List all immutable snapshot IDs (chronological order)
122132
const snapshotIds = await storage.listSnapshotIds({ location })
@@ -129,7 +139,10 @@ async function listAndRestoreExample() {
129139
})
130140

131141
// Restore agent to a specific checkpoint
132-
const session = new SessionManager({ sessionId: 'my-session', storage: { snapshot: storage } })
142+
const session = new SessionManager({
143+
sessionId: 'my-session',
144+
storage: { snapshot: storage },
145+
})
133146
const agent = new Agent({ sessionManager: session })
134147
await agent.initialize()
135148
await session.restoreSnapshot({ target: agent, snapshotId: snapshotIds[0]! })
@@ -144,21 +157,36 @@ async function customStorageExample() {
144157
// --8<-- [start:custom_storage]
145158
// Implement SnapshotStorage to plug in any backend (database, Redis, etc.)
146159
class MyStorage implements SnapshotStorage {
147-
async saveSnapshot({ location, snapshotId, snapshot }: {
148-
location: SnapshotLocation; snapshotId: string; isLatest: boolean; snapshot: Snapshot
160+
async saveSnapshot({
161+
location,
162+
snapshotId,
163+
snapshot,
164+
}: {
165+
location: SnapshotLocation
166+
snapshotId: string
167+
isLatest: boolean
168+
snapshot: Snapshot
149169
}) {
150170
// Store the snapshot JSON keyed by location + snapshotId
151171
}
152172

153-
async loadSnapshot({ location, snapshotId }: {
154-
location: SnapshotLocation; snapshotId?: string
173+
async loadSnapshot({
174+
location,
175+
snapshotId,
176+
}: {
177+
location: SnapshotLocation
178+
snapshotId?: string
155179
}) {
156180
// Return the snapshot for the given location, or null if not found
157181
return null
158182
}
159183

160-
async listSnapshotIds({ location }: {
161-
location: SnapshotLocation; limit?: number; startAfter?: string
184+
async listSnapshotIds({
185+
location,
186+
}: {
187+
location: SnapshotLocation
188+
limit?: number
189+
startAfter?: string
162190
}) {
163191
// Return immutable snapshot IDs sorted chronologically
164192
return []
@@ -168,13 +196,21 @@ async function customStorageExample() {
168196
// Remove all stored data for this session
169197
}
170198

171-
async loadManifest({ location }: { location: SnapshotLocation }): Promise<SnapshotManifest> {
199+
async loadManifest({
200+
location,
201+
}: {
202+
location: SnapshotLocation
203+
}): Promise<SnapshotManifest> {
172204
// Return the manifest for the given location
173205
return { schemaVersion: '1', updatedAt: new Date().toISOString() }
174206
}
175207

176-
async saveManifest({ location, manifest }: {
177-
location: SnapshotLocation; manifest: SnapshotManifest
208+
async saveManifest({
209+
location,
210+
manifest,
211+
}: {
212+
location: SnapshotLocation
213+
manifest: SnapshotManifest
178214
}) {
179215
// Persist the manifest
180216
}

src/content/docs/user-guide/concepts/agents/state.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ async function conversationManagerExample() {
4444
// Create a conversation manager with custom window size
4545
// By default, SlidingWindowConversationManager is used even if not specified
4646
const conversationManager = new SlidingWindowConversationManager({
47-
windowSize: 10
47+
windowSize: 10,
4848
})
49-
49+
5050
const agent = new Agent({
51-
conversationManager
51+
conversationManager,
5252
})
5353
// --8<-- [end:conversation_manager]
5454
}

src/content/docs/user-guide/concepts/agents/structured-output.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,12 @@ async function multipleOutputTypes() {
141141
const personAgent = new Agent({ structuredOutputSchema: PersonSchema })
142142
const taskAgent = new Agent({ structuredOutputSchema: TaskSchema })
143143

144-
const personResult = await personAgent.invoke('Extract person: John Doe, 35, john@test.com')
145-
const taskResult = await taskAgent.invoke('Create task: Review code, high priority, completed')
144+
const personResult = await personAgent.invoke(
145+
'Extract person: John Doe, 35, john@test.com'
146+
)
147+
const taskResult = await taskAgent.invoke(
148+
'Create task: Review code, high priority, completed'
149+
)
146150
// --8<-- [end:multiple_types]
147151
}
148152

@@ -164,7 +168,9 @@ async function conversationHistory() {
164168
await agent.invoke('Tell me about the weather there in spring.')
165169

166170
// Extract structured information from the conversation
167-
const result = await agent.invoke('Extract structured information about Paris from our conversation')
171+
const result = await agent.invoke(
172+
'Extract structured information about Paris from our conversation'
173+
)
168174

169175
const cityInfo = result.structuredOutput as CityInfo
170176
console.log(`City: ${cityInfo.city}`) // "Paris"
@@ -214,7 +220,9 @@ async function overridingDefaults() {
214220

215221
// Create a new agent with CompanyInfo schema for this specific use case
216222
const companyAgent = new Agent({ structuredOutputSchema: CompanySchema })
217-
const result = await companyAgent.invoke('TechCorp is a software company with 500 employees')
223+
const result = await companyAgent.invoke(
224+
'TechCorp is a software company with 500 employees'
225+
)
218226

219227
const company = result.structuredOutput as Company
220228
console.log(`Company: ${company.name}`) // "TechCorp"

0 commit comments

Comments
 (0)