Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions public/.well-known/skills/agents-sdk/references/codemode.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
this.tools = { ...tools, ...this.mcp.getAITools() };

const { prompt, tools: wrappedTools } = await codemode({
model: openai("gpt-4o"), // Optional: defaults to openai("gpt-4.1")
prompt: "You are a helpful assistant...",
tools: this.tools,
globalOutbound: env.globalOutbound,
Expand All @@ -143,6 +144,45 @@
}
```

## API Reference

### `experimental_codemode(options)`

Wraps your tools to enable code generation mode for the LLM.

**Parameters:**

- `options.model` (optional): `LanguageModel` - AI SDK-compatible model instance (defaults to `openai("gpt-4.1")`)
- `options.tools`: `ToolSet` - Object containing tool definitions
- `options.prompt`: `string` - System prompt for the agent
- `options.globalOutbound`: `Fetcher` - Outbound fetch handler for security filtering
- `options.loader`: `WorkerLoader` - Worker loader binding for dynamic code execution
- `options.proxy`: `Fetcher<CodeModeProxy>` - Proxy for routing tool calls back to the agent

**Returns:**

```typescript
Promise<{
prompt: string;
tools: ToolSet;
}>
```

The returned `tools` should be used instead of your original tools when calling `streamText()`.

**Example:**

```typescript
const { prompt, tools: wrappedTools } = await codemode({
model: openai("gpt-4o"), // Optional: defaults to openai("gpt-4.1")
prompt: "You are a helpful assistant...",
tools: myTools,
globalOutbound: env.globalOutbound,
loader: env.LOADER,
proxy: this.ctx.exports.CodeModeProxy({ props: { ... } })
});
```

## Generated Code Example

When user asks "Check the weather in NYC and email me the forecast", codemode generates:
Expand Down Expand Up @@ -199,6 +239,39 @@
| Token budget constrained | Yes |
| Simple Q&A chat | No |

## Model Configuration

The `model` parameter is optional and defaults to `openai("gpt-4.1")`. You can specify any AI SDK-compatible model:

```typescript
import { openai } from "@ai-sdk/openai";
import { anthropic } from "@ai-sdk/anthropic";

// Using a different OpenAI model
const { prompt, tools: wrappedTools } = await codemode({
model: openai("gpt-4o"),
prompt: "You are a helpful assistant...",
tools: myTools,
// ... other options
});

// Or use a different provider entirely
const { prompt, tools: wrappedTools } = await codemode({
model: anthropic("claude-3-5-sonnet-20241022"),

Check warning on line 260 in public/.well-known/skills/agents-sdk/references/codemode.md

View workflow job for this annotation

GitHub Actions / Semgrep

semgrep.style-guide-potential-date-year

Potential year found. Documentation should strive to represent universal truth, not something time-bound. (add [skip style guide checks] to commit message to skip)
prompt: "You are a helpful assistant...",
tools: myTools,
// ... other options
});

// Or omit to use the default
const { prompt, tools: wrappedTools } = await codemode({
prompt: "You are a helpful assistant...",
tools: myTools,
// ... other options
// model defaults to openai("gpt-4.1")
});
```

## Limitations

- Experimental - API may change
Expand Down
Loading