utils.ts
This file provides essential "factory" functions that you use to define the building blocks of your Daydreams agent, such as its tools (Actions), how it receives information (Inputs), how it responds (Outputs), how it remembers things specifically for an action (Memory), and how you bundle features together (Extensions).
How to Use
You'll import these functions directly from @daydreamsai/core
when defining
your agent's components, typically in separate files.
-
action({...})
: Use this to define a specific capability or tool for your agent. You give it aname
,description
, expected arguments (schema
using Zod), and thehandler
code that runs when the AI decides to use this tool. (See Actions for details). -
input({...})
: Use this to define how your agent receives information from the outside world (like a chat message or an API event). You specify how tosubscribe
to the source and how tosend
incoming data into the agent for processing. (See Inputs). -
output({...})
: Use this to define how your agent sends information out (like replying to a chat). You give it atype
, expected content structure (schema
), and thehandler
code that performs the sending. (See Outputs). -
extension({...})
: Use this to package related actions, inputs, outputs, contexts, and services together into a reusable module. You provide aname
and arrays/objects containing the components this extension provides. (See Services & Extensions). -
memory({...})
: A specialized helper used within anaction
definition if that specific action needs its own persistent memory across different calls (less common than context memory). You provide akey
and acreate
function for its initial state.
Benefit
These functions provide a standardized way to define the different parts of your agent. They ensure all the necessary configuration details are provided and integrate smoothly with the agent's lifecycle and the AI model. They abstract away the internal wiring, letting you focus on the logic of your agent's capabilities.
Anticipated Questions
- "Do I use these functions inside
createDreams
?" No, you typically use these functions in separate files to define your actions, inputs, etc., and then you import those definitions and pass them tocreateDreams
in its configuration object (e.g., in theactions: [...]
orextensions: [...]
arrays). - "What's the difference between
action
andoutput
?" Useaction
when the agent needs to perform a task and get a result back to continue thinking (like looking up information). Useoutput
when the agent just needs to send information out (like sending a final reply message).