Build a working AI agent in just a few lines of code.
1
Install the package
npm install @deepagents/agent zod
You’ll also need an AI SDK provider:
npm install @ai-sdk/openai
2
Set your API key
Configure your OpenAI API key:
export OPENAI_API_KEY="your-api-key"
3
Create your first agent
Create a simple assistant agent:
import { openai } from '@ai-sdk/openai';import { agent, execute } from '@deepagents/agent';const assistant = agent({ name: 'assistant', model: openai('gpt-4o'), prompt: 'You are a helpful assistant.',});const stream = execute(assistant, 'Hello! What can you help me with?', {});for await (const chunk of stream.textStream) { process.stdout.write(chunk);}
import { openai } from '@ai-sdk/openai';import { agent, instructions, swarm } from '@deepagents/agent';// Research specialistconst researcher = agent({ name: 'researcher', model: openai('gpt-4o'), prompt: 'You research topics and provide detailed information.', handoffDescription: 'Handles research and fact-finding tasks',});// Writing specialistconst writer = agent({ name: 'writer', model: openai('gpt-4o'), prompt: 'You write clear, engaging content based on research.', handoffDescription: 'Handles writing and content creation',});// Coordinatorconst coordinator = agent({ name: 'coordinator', model: openai('gpt-4o'), prompt: instructions({ purpose: ['Coordinate research and writing tasks'], routine: [ 'Analyze the request', 'Use transfer_to_researcher for fact-finding', 'Use transfer_to_writer for content creation', ], }), handoffs: [researcher, writer],});// The coordinator automatically delegates to specialistsconst stream = swarm(coordinator, 'Write a blog post about AI agents', {});
Agents automatically get transfer_to_<agent_name> tools and coordinate seamlessly.
Use Text2SQL for natural language database queries:
import { Sqlite } from '@deepagents/text2sql/sqlite';import { openai } from '@ai-sdk/openai';const text2sql = new Sqlite( './database.db', openai('gpt-4o'));const result = await text2sql.query( 'What are the top 5 customers by revenue?');console.log(result.rows);
Text2SQL automatically introspects your schema, validates queries, and handles multi-turn conversations.