Examples
Examples
Complete Examples
See the examples/ directory:
# Basic examples
npm run example:text # Simple text generation
npm run example:agent # Basic agent with tools
npm run example:conversation # Multi-turn conversation
npm run example:chat # Interactive chat
npm run example:vision # Image analysis
npm run example:providers # Multi-provider comparison
# Tools and hooks
npm run example:json-tool # JSON manipulation tool
npm run example:hooks # Agent lifecycle hooks
npm run example:web # Web research agent
# OAuth examples
npm run example:oauth # OAuth demo
npm run example:oauth-registry # OAuth registry
Quick Recipes
Multi-Provider Setup
// Configure all providers
Connector.create({ name: 'openai', vendor: Vendor.OpenAI,
auth: { type: 'api_key', apiKey: process.env.OPENAI_API_KEY! } });
Connector.create({ name: 'anthropic', vendor: Vendor.Anthropic,
auth: { type: 'api_key', apiKey: process.env.ANTHROPIC_API_KEY! } });
Connector.create({ name: 'google', vendor: Vendor.Google,
auth: { type: 'api_key', apiKey: process.env.GOOGLE_API_KEY! } });
// Create agents for each
const openaiAgent = Agent.create({ connector: 'openai', model: 'gpt-5.6-terra' });
const claudeAgent = Agent.create({ connector: 'anthropic', model: 'claude-opus-5' });
const geminiAgent = Agent.create({ connector: 'google', model: 'gemini-3.8-flash' });
// Compare responses
const [r1, r2, r3] = await Promise.all([
openaiAgent.run(prompt),
claudeAgent.run(prompt),
geminiAgent.run(prompt),
]);
RAG (Retrieval-Augmented Generation)
const searchTool: ToolFunction = {
definition: {
type: 'function',
function: {
name: 'search_knowledge_base',
description: 'Search internal knowledge base',
parameters: {
type: 'object',
properties: {
query: { type: 'string' },
},
required: ['query'],
},
},
},
execute: async (args) => {
// Search your vector database
const results = await vectorDB.search(args.query);
return { results };
},
};
const agent = Agent.create({
connector: 'openai',
model: 'gpt-4.1',
tools: [searchTool],
instructions: `You are a helpful assistant with access to a knowledge base.
Always search the knowledge base before answering questions.`,
});
const response = await agent.run('What is our return policy?');
Research Agent with Memory
const agent = Agent.create({
connector: 'openai',
model: 'gpt-4.1',
tools: [searchTool, scrapeWebTool],
context: {
model: 'gpt-4.1',
features: { workingMemory: true },
},
});
// Agent uses memory tools to store research findings
const response = await agent.run(`
Research our top 5 competitors.
For each competitor:
1. Search for their information
2. Scrape their website
3. Store key findings in memory
4. Create a comprehensive report
`);