Inputs
How Daydreams agents receive information and trigger processing.
What is an Input?
An input is how your agent listens to the outside world. If outputs are how your agent "speaks", inputs are how your agent "hears" things happening.
Real Examples
Here are inputs that make agents responsive:
Discord Messages
CLI Commands
API Webhooks
The Problem: Agents Need to Know When Things Happen
Without inputs, your agent can't react to anything:
The Solution: Inputs Enable Listening
With inputs, your agent can hear and respond:
How Inputs Work in Your Agent
1. You Define What the Agent Listens For
2. Inputs Watch for Events
When you start your agent, inputs begin listening:
3. Inputs Trigger the Agent
When an input detects something, it "sends" the data to your agent:
Creating Your First Input
Here's a simple input that listens for file changes:
Use it in your agent:
Working with Context Targeting
Inputs need to know which context should handle the incoming data:
This creates separate context instances for each user:
- User "alice" gets context instance
chat:alice
- User "bob" gets context instance
chat:bob
- Each maintains separate conversation memory
Real-Time vs Polling Inputs
Real-Time (Event-Driven)
Polling (Check Periodically)
Multiple Inputs Working Together
Your agent can listen to multiple sources simultaneously:
Error Handling and Validation
Always handle errors gracefully in your inputs:
Best Practices
1. Use Clear Types and Schemas
2. Always Return Cleanup Functions
3. Handle Connection Failures
4. Target the Right Context
Key Takeaways
- Inputs enable responsiveness - Without them, agents can't hear anything
- Subscribe pattern - Watch external sources, call
send()
when data arrives - Context targeting - Route inputs to appropriate context instances
- Always cleanup - Return functions to disconnect when agent stops
- Validate data - Use schemas to ensure incoming data is correct
- Handle errors gracefully - Don't let bad input data crash your agent
Inputs are what turn your agent from a one-time script into a responsive, always-listening assistant that can react to the world in real-time.