Skip to content

runAgenticTask

runAgenticTask(options): Promise<AgenticTaskResult>

Defined in: mcp.ts:691

Run an agentic task with MCP tools

This is the main entry point for AI tasks that need tool access. Properly handles the agentic loop via AI SDK’s stopWhen.

AgenticTaskOptions

Promise<AgenticTaskResult>

const result = await runAgenticTask({
systemPrompt: 'You are a code reviewer...',
userPrompt: 'Review this PR diff...',
mcpClients: {
filesystem: process.cwd(), // Read files for context
context7: true, // Check documentation - prevents hallucinations
},
maxSteps: 15,
onToolCall: (name, args) => console.log(`Using ${name}`),
});