Daydreams Logo
Concepts

Introduction

Understand the fundamental building blocks of the Daydreams framework.

The Daydreams framework is designed around a set of core concepts that work together to enable autonomous agent behavior. Understanding these concepts is key to effectively building and customizing agents.

Core Architecture

A Daydreams agent consists of several key components:

Contexts

Contexts are the foundation of a Daydreams agent. Similar to React components, contexts manage state and rendering for your agent. Each context:

  • Has a defined schema for initialization
  • Maintains its own memory state
  • Provides a rendering function that formats its state for the LLM
const myContext = context({
  // Unique identifier for this context type
  type: "my-context",
 
  // Schema defining the arguments needed to initialize this context
  schema: z.object({
    id: z.string(),
  }),
 
  // Function to generate a unique key for this context instance
  key({ id }) {
    return id;
  },
 
  // Initialize the context's memory state
  create(state) {
    return {
      items: [],
      currentItem: null,
    };
  },
 
  // Format the context for the LLM
  render({ memory }) {
    return `
      Current Items: ${memory.items.join(", ")}
      Active Item: ${memory.currentItem || "None"}
    `;
  },
});

Actions

Actions are functions that your agent can call to interact with its environment or modify its state. They're similar to event handlers in React:

action({
  name: "addItem",
  description: "Add a new item to the list",
  schema: z.object({
    item: z.string().describe("The item to add"),
  }),
  handler(call, ctx, agent) {
    // Access the context memory
    const contextMemory = ctx.agentMemory;
 
    // Update the state
    contextMemory.items.push(call.data.item);
 
    // Return a response
    return {
      message: `Added ${call.data.item} to the list`,
      items: contextMemory.items,
    };
  },
});

Extensions

Extensions are pre-packaged bundles of inputs, outputs, and actions that add specific capabilities to your agent. For example, the cli extension adds terminal input/output capabilities.

The React-like Mental Model

If you're familiar with React, you can think of Daydreams in similar terms:

  • Contexts are like React components, managing state and rendering
  • Actions are like event handlers, responding to inputs and updating state
  • Extensions are like pre-built component libraries
  • The agent itself is like a React application, orchestrating everything

This mental model makes it easy to reason about how your agent works and how to structure complex behaviors.


This section provides a detailed explanation of each fundamental component:

  • Agent Lifecycle: How an agent processes information, makes decisions, and executes tasks in a continuous loop.
  • Contexts: The mechanism for managing state, memory, and behavior for specific tasks or interactions.
  • Actions: Definable tasks or capabilities that an agent can perform.
  • Inputs: How agents receive data and trigger processing cycles.
  • Outputs: How agents communicate results or send information to external systems.
  • Memory: The different ways agents store, retrieve, and utilize information (Working, Episodic, Vector).
  • Prompting: How instructions and context are formatted for the LLM to guide its reasoning.
  • Tasks: The system for managing asynchronous operations and background tasks.
  • Services & Extensions: How to integrate external services and extend the framework's capabilities.

Explore these pages to gain a deeper understanding of how Daydreams works under the hood.

On this page