Lightweight TypeScript Framework for Stateful AI Agents
Features β’ Quick Start β’ Docs β’ Examples β’ Contributing
β οΈ Alpha Software: This framework is under active development. APIs may change between versions.
Daydreams is a lightweight TypeScript framework for building autonomous AI agents with persistent state and multi-context capabilities. Built for both Node.js and browser environments.
- π Multi-Context System: Manage multiple stateful conversations and agent contexts simultaneously
- πΎ Long-Running State: Agents maintain memory and context across sessions, enabling complex multi-step workflows
- π Framework Agnostic: Seamlessly integrates with LangChain, Vercel AI SDK, and other popular AI frameworks
- π Universal Compatibility: Runs in Node.js, browsers, Deno, Bun, and edge runtimes
- πͺΆ Lightweight Core: Minimal dependencies, tree-shakeable
- π€ Any LLM Provider: Works with OpenAI, Anthropic, Groq, local models, or any provider via adapters
- TypeScript First: Full type safety with excellent IntelliSense support
- Simple API: Intuitive context and action system
- Modular Design: Use only what you need
- Framework Composition: Combine with LangChain tools, Vercel AI SDK, or custom implementations
- Streaming Support: Real-time response streaming out of the box
- Stateful Contexts: Maintain conversation history and agent state
- Action System: Define custom functions agents can execute
- Memory Persistence: Store and retrieve information across sessions
- Task Management: Handle complex multi-step operations
- Event-Driven: React to inputs from multiple sources
- Multi-Platform: Discord, Twitter, Telegram, CLI, and more via extensions
- Blockchain Ready: Optional modules for Web3 interactions
- API Integration: Connect to any REST or GraphQL API
- Database Support: Works with any database through adapters
- Node.js 18+ or modern browser environment
- TypeScript 4.5+ (optional but recommended)
- LLM API Key from any supported provider
npm install @daydreamsai/core
# or
yarn add @daydreamsai/core
# or
pnpm add @daydreamsai/coreimport { createDreams, context } from "@daydreamsai/core";
import { anthropic } from "@ai-sdk/anthropic";
import { z } from "zod";
// Define a stateful context
const chatContext = context({
type: "chat",
schema: z.object({
userId: z.string(),
}),
create() {
return {
messages: [],
metadata: {},
};
},
});
// Create an agent with persistent state
const agent = await createDreams({
model: anthropic("claude-3-5-sonnet-latest"),
context: chatContext,
actions: [
// Define custom actions your agent can take
],
}).start({ userId: "user-123" });
// Send messages - state is maintained across calls
await agent.send({
context: chatContext,
args: { userId: "user-123" },
input: {
type: "text",
data: "Remember that I prefer Python for data analysis",
},
});// Works with LangChain
import { ChatOpenAI } from "@langchain/openai";
const agent = await createDreams({
model: new ChatOpenAI({ modelName: "gpt-4" }),
// ... rest of config
});
// Works with Vercel AI SDK
import { openai } from "@ai-sdk/openai";
const agent = await createDreams({
model: openai("gpt-4-turbo"),
// ... rest of config
});
// Works with any LLM provider
import { createCustomProvider } from "./my-provider";
const agent = await createDreams({
model: createCustomProvider(),
// ... rest of config
});Visit our comprehensive documentation to learn more:
- Getting Started Guide - Set up your first agent
- Core Concepts - Understand contexts, actions, and memory
- API Reference - Detailed API documentation
- Examples - Learn from working code
- Integration Guide - Connect with other frameworks
Explore our example implementations:
| Example | Description | Location |
|---|---|---|
| Basic Chat | Simple chat interface with personality traits | examples/basic/ |
| Discord Bot | Multi-functional Discord bot | examples/discord/ |
| Twitter Agent | Autonomous Twitter/X agent | examples/twitter/ |
| Telegram Bot | Telegram bot integration | examples/telegram/ |
| Task Management | Task planning and execution | examples/tasks/ |
| Deep Research | Advanced research capabilities | examples/deep-research/ |
| Blockchain Interactions | Cross-chain operations | examples/chains/ |
| Game Agents | Agents for on-chain games (Gigaverse, Lootsurvivor) | examples/games/ |
| MCP Integration | Model Context Protocol examples | examples/mcp/ |
| Composio | Composio integration examples | examples/composio/ |
Daydreams uses a modular, event-driven architecture designed for flexibility and composability:
graph TB
A[Input Sources] --> B[Dreams Engine]
B --> C[Context Manager]
B --> D[Memory System]
B --> E[Action Registry]
C --> F[Context State]
C --> G[Working Memory]
E --> H[User Actions]
E --> I[System Actions]
D --> J[Vector Store]
D --> K[KV Store]
B --> L[Task Runner]
L --> M[LLM Provider]
B --> N[Extensions]
N --> O[Platform Extensions]
N --> P[Storage Extensions]
style B fill:#f9f,stroke:#333,stroke-width:4px
style C fill:#bbf,stroke:#333,stroke-width:2px
style E fill:#bbf,stroke:#333,stroke-width:2px
- Dreams Engine: Lightweight orchestrator managing agent lifecycle and message flow
- Context Manager: Handles multiple concurrent stateful conversations with type safety
- Memory System: Pluggable storage layer supporting both KV and vector stores
- Action Registry: Type-safe action system for extending agent capabilities
- Task Runner: Manages async operations with concurrency control
- Extensions: Plugin architecture for platforms, storage, and custom features
Daydreams can be extended with blockchain capabilities through optional packages:
@daydreamsai/discord- Discord bot integration@daydreamsai/twitter- Twitter/X automation@daydreamsai/telegram- Telegram bot support@daydreamsai/cli- Command-line interface
@daydreamsai/supabase- Supabase vector store@daydreamsai/chroma- ChromaDB integration@daydreamsai/mongo- MongoDB support
Daydreams works with any LLM provider through the AI SDK adapters:
- OpenAI - GPT-4, GPT-3.5, etc.
- Anthropic - Claude 3.5, Claude 4, etc.
- Google - Gemini Pro, Gemini Ultra
- Groq - Fast inference for open models
- OpenRouter - Access multiple providers
- Ollama - Local model support
- LangChain - Use any LangChain model
- Custom - Bring your own provider
We love contributions! Whether you're fixing bugs, adding features, or improving documentation, we'd appreciate your help.
- Check existing issues or create a new one to discuss your ideas
- Fork the repository and create your branch from
main - Make your changes and ensure tests pass
- Submit a pull request with a clear description
See our Contributing Guide for detailed instructions.
# Clone the repository
git clone https://github.com/daydreamsai/daydreams.git
cd daydreams
# Install dependencies
pnpm install
# Build packages in watch mode
pnpm build:packages --watch
# Run tests
pnpm testNew to the project? Check out our
good first issue
label for beginner-friendly tasks.
Join our growing community:
- Discord - Chat with other developers
- Twitter - Stay updated with announcements
- GitHub Discussions - Ask questions and share ideas
Daydreams is MIT licensed.
Built with β€οΈ by the Daydreams team
