Daydreams Logo
Concepts

Building Blocks

The core components that make up a Daydreams agent.

Every Daydreams agent is built from four main building blocks. Think of them as the essential parts that work together to create intelligent behavior.

The Four Building Blocks

1. Inputs - How Your Agent Listens

Inputs are how your agent receives information from the outside world.

input-example.ts
// Listen for Discord messages
const discordMessage = input({
  name: "discord-message",
  description: "Receives messages from Discord",
  // When a message arrives, this triggers the agent
});

Examples:

  • A Discord message arrives
  • A user types in the CLI
  • An API webhook gets called
  • A timer goes off

2. Outputs - How Your Agent Speaks

Outputs are how your agent sends information back to the world.

output-example.ts
// Send a Discord message
const discordReply = output({
  name: "discord-reply",
  description: "Sends a message to Discord",
  // The agent can call this to respond
});

Examples:

  • Posting a message to Discord
  • Printing to the console
  • Sending an email
  • Making an API call

3. Actions - What Your Agent Can Do

Actions are tasks your agent can perform to interact with systems or gather information.

action-example.ts
// Check the weather
const getWeather = action({
  name: "get-weather",
  description: "Gets current weather for a location",
  schema: z.object({
    location: z.string(),
  }),
  handler: async ({ location }) => {
    // Call weather API and return result
    return { temperature: "72°F", condition: "sunny" };
  },
});

Examples:

  • Calling a weather API
  • Reading from a database
  • Processing a file
  • Making calculations

4. Contexts - Your Agent's Workspace

Contexts define different "workspaces" or "modes" for your agent. Each context has its own memory and behavior.

context-example.ts
// A chat session context
const chatContext = context({
  type: "chat",
  schema: z.object({
    userId: z.string(),
  }),
  // This context remembers chat history
  create: () => ({
    messages: [],
    userPreferences: {},
  }),
});

Examples:

  • A chat session with a specific user
  • Playing a specific game
  • Processing a specific document
  • Managing a specific project

How They Work Together

Here's a simple flow showing how these building blocks connect:

  1. Input arrives → "New Discord message from user123"
  2. Agent thinks → "I should respond helpfully in this chat context"
  3. Agent acts → Calls the getWeather action if needed
  4. Agent responds → Uses an output to send a reply
  5. Context remembers → Saves the conversation in chat context memory

The React Mental Model

If you know React, think of it this way:

  • Contexts = React components (manage state and behavior)
  • Actions = Event handlers (respond to interactions)
  • Inputs/Outputs = Props/callbacks (data in and out)
  • Agent = React app (orchestrates everything)

Next Steps

Now that you understand the building blocks, you can dive deeper into each one:

  • Contexts - Learn how to manage state and memory
  • Inputs - Set up ways for your agent to receive information
  • Outputs - Configure how your agent responds
  • Actions - Define what your agent can do
  • Agent Lifecycle - Understand the complete execution flow

On this page