Actions
Define capabilities and interactions for your Daydreams agent.
What is an Action?
An action is something your agent can do - like calling an API, saving data, or performing calculations. Think of actions as giving your agent superpowers.
Real Examples
Here are actions that make agents useful:
Weather Action
Database Action
Email Action
The Problem Without Actions
Without actions, your agent can only talk:
The Solution: Actions Give Agents Capabilities
With actions, your agent can do things:
How Actions Work in Your Agent
1. You Define What the Agent Can Do
2. The LLM Decides When to Use Them
When the agent thinks, it sees:
3. The LLM Calls Actions
The LLM responds with structured calls:
4. Daydreams Executes Your Code
Daydreams automatically:
- Validates the arguments against your schema
- Runs your handler function
- Returns results to the LLM
- Handles errors gracefully
Creating Your First Action
Here's a simple action that adds two numbers:
Use it in your agent:
Working with State and Memory
Actions can read and modify your agent's memory:
Now your agent can manage todo lists across conversations!
External API Integration
Actions are perfect for calling external APIs:
Best Practices
1. Use Clear Names and Descriptions
2. Validate Input with Schemas
3. Handle Errors Gracefully
4. Use async/await for I/O Operations
5. Check for Cancellation in Long Operations
Advanced: Context-Specific Actions
You can attach actions to specific contexts so they're only available in certain situations:
Key Takeaways
- Actions give agents capabilities - They can do things, not just talk
- LLM chooses when to use them - Based on names and descriptions you provide
- Arguments are validated - Zod schemas ensure type safety
- State persists automatically - Changes to memory are saved
- Error handling is crucial - Return structured success/error responses
- async/await required - For any I/O operations like API calls
Actions transform your agent from a chatbot into a capable assistant that can actually get things done.