Skip to content

Commit b4b57bd

Browse files
committed
Load AgentDefinition.ts file for Agent Reference section
1 parent 75f1489 commit b4b57bd

File tree

6 files changed

+117
-29
lines changed

6 files changed

+117
-29
lines changed

bun.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/types/agent-template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import type { AgentState, AgentTemplateType } from './session-state'
1212
import type {
1313
ToolCall,
1414
AgentState as PublicAgentState,
15-
Logger,
1615
} from '../templates/initial-agents-dir/types/agent-definition'
16+
import type { Logger } from '../templates/initial-agents-dir/types/util-types'
1717
import type { ToolName } from '../tools/constants'
1818
import type { OpenRouterProviderOptions } from '@codebuff/internal/openrouter-ai-sdk'
1919
import type { z } from 'zod/v4'
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { NextResponse } from 'next/server'
2+
import { readFile } from 'fs/promises'
3+
import { join } from 'path'
4+
5+
/**
6+
* API route that serves the content of the agent-definition.ts file
7+
* This allows the docs to dynamically include the actual TypeScript types
8+
*/
9+
export async function GET() {
10+
try {
11+
// Path to the agent-definition.ts file
12+
const filePath = join(
13+
process.cwd(),
14+
'../common/src/templates/initial-agents-dir/types/agent-definition.ts'
15+
)
16+
17+
// Read the file content
18+
const fileContent = await readFile(filePath, 'utf-8')
19+
20+
return new NextResponse(fileContent, {
21+
headers: {
22+
'Content-Type': 'text/plain; charset=utf-8',
23+
// Cache for 5 minutes to improve performance while allowing updates
24+
'Cache-Control': 'public, max-age=300, stale-while-revalidate=60',
25+
},
26+
})
27+
} catch (error) {
28+
console.error('Error reading agent-definition.ts:', error)
29+
30+
return NextResponse.json(
31+
{
32+
error: 'Failed to load agent definition file',
33+
details: error instanceof Error ? error.message : 'Unknown error',
34+
},
35+
{ status: 500 }
36+
)
37+
}
38+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use client'
2+
3+
import { useState, useEffect } from 'react'
4+
import { CodeDemo } from './code-demo'
5+
6+
/**
7+
* Component that displays the actual TypeScript content from agent-definition.ts
8+
* This loads the file content via API to ensure docs stay in sync with the actual types
9+
*/
10+
export function AgentDefinitionDisplay() {
11+
const [fileContent, setFileContent] = useState<string>('')
12+
const [isLoading, setIsLoading] = useState(true)
13+
const [error, setError] = useState<string | null>(null)
14+
15+
useEffect(() => {
16+
const loadFileContent = async () => {
17+
try {
18+
const response = await fetch('/api/docs/agent-definition')
19+
if (!response.ok) {
20+
throw new Error(`Failed to load file: ${response.statusText}`)
21+
}
22+
const content = await response.text()
23+
setFileContent(content)
24+
} catch (err) {
25+
console.error('Error loading agent definition:', err)
26+
setError(
27+
err instanceof Error ? err.message : 'Failed to load file content'
28+
)
29+
} finally {
30+
setIsLoading(false)
31+
}
32+
}
33+
34+
loadFileContent()
35+
}, [])
36+
37+
if (isLoading) {
38+
return (
39+
<div className="rounded-lg border bg-muted/30 px-4 py-8 text-center text-muted-foreground">
40+
Loading agent definition types...
41+
</div>
42+
)
43+
}
44+
45+
if (error) {
46+
return (
47+
<div className="rounded-lg border bg-red-50 px-4 py-4 text-red-700">
48+
<p className="font-medium">Error loading agent definition:</p>
49+
<p className="text-sm mt-1">{error}</p>
50+
<p className="text-xs mt-2 text-red-600">
51+
The file should be located at:
52+
common/src/templates/initial-agents-dir/types/agent-definition.ts
53+
</p>
54+
</div>
55+
)
56+
}
57+
58+
return (
59+
<div className="space-y-2">
60+
<CodeDemo language="typescript">{fileContent}</CodeDemo>
61+
</div>
62+
)
63+
}

web/src/components/docs/mdx/mdx-components.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import React, { useState, useEffect } from 'react'
66
import { CodeDemo } from './code-demo'
77
import { MarkdownTable } from './markdown-table'
88
import { AgentTemplateSchemaDisplay, SchemaDisplay } from './schema-display'
9+
import { AgentDefinitionDisplay } from './agent-definition-display'
910

1011
import type {
1112
HTMLAttributes,
@@ -288,6 +289,7 @@ const components = {
288289
MarkdownTable,
289290
SchemaDisplay,
290291
AgentTemplateSchemaDisplay,
292+
AgentDefinitionDisplay,
291293
}
292294

293295
export function Mdx({ code }: MdxProps) {

web/src/content/agents/agent-reference.mdx

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,9 @@ order: 4
77

88
# Agent Reference
99

10-
Complete reference for all agent configuration fields and tools.
10+
Complete reference for all agent definition fields:
1111

12-
## Key Terms
13-
14-
**Agent Template:** JSON file defining agent behavior
15-
16-
**Spawnable Agents:** Sub-agents this agent can create
17-
18-
**Tool Names:** Capabilities (read files, run commands, etc.)
19-
20-
**Output Mode:** Response format (last message, report, all messages)
21-
22-
**Prompt Schema:** Input validation rules
23-
24-
## Agent Configuration
25-
26-
When creating agent templates, you define all aspects of the agent from scratch.
27-
28-
### Agent Schema
29-
30-
<AgentTemplateSchemaDisplay />
12+
<AgentDefinitionDisplay />
3113

3214
### Core Configuration
3315

@@ -177,10 +159,12 @@ Other agents this agent can spawn. Use the fully qualified agent ID from the age
177159
> **⚠️ Important:** When referencing built-in agents, you **must** specify both publisher and version (e.g., `codebuff/reviewer@0.0.1`). Omit publisher/version only for local agents defined in your `.agents/` directory.
178160
179161
**Referencing Agents:**
162+
180163
- Published/built-in agents: `"codebuff/file-picker@0.0.1"` (publisher and version required!)
181164
- Local agents: `"my-custom-agent"` (just the agent ID)
182165

183166
**Available Built-in Agents:**
167+
184168
- `codebuff/base` - Main coding assistant
185169
- `codebuff/reviewer` - Code review agent
186170
- `codebuff/thinker` - Deep thinking agent
@@ -231,25 +215,24 @@ Prompt inserted at each agent step. Powerful for changing behavior but usually n
231215
**🚀 This is what makes Codebuff agents truly powerful!** Unlike traditional prompt-based agents, `handleSteps` lets you write actual code to control agent behavior.
232216

233217
Programmatically control the agent's execution using a TypeScript generator function. This enables:
218+
234219
- **Dynamic decision making** based on tool results
235220
- **Complex orchestration** between multiple tools and agents
236221
- **Conditional branching** based on file contents or agent responses
237222
- **Iterative refinement** until desired results are achieved
238223
- **State management** across multiple steps
239224

240-
241225
**What You Can Yield:**
242226

243227
<MarkdownTable>
244-
| Yield Value | What It Does |
245-
|------------|-------------|
246-
| Tool call object | Execute a specific tool and get its result |
247-
| 'STEP' | Run agent's LLM for one generation step |
248-
| 'STEP_ALL' | Let agent run until completion |
249-
| return | End the agent's turn immediately |
228+
| Yield Value | What It Does | |------------|-------------| | Tool call object
229+
| Execute a specific tool and get its result | | 'STEP' | Run agent's LLM for
230+
one generation step | | 'STEP_ALL' | Let agent run until completion | | return
231+
| End the agent's turn immediately |
250232
</MarkdownTable>
251233

252234
**Tool Call Pattern:**
235+
253236
```typescript
254237
const { toolResult, toolError } = yield {
255238
toolName: 'read_files',
@@ -259,6 +242,7 @@ const { toolResult, toolError } = yield {
259242
```
260243

261244
**Example:**
245+
262246
```typescript
263247
handleSteps: function* ({ agentState, prompt, params }) {
264248
// First, read some files
@@ -304,6 +288,7 @@ JSON Schema definitions for validating prompt and params when spawning the agent
304288
```
305289

306290
**Real-World Example:**
291+
307292
```typescript
308293
// 1. Dynamically find relevant files
309294
const { toolResult: searchResults } = yield {

0 commit comments

Comments
 (0)