text stringlengths 0 59.1k |
|---|
console.log(result.object); // Type-safe JSON object |
``` |
This feature is especially useful for **data extraction** and **API responses**. You're not saying "give it in JSON format" and then trying to parse it anymore. |
### Tool Integration: Real World Connection |
We added MCP (Model Context Protocol) support in the tool integration part. This really became a game-changing feature: |
```typescript |
// Define local tool |
const weatherTool = createTool({ |
name: "get_weather", |
description: "Get the current weather for a specific location", |
parameters: z.object({ |
location: z.string().describe("City and state"), |
}), |
execute: async ({ location }) => { |
// Real API call would be here |
return { temperature: 72, conditions: "sunny" }; |
}, |
}); |
// Connect to external MCP server |
const mcpTools = await connectMCPServer("stdio://weather-server"); |
const agent = new Agent({ |
name: "Weather Assistant", |
instructions: "Can check weather using available tools", |
llm: new VercelAIProvider(), |
model: openai("gpt-4o"), |
tools: [weatherTool, ...mcpTools], // Combine both |
}); |
``` |
The agent decides which tool to use when by itself. You just say "How's the weather in London?", it calls its own tool and brings you the result. |
### Memory: Context Management |
We also carefully designed the memory system. It's critical for agents to remember past conversations: |
```typescript |
import { LibSQLStorage } from "@voltagent/core"; |
const memoryStorage = new LibSQLStorage({ |
url: "file:local.db", |
}); |
const agent = new Agent({ |
name: "Assistant with Memory", |
instructions: "Remember our conversation history", |
llm: new VercelAIProvider(), |
model: openai("gpt-4o"), |
memory: memoryStorage, // Automatic context management |
}); |
// First conversation |
await agent.generateText("My name is John and I love pizza"); |
// Next conversation - will remember the previous one |
await agent.generateText("What's my favorite food?"); |
// "Based on our previous conversation, you love pizza!" |
``` |
The framework automatically fetches relevant context and saves new interactions. |
### Multi-Agent Systems |
One of my favorite features is the sub-agent system. You can break complex tasks into small pieces and distribute them to expert agents: |
```typescript |
const researchAgent = new Agent({ |
name: "Researcher", |
instructions: "Research topics thoroughly using web search", |
tools: [webSearchTool], |
}); |
const writerAgent = new Agent({ |
name: "Writer", |
instructions: "Write engaging content based on research", |
tools: [contentGenerator], |
}); |
const coordinator = new Agent({ |
name: "Coordinator", |
instructions: "Coordinate research and writing tasks", |
llm: new VercelAIProvider(), |
model: openai("gpt-4o"), |
subAgents: [researchAgent, writerAgent], // Automatic delegate_task tool |
}); |
// Complex workflow in a single call |
await coordinator.generateText("Write a blog post about quantum computing"); |
// Coordinator will give research to researcher, writing to writer |
``` |
:::important |
Memory management and tool integration are the foundation of production-ready agents. Without these, you'll hit scaling issues quickly as your application grows. |
::: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.