API Reference
Complete reference documentation for the AgentFlare API.
Agent Class
The Agent class is the core of AgentFlare. It represents an autonomous AI entity that can execute tasks.
Constructor
new Agent(config: AgentConfig)Parameters
config.name(string): Unique identifier for the agentconfig.model(string): LLM model to use (e.g., 'gpt-4', 'claude-3')config.tools(string[]): Array of tool names to enableconfig.systemPrompt(string): System prompt defining agent behaviorconfig.memory(MemoryConfig): Optional memory configuration
Methods
run()
Execute a task with the agent.
async run(input: string): Promise<AgentResponse>Example:
const response = await agent.run('Analyze this dataset')
console.log(response.output)addTool()
Add a custom tool to the agent.
addTool(tool: Tool): voidExample:
agent.addTool(customWeatherTool)Tool Class
Create custom tools for your agents.
Constructor
new Tool(config: ToolConfig)Parameters
config.name(string): Tool identifierconfig.description(string): What the tool doesconfig.parameters(ParameterSchema): Input parameter schemaconfig.execute(Function): Tool execution function
Example
const searchTool = new Tool({
name: 'web-search',
description: 'Search the web for information',
parameters: {
query: { type: 'string', required: true }
},
execute: async ({ query }) => {
const results = await searchAPI(query)
return results
}
})Memory
Configure agent memory for context retention.
Types
type MemoryConfig = {
type: 'conversation' | 'vector' | 'hybrid'
maxTokens?: number
vectorStore?: VectorStoreConfig
}Example
const agent = new Agent({
name: 'Assistant',
model: 'gpt-4',
memory: {
type: 'hybrid',
maxTokens: 8000,
vectorStore: {
provider: 'pinecone',
index: 'agent-memory'
}
}
})Workflows
Orchestrate multiple agents in complex workflows.
Creating a Workflow
import { Workflow } from 'agentflare'
const workflow = new Workflow({
name: 'DataPipeline',
agents: [dataAgent, analysisAgent, reportAgent],
steps: [
{ agent: 'dataAgent', input: 'fetch data' },
{ agent: 'analysisAgent', input: '{{dataAgent.output}}' },
{ agent: 'reportAgent', input: '{{analysisAgent.output}}' }
]
})
const result = await workflow.execute()Error Handling
AgentFlare provides comprehensive error handling.
try {
const response = await agent.run(input)
} catch (error) {
if (error instanceof AgentError) {
console.error('Agent error:', error.message)
} else if (error instanceof ToolError) {
console.error('Tool error:', error.toolName, error.message)
}
}