Extensions
Building your own modular Daydreams extensions.
Extensions are the primary mechanism for packaging and distributing reusable Daydreams functionality. They bundle together contexts, actions, inputs, outputs, and the service providers they depend on.
Purpose
- Encapsulate Features: Group all related components for a specific capability (e.g., Discord integration, ChromaDB support, a custom game interface).
- Simplify Agent Configuration: Add complex features to an agent by simply
including the extension in the
createDreams
configuration. - Promote Code Reuse: Share common functionalities across different agents.
Defining an Extension
Use the extension
helper function exported from @daydreamsai/core
:
Usage and Lifecycle
-
Configuration: Pass your extension instances to
createDreams
in theextensions
array: -
Merging: When
createDreams
initializes, it iterates through theextensions
array. For each extension, it merges the definedcontexts
,actions
,inputs
,outputs
, andevents
into the agent's central registries, making them available for use. -
Service Registration: It automatically registers all
services
listed within each extension with the agent'sServiceManager
. -
Installation & Booting: When
agent.start()
is called:- The
install
method of each extension is executed (if defined). - The
ServiceManager
boots all registered services (calling theirboot
methods, ensuring dependencies are ready). - Input
subscribe
methods are called to start listening for external events.
- The
Extensions provide a powerful and organized way to structure agent capabilities, making it easy to combine built-in features with your own custom logic and integrations.