by daydreamsai
Create composable, stateful AI agents with persistent memory, TypeScript‑first design, and native Model Context Protocol (MCP) integration, enabling seamless access to external tools and pay‑per‑use AI models.
Daydreams provides a TypeScript‑centric framework that lets developers build modular AI agents using composable contexts. Each context encapsulates isolated state, actions, and instructions, allowing agents to remember, learn, and scale without tangled code or manual state management.
npm install @daydreamsai/core @ai-sdk/openai zod
context
and action
.createDreams
, supplying the model and one or more contexts.agent.send({ context, input })
.createMcpExtension
and other extensions.import { createDreams, context, action } from "@daydreamsai/core";
import { openai } from "@ai-sdk/openai";
import { z } from "zod";
const weather = context({
type: "weather",
create: () => ({ lastQuery: null })
}).setActions([
action({
name: "getWeather",
schema: z.object({ city: z.string() }),
handler: async ({ city }, ctx) => {
ctx.memory.lastQuery = city;
return { weather: `Sunny, 72°F in ${city}` };
}
})
]);
const agent = createDreams({ model: openai("gpt-4o"), contexts: [weather] });
await agent.send({ context: weather, input: "What’s the weather in Paris?" });
.use()
to combine isolated workspaces.dreamsRouter
) to call any model (OpenAI, Anthropic, Google, Groq, etc.) with built‑in USDC x402 micropayments.Domain | Example |
---|---|
Customer Support | Context that composes analytics, ticketing, and premium features per user tier. |
E‑commerce assistants | Persistent shopping cart, order tracking, and recommendation contexts. |
Developer tools | Code review bots that call MCP‑based linters or test runners. |
Finance | Compliance‑aware agents with secure memory and MCP‑backed ledger access. |
Gaming | NPCs with long‑term memory and dynamic behavior composition. |
Healthcare | HIPAA‑compatible agents that retain patient history across sessions. |
Q: Do I need to run my own MCP servers?
A: No. You can use public MCP services or start local servers with npx @modelcontextprotocol/server‑*
as shown in the configuration below.
Q: How does payment work for model calls? A: The router supports x402 USDC micropayments; you specify the amount and network when creating the authenticated router.
Q: Can I use Daydreams in the browser? A: Yes. The core library is pure TypeScript and works in any JavaScript runtime.
Q: Is the framework open source? A: Yes, it is released under the MIT license.
Q: How do I add a new context after the agent is created?
A: Extend the agent with additional contexts in the createDreams
call or dynamically load extensions that register new contexts.
Finally, TypeScript agents that scale and compose
🌐 Website • ⚡ Quick Start • 📖 Documentation • 💬 Discord
You build an AI agent. It works great in testing. Then you need to add more features and...
❌ Context switching breaks existing functionality
❌ State management becomes a nightmare
❌ Memory doesn't persist across sessions
❌ Code becomes a tangled mess of prompts and logic
Sound familiar? You're not alone. This is why most AI agents never make it to production.
Daydreams is the first AI framework with composable contexts - isolated workspaces that combine for complex behaviors. Build agents that remember, learn, and scale with true memory, MCP integration, and TypeScript-first design.
Access any AI model through one API with built-in authentication and payments:
import { dreamsRouter } from "@daydreamsai/ai-sdk-provider";
// Use any model from any provider
const models = [
dreamsRouter("openai/gpt-4o"),
dreamsRouter("anthropic/claude-3-5-sonnet-20241022"),
dreamsRouter("google-vertex/gemini-2.5-flash"),
dreamsRouter("groq/llama-3.1-405b-reasoning"),
];
// Pay-per-use with USDC micropayments (no subscriptions)
const { dreamsRouter } = await createDreamsRouterAuth(account, {
payments: { amount: "100000", network: "base-sepolia" }, // $0.10 per request
});
Features:
🌐 Live Service: router.daydreams.systems • 📖 Router Docs • ⚡ Router Quickstart
Unlike other frameworks, Daydreams lets you compose contexts using .use()
-
creating powerful agents from modular components:
import { createDreams, context, action } from "@daydreamsai/core";
import { openai } from "@ai-sdk/openai";
// Base analytics context - tracks user behavior
const analyticsContext = context({
type: "analytics",
create: () => ({ events: [], sessions: 0 }),
}).setActions([
action({
name: "trackEvent",
schema: { event: z.string() },
handler: async ({ event }, ctx) => {
ctx.memory.events.push({ event, timestamp: Date.now() });
return { tracked: true };
},
}),
]);
// Customer support context that composes with analytics
const supportContext = context({
type: "support",
schema: z.object({
customerId: z.string(),
tier: z.enum(["free", "premium"]),
}),
create: () => ({ tickets: [] }),
})
// 🌟 The magic: compose contexts together
.use((state) => [
{ context: analyticsContext, args: { userId: state.args.customerId } },
// Conditional composition based on customer tier
...(state.args.tier === "premium" ? [{ context: premiumContext }] : []),
])
.instructions(
(state) =>
`You are a ${state.args.tier} customer support agent. Track all interactions.`
);
// Agent automatically gets ALL composed functionality
const agent = createDreams({
model: openai("gpt-4o"),
contexts: [supportContext],
});
// Customer gets support + analytics + premium features (if applicable)
await agent.send({
context: supportContext,
args: { customerId: "alice", tier: "premium" },
input: "I need help with billing",
});
Result: Your agent seamlessly combines customer support, analytics tracking, and premium features in a single conversation. No manual integration required.
Connect to any Model Context Protocol server for instant access to external tools:
import { createMcpExtension } from "@daydreamsai/mcp";
const agent = createDreams({
extensions: [
createMcpExtension([
{
id: "filesystem",
transport: {
type: "stdio",
command: "npx",
args: ["@modelcontextprotocol/server-filesystem", "./docs"],
},
},
{
id: "database",
transport: {
type: "stdio",
command: "npx",
args: ["@modelcontextprotocol/server-sqlite", "./data.db"],
},
},
]),
],
});
// Use MCP tools in any action
const searchAction = action({
name: "search-docs",
handler: async ({ query }, ctx) => {
// Read files via MCP
const docs = await ctx.callAction("mcp.listResources", {
serverId: "filesystem",
});
// Query database via MCP
const results = await ctx.callAction("mcp.callTool", {
serverId: "database",
name: "query",
arguments: { sql: `SELECT * FROM docs WHERE content LIKE '%${query}%'` },
});
return { docs, results };
},
});
Result: Your agent instantly gets file system access, database querying, web scraping, 3D rendering, and more through the growing MCP ecosystem.
npm install @daydreamsai/core @ai-sdk/openai zod
import { createDreams, context, action } from "@daydreamsai/core";
import { openai } from "@ai-sdk/openai";
import { z } from "zod";
// Define a simple weather context
const weatherContext = context({
type: "weather",
create: () => ({ lastQuery: null }),
}).setActions([
action({
name: "getWeather",
schema: z.object({ city: z.string() }),
handler: async ({ city }, ctx) => {
ctx.memory.lastQuery = city;
// Your weather API logic here
return { weather: `Sunny, 72°F in ${city}` };
},
}),
]);
// Create your agent
const agent = createDreams({
model: openai("gpt-4o"),
contexts: [weatherContext],
});
// Start chatting!
await agent.send({
context: weatherContext,
input: "What's the weather in San Francisco?",
});
That's it! Your agent is running with persistent memory and type-safe actions.
npx create-daydreams-agent my-agent
cd my-agent && npm run dev
🏗️ Traditional AI Frameworks | ⚡ Daydreams |
---|---|
Monolithic agent design | Composable context architecture |
Memory resets between sessions | Persistent memory across restarts |
Manual state management | Automatic context isolation |
Complex integration setup | Native MCP support |
JavaScript with types bolted on | TypeScript-first design |
🧩 Composable Contexts - Build complex agents from simple, reusable
contexts
🔌 Native MCP Support - Universal access to external tools and services
💾 Persistent Memory - True stateful agents that remember across sessions
⚡ Full TypeScript - Complete type safety with excellent developer
experience
🎯 Context Isolation - Automatic separation of user data and conversations
🔧 Action Scoping - Context-specific capabilities and permissions
🌐 Universal Runtime - Works in Node.js, browsers, Deno, Bun, and edge
functions
🏗️ Modular Extensions - Clean plugin architecture for platforms and
services
📊 Full Explainability - Understand every decision your agent makes
Isolated stateful workspaces for different conversation types:
const userContext = context({
type: "user",
schema: z.object({ userId: z.string() }),
create: () => ({ preferences: {}, history: [] }),
render: (state) =>
`User: ${state.args.userId} | History: ${state.memory.history.length} items`,
});
Dual-tier storage with automatic persistence:
create()
functionType-safe functions with context access and schema validation:
const savePreference = action({
name: "save-preference",
description: "Save a user preference",
schema: z.object({ key: z.string(), value: z.string() }),
handler: async ({ key, value }, ctx) => {
ctx.memory.preferences[key] = value;
return { saved: `${key} = ${value}` };
},
});
Modular integrations for platforms and services:
import { discordExtension } from "@daydreamsai/discord";
import { supabaseExtension } from "@daydreamsai/supabase";
const agent = createDreams({
extensions: [
discordExtension({ token: process.env.DISCORD_TOKEN }),
supabaseExtension({ url: process.env.SUPABASE_URL }),
],
});
Perfect for straightforward bots:
const faqBot = context({
type: "faq",
instructions: "Answer questions about our product",
});
When you need isolated functionality:
const agent = createDreams({
contexts: [
chatContext, // User conversations
gameContext, // Game sessions
adminContext, // Admin functions
],
});
This is where Daydreams excels - contexts working together:
const smartAssistant = context({
type: "assistant",
schema: z.object({ userId: z.string(), plan: z.enum(["free", "pro"]) }),
}).use((state) => [
// Always include user profile
{ context: profileContext, args: { userId: state.args.userId } },
// Always include basic analytics
{ context: analyticsContext, args: { userId: state.args.userId } },
// Add premium features for pro users
...(state.args.plan === "pro" ? [{ context: premiumContext }] : []),
]);
Daydreams provides native Model Context Protocol support through extensions:
import { createMcpExtension } from "@daydreamsai/mcp";
// Connect to any MCP server
createMcpExtension([
// Local servers via stdio
{
id: "files",
transport: { type: "stdio", command: "mcp-server", args: ["./data"] },
},
// Remote servers via HTTP/SSE
{
id: "api",
transport: { type: "sse", serverUrl: "https://mcp-api.example.com" },
},
]);
Popular MCP Servers:
🏠 Complete Documentation - Everything you need to build production agents
🎯 I want to test it myself →
5-minute quickstart
🛠️ I want to see examples → Working examples
🚀 I want to build something → Tutorials
💬 I need help → Join our Discord
E-commerce | Healthcare | Financial Services | Developer Tools |
---|---|---|---|
Customer service at scale | HIPAA-ready agents | Compliance-first design | Code review automation |
Order processing automation | Patient data protection | Built-in risk management | Documentation generation |
Inventory management | Treatment recommendations | Transaction monitoring | API testing assistance |
Explore working examples in examples/
:
Each example includes:
We welcome contributions! See CONTRIBUTING.md for guidelines.
Development setup:
git clone https://github.com/daydreamsai/daydreams.git
cd daydreams
pnpm install
./scripts/build.sh --watch
bun run packages/core # Run tests
Companies using Daydreams:
E-commerce platforms • Healthcare providers • Financial institutions • Developer
tools
💬 Discord Community - Get help from the
team and community
📖 Documentation - Comprehensive guides and
examples
🐛 GitHub Issues - Bug
reports and feature requests
📧 Direct Support - Direct line to our engineering team
⭐ Star this repo • 🚀 Try Daydreams now • 💬 Join Discord
MIT Licensed • Built with ❤️ by the Daydreams team
Please log in to share your review and rating for this MCP.
{ "mcpServers": { "filesystem": { "command": "npx", "args": [ "@modelcontextprotocol/server-filesystem", "./docs" ], "env": {} }, "database": { "command": "npx", "args": [ "@modelcontextprotocol/server-sqlite", "./data.db" ], "env": {} } } }
Discover more MCP servers with similar functionality and use cases
by zed-industries
Provides real-time collaborative editing powered by Rust, enabling developers to edit code instantly across machines with a responsive, GPU-accelerated UI.
by cline
Provides autonomous coding assistance directly in the IDE, enabling file creation, editing, terminal command execution, browser interactions, and tool extension with user approval at each step.
by continuedev
Provides continuous AI assistance across IDEs, terminals, and CI pipelines, offering agents, chat, inline editing, and autocomplete to accelerate software development.
by github
Enables AI agents, assistants, and chatbots to interact with GitHub via natural‑language commands, providing read‑write access to repositories, issues, pull requests, workflows, security data and team activity.
by block
Automates engineering tasks by installing, executing, editing, and testing code using any large language model, providing end‑to‑end project building, debugging, workflow orchestration, and external API interaction.
by RooCodeInc
An autonomous coding agent that lives inside VS Code, capable of generating, refactoring, debugging code, managing files, running terminal commands, controlling a browser, and adapting its behavior through custom modes and instructions.
by lastmile-ai
A lightweight, composable framework for building AI agents using Model Context Protocol and simple workflow patterns.
by firebase
Provides a command‑line interface to manage, test, and deploy Firebase projects, covering hosting, databases, authentication, cloud functions, extensions, and CI/CD workflows.
by gptme
Empowers large language models to act as personal AI assistants directly inside the terminal, providing capabilities such as code execution, file manipulation, web browsing, vision, and interactive tool usage.