Your First Agent
Let’s create a simple agent that estimates the size of objects. This example demonstrates the core Fast Agent pattern.Create your agent file
Create a file called That’s it! This is a complete Fast Agent application.
agent.py with the following code:agent.py
Understanding the Code
Let’s break down what’s happening:1. Create a FastAgent App
2. Define an Agent
@fast.agent decorator defines an agent with a specific instruction. The instruction is the base prompt that guides the agent’s behavior.
3. Run the Agent
Sending Messages Programmatically
Instead of interactive mode, you can send messages directly:agent.py
Using the Scaffold Command
Fast Agent provides a scaffold command to generate a complete agent template with configuration files:agent.py- A template agent filefastagent.config.yaml- Configuration for models and MCP serversfastagent.secrets.yaml.example- Example secrets file.gitignore- Git ignore rulespyproject.toml.tmpl- Project template
The scaffolded agent includes template variables like
{{serverInstructions}}, {{agentSkills}}, and {{currentDate}} that get automatically populated at runtime.Adding MCP Servers
Let’s create an agent that uses MCP servers to fetch web content and write social media posts.Create the configuration file
Create
fastagent.config.yaml to define the MCP server:fastagent.config.yaml
How It Works
- url_fetcher agent uses the
fetchMCP server to retrieve and summarize the URL - social_media agent takes the summary and writes a concise social post
- post_writer chain connects them in sequence
Interactive Features
Fast Agent provides rich interactive features:Switch Between Agents
During a chain workflow, you can switch agents by typing@agent-name:
Use MCP Prompts
If your MCP server provides prompts, you can apply them interactively:Request Human Input
Agents can request human input when they need additional context:Using Quickstart Templates
Fast Agent includes several quickstart templates for common patterns:Workflow Example
Generate example workflows including chaining, parallel, router, and orchestrator:Researcher Agent
Create a researcher agent with evaluator-optimizer workflow:- Web search with the fetch MCP server
- Quality evaluation and iterative improvement
- Multi-agent collaboration
Data Analysis Agent
Create a data analysis agent with filesystem access:Model Selection
Fast Agent supports multiple model providers with simple aliases:Anthropic Models
OpenAI Models
Ollama (Local Models)
Configure Default Model
Set the default model infastagent.config.yaml:
fastagent.config.yaml
Quick Reference
Command Line
Agent Syntax
Calling Agents
Next Steps
Now that you’ve built your first agent, explore more advanced features:Agent Workflows
Learn about chain, parallel, router, and orchestrator patterns
MCP Servers
Connect agents to tools and data sources via MCP
Configuration
Configure models, logging, and advanced options
Examples
Explore complete examples and use cases
Getting Help
If you need assistance:- Read the full documentation
- Check the LLMs.txt for AI-optimized docs
- Join the Discord community
- Report issues on GitHub
