🚨 Open Responses API (Alpha). Learn more here
Create and manage AI agents with the Node.js SDK
const agent = await client.agents.create({ name: 'Customer Support Agent', model: 'claude-3.5-sonnet', about: 'A helpful customer support agent that assists users with their queries', metadata: { department: 'support', language: 'english' } });
// Get a specific agent const agent = await client.agents.get(agentId); // List all agents const agents = await client.agents.list({ limit: 10, offset: 0 }); // Search agents const searchResults = await client.agents.search({ query: 'support', metadata: { department: 'support' } });
const updatedAgent = await client.agents.update(agentId, { name: 'Senior Support Agent', metadata: { department: 'support', seniority: 'senior' } });
await client.agents.delete(agentId);
// Add a document const document = await client.agents.docs.create(agentId, { title: 'Support Guidelines', content: 'Here are the guidelines for customer support...', metadata: { category: 'guidelines', version: '1.0' } }); // Search documents const docs = await client.agents.docs.search(agentId, { query: 'refund policy', metadata: { category: 'policy' } }); // Delete a document await client.agents.docs.delete(agentId, documentId);
// Add a web search tool const tool = await client.agents.tools.create(agentId, { name: 'web_search', description: 'Search the web for information', integration: { provider: 'brave', method: 'search', setup: { brave_api_key: process.env.BRAVE_API_KEY } } }); // Add a custom function tool const customTool = await client.agents.tools.create(agentId, { name: 'calculate_price', description: 'Calculate the final price including tax', type: 'function', function: { parameters: { type: 'object', properties: { base_price: { type: 'number', description: 'Base price before tax' }, tax_rate: { type: 'number', description: 'Tax rate as a decimal' } }, required: ['base_price', 'tax_rate'] } } });
try { const agent = await client.agents.create({ name: 'Test Agent', model: 'invalid-model' }); } catch (error) { if (error.name === 'ValidationError') { console.error('Invalid model specified:', error.message); } else if (error.name === 'ApiError') { console.error('API error:', error.message, error.status); } else { console.error('Unexpected error:', error); } }