Examples
Explore real-world examples to learn how to build powerful AI agents with AgentFlare.
Customer Support Agent
Build an intelligent customer support agent that can handle inquiries, search documentation, and escalate issues.
import { Agent, Tool } from 'agentflare'
// Create a documentation search tool
const docSearchTool = new Tool({
name: 'search-docs',
description: 'Search product documentation',
parameters: {
query: { type: 'string', required: true }
},
execute: async ({ query }) => {
// Search your documentation
const results = await searchDocs(query)
return results
}
})
// Create the support agent
const supportAgent = new Agent({
name: 'SupportAgent',
model: 'gpt-4',
tools: ['search-docs', 'create-ticket'],
systemPrompt: `You are a helpful customer support agent.
Search documentation to answer questions.
If you cannot resolve the issue, create a support ticket.`,
memory: {
type: 'conversation',
maxTokens: 4000
}
})
supportAgent.addTool(docSearchTool)
// Handle customer inquiry
const response = await supportAgent.run(
'How do I reset my password?'
)Data Analysis Agent
Create an agent that can analyze datasets, generate insights, and create visualizations.
import { Agent, Tool } from 'agentflare'
const pythonTool = new Tool({
name: 'python',
description: 'Execute Python code for data analysis',
parameters: {
code: { type: 'string', required: true }
},
execute: async ({ code }) => {
// Execute Python code safely
const result = await executePython(code)
return result
}
})
const dataAgent = new Agent({
name: 'DataAnalyst',
model: 'gpt-4',
tools: ['python', 'visualization'],
systemPrompt: `You are an expert data analyst.
Analyze datasets and provide insights.
Create visualizations to illustrate findings.`
})
dataAgent.addTool(pythonTool)
// Analyze data
const analysis = await dataAgent.run(`
Analyze this sales data and identify trends:
${salesData}
`)Multi-Agent Workflow
Orchestrate multiple specialized agents working together.
import { Workflow, Agent } from 'agentflare'
// Create specialized agents
const researchAgent = new Agent({
name: 'Researcher',
model: 'gpt-4',
tools: ['web-search', 'scraper'],
systemPrompt: 'Research topics thoroughly and gather information.'
})
const writerAgent = new Agent({
name: 'Writer',
model: 'gpt-4',
tools: ['grammar-check'],
systemPrompt: 'Write clear, engaging content based on research.'
})
const editorAgent = new Agent({
name: 'Editor',
model: 'gpt-4',
systemPrompt: 'Review and improve content for clarity and accuracy.'
})
// Create workflow
const contentWorkflow = new Workflow({
name: 'ContentCreation',
agents: [researchAgent, writerAgent, editorAgent],
steps: [
{
agent: 'Researcher',
input: 'Research AI agent frameworks'
},
{
agent: 'Writer',
input: 'Write an article based on: {{Researcher.output}}'
},
{
agent: 'Editor',
input: 'Edit and improve: {{Writer.output}}'
}
]
})
// Execute workflow
const result = await contentWorkflow.execute()
console.log(result.output)RAG Agent
Build a Retrieval-Augmented Generation agent with vector memory.
import { Agent } from 'agentflare'
const ragAgent = new Agent({
name: 'RAGAssistant',
model: 'gpt-4',
tools: ['vector-search'],
memory: {
type: 'vector',
vectorStore: {
provider: 'pinecone',
index: 'knowledge-base',
dimension: 1536
}
},
systemPrompt: `You are a knowledgeable assistant.
Use vector search to find relevant information.
Provide accurate answers based on the knowledge base.`
})
// Query with context retrieval
const answer = await ragAgent.run(
'What are the best practices for agent design?'
)