Stateful Agents

Agents that remember. Context that scales.

Build agents with persistent memory, multi-tier context blocks, tool management, and automatic context optimization.

Persistent
Memory
Multi-tier
Blocks
Tool
Management
Context
Optimization
Features

Everything agents need to remember

Memory Blocks

Persistent memory that survives across conversations. Agents build knowledge over time.

Multi-tier Architecture

Persona, human, system, and custom blocks. Each tier has its own retention and priority rules.

Tool Management

Register, update, and manage tools per agent. Fold optimizes tool descriptions in context.

Context Budgets

Automatic context optimization keeps agents within token budgets without losing important memory.

Artifact Trails

Track every code block, document, and structured output your agent produces.

Playground

Interactive playground for testing agents, adjusting memory, and debugging conversations.

Getting Started

Create an agent in seconds

Define memory blocks, set a system prompt, and start sending messages.

// Create a stateful agent
const agent = await fold.agents.create({
  name: "code-reviewer",
  model: "gpt-4o",
  systemPrompt: "You are an expert code reviewer...",
  memory: {
    persona: "Senior engineer who values clean code",
    blocks: [
      { type: "system", content: "Always check for security issues" },
      { type: "human", content: "Prefers TypeScript and functional patterns" },
    ],
  },
});

// Send a message — agent remembers previous conversations
const response = await fold.agents.message(agent.id, {
  content: "Review this pull request for security issues",
  attachments: [{ type: "code", content: prCode }],
});
Memory Architecture

Four tiers of memory

Each memory tier has its own priority and retention rules. Fold automatically manages what stays in context.

Persona

Defines the agent's identity, expertise, and communication style. Highest priority — always included in context.

Human

Stores information about the user: preferences, past interactions, and working context. Updated automatically.

System

Operational instructions and constraints. Guidelines, safety rules, and behavioral boundaries.

Custom

Application-specific blocks for domain knowledge, project context, or any structured data your agent needs.

Advanced

Streaming, tools, and analytics

Stream responses, manage tools, and monitor context optimization in real time.

// Stream responses from your agent
const stream = await fold.agents.stream(agent.id, {
  content: "Explain the architecture of this codebase",
});

for await (const chunk of stream) {
  process.stdout.write(chunk.text);
}

// Add tools to your agent
await fold.agents.addTool(agent.id, {
  name: "search_code",
  description: "Search the codebase for relevant files",
  parameters: { query: { type: "string" } },
});

// Check context optimization stats
const stats = await fold.agents.stats(agent.id);
console.log(stats.optimization);
// { tokensUsed: 12000, tokensSaved: 34000, savingsPercent: 74 }

Build agents that remember everything.

Without paying for everything.