diff --git a/public/.well-known/skills/agents-sdk/references/codemode.md b/public/.well-known/skills/agents-sdk/references/codemode.md index f95ab384443..b2a3719cb3a 100644 --- a/public/.well-known/skills/agents-sdk/references/codemode.md +++ b/public/.well-known/skills/agents-sdk/references/codemode.md @@ -118,6 +118,7 @@ export class MyAgent extends Agent { 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, @@ -143,6 +144,45 @@ export class MyAgent extends Agent { } ``` +## 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` - 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: @@ -199,6 +239,39 @@ async function executeTask() { | 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"), + 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