Your first agent
Build your first Daydreams agent.
Overview
Daydreams is a framework for building autonomous AI agents. At its core, an agent operates through a continuous cycle:
- Analyzes incoming information (inputs)
- Reasons about it using a Large Language Model (LLM)
- Decides on the next steps - either generating a response (output) or performing a task (action)
- Feeds results back into the agent's awareness, creating a continuous loop orchestrated by the LLM
This enables you to build agents that can interact with various systems like blockchains, social media platforms, APIs, and more, all based on predefined goals and contextual understanding.
Installation
Install the core Daydreams packages:
You'll also need an LLM provider SDK. For this guide, we'll use OpenAI:
Important: Make sure you have an OPENAI_API_KEY
environment variable set
before proceeding.
Core Concepts
Daydreams is built around several key components that work together:
Essential Components
- Agent Lifecycle - The central orchestrator that runs the main loop
- Contexts - Manages state and memory for specific tasks or interactions (e.g., a chat session)
- Inputs - How agents receive information (e.g., CLI messages, API events)
- Outputs - How agents respond or send information (e.g., CLI responses, tweets)
- Actions - Tasks agents can perform (e.g., calling APIs, executing transactions)
- Memory - How agents store and recall information (working memory, episodic memory)
For detailed information about these concepts, visit the Core Concepts section.
Your First Agent (CLI Echo Bot)
Let's build a simple agent that echoes back whatever you type in the command line. This example demonstrates the basic structure and workflow of a Daydreams agent.
Step 1: Set up your project
pnpm add @daydreamsai/core @daydreamsai/cli @ai-sdk/openai zod
Step 2: Create your agent
Create a file named agent.ts
:
Step 3: Run your agent
Ensure your OPENAI_API_KEY
environment variable is set, then run:
Your agent will start listening for input. Type any message and watch as the
agent echoes it back using the LLM and CLI handlers provided by the
cliExtension
.
Next Steps
Continue learning about Daydreams with these resources:
- Core Concepts - Deep dive into Daydreams architecture
- Advanced Features - More complex examples and advanced usage patterns