Overview
Agents are AI systems that can:- Reason about which tools to use
- Call functions with appropriate parameters
- Maintain conversation context
- Make decisions based on tool results
@llamaindex/workflow package.
Complete Example
single-agent.ts
Step-by-Step Explanation
1. Define Tools
Tools are functions the agent can call:name- Unique identifier for the tooldescription- Helps the LLM understand when to use the toolparameters- Zod schema defining input parametersexecute- The actual function implementation
2. Create the Agent
3. Run the Agent
4. Maintain State
Reuse conversation context for follow-up questions:More Tool Examples
User Information Tool
Random ID Generator
Query Engine as a Tool
Use a RAG query engine as a tool:Using Different LLM Providers
Anthropic (Claude)
Ollama (Local Models)
Running the Example
- Install dependencies:
- Set your API key:
- Run the example:
Expected Output
The agent will:- Receive your question
- Decide to use the
get_weathertool - Call the tool with extracted parameters
- Use the tool result to formulate a response
Advanced Features
Multiple Agents
Coordinate multiple specialized agents:Memory and Context
Add memory to your agents:Streaming Responses
Stream agent responses in real-time:Next Steps
Workflows
Build complex multi-step workflows
Agent Memory
Add memory and context to agents
Custom Tools
Create sophisticated custom tools
Multi-Agent
Coordinate multiple agents
Related Examples
- Multiple Agents - Multi-agent coordination
- Blog Writer - Content generation agent
- Agent Memory - Memory management
- MCP Tools - Model Context Protocol integration