Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1b2eb3a
feat(experimental): add context memory — persistent key-value blocks
mattzcarey Feb 26, 2026
69cf925
fix: use inputSchema instead of parameters for AI SDK tool type
mattzcarey Feb 26, 2026
50acd2a
Unify Session + Context into single Session API
mattzcarey Mar 23, 2026
084a229
Add TODO for memory features from hermes-agent analysis
mattzcarey Mar 23, 2026
09fc804
feat: reference compaction + frozen snapshot fix
mattzcarey Mar 23, 2026
ba0da8e
Remove tracked .nx cache files
mattzcarey Mar 23, 2026
e8d1984
Update TODO: mark completed items, trim resolved
mattzcarey Mar 23, 2026
e0b8f4e
feat(think): session metadata, compactAndSplit, FTS search
mattzcarey Mar 23, 2026
858b4d5
feat: add branching and compaction records to Session API
mattzcarey Mar 23, 2026
102582a
refactor(think): replace SessionManager internals with agents Session…
mattzcarey Mar 23, 2026
690bb39
refactor(think): integrate compaction, usage tracking, cleanup
mattzcarey Mar 23, 2026
42c5788
test: update session test agents for branching, compaction, context
mattzcarey Mar 23, 2026
4e165ca
update_context tool returns block content, not metadata
mattzcarey Mar 23, 2026
899df45
update_context: add append action, return 'Context successfully written'
mattzcarey Mar 23, 2026
695a7c9
feat: SqliteBlockProvider + Think context block integration
mattzcarey Mar 23, 2026
26f430e
cleanup: remove dead layers from Session API
mattzcarey Mar 23, 2026
52cb0e9
feat: read-time tool output truncation (non-destructive microCompaction)
mattzcarey Mar 23, 2026
f2b5a81
update examples for new Session API
mattzcarey Mar 23, 2026
1c5ee99
session-memory example: add hermes-style compaction
mattzcarey Mar 23, 2026
81ff896
example: multichat — orchestrator with Think facet sessions
mattzcarey Mar 23, 2026
7c8b883
export agents/experimental/memory/utils
mattzcarey Mar 23, 2026
55a79aa
fix: add getMessages alias, use createCompactFunction reference impl
mattzcarey Mar 23, 2026
afe293a
fix: debug tab + compact button + clean client
mattzcarey Mar 23, 2026
78dbd8c
debug drawer: slide-out panel showing LLM context in parallel
mattzcarey Mar 23, 2026
ecc67bd
fix: use icon prop on Button, not children
mattzcarey Mar 23, 2026
71551ed
Session API: context namespace, frozen prompts, multi-session, tests
mattzcarey Mar 23, 2026
ff2ae96
Move SessionManager to agents package, add session_search tool
mattzcarey Mar 23, 2026
3e4f3dd
Use session.tools() in examples to include session_search
mattzcarey Mar 23, 2026
d623090
Flatten API: session.freezeSystemPrompt(), session.replaceContextBloc…
mattzcarey Mar 23, 2026
8857d81
Slim SessionManager to lifecycle only, Session stays lean
mattzcarey Mar 23, 2026
c9c2448
Add tests for SessionManager, session_search tool, context block prox…
mattzcarey Mar 23, 2026
913eb82
Clean up search: session.search scoped, manager.search queries FTS di…
mattzcarey Mar 23, 2026
f277b43
Move session_search to manager.tools(), session.tools() is context only
mattzcarey Mar 23, 2026
8a0f64c
Align SessionManager API with Think, replace Think's SessionManager
mattzcarey Mar 23, 2026
721b849
Use Think's table names (assistant_*) for backward compat
mattzcarey Mar 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions examples/assistant/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ export class ChatSession extends Think<Env, AgentConfig> {
});
}

override getSystemPrompt(): string {
override getContextBlocks() {
const config = this.getConfig();
if (config?.systemPrompt) return config.systemPrompt;

return `You are a helpful assistant with access to workspace tools.
return [
{
label: "soul",
description: "Agent identity and instructions",
defaultContent: config?.systemPrompt ?? `You are a helpful assistant with access to workspace tools.

You have two workspaces:
- Session workspace (private to this conversation): read, write, edit, list, find, grep, delete
Expand All @@ -164,17 +166,20 @@ You also have an "execute" tool that runs JavaScript in a sandbox with access to
Use it for multi-file refactors, coordinated edits, search/replace across files, or any batch operation.
For simple single-file reads and writes, prefer the direct tools.

Example execute usage:
await state.replaceInFiles("/src/**/*.ts", "oldName", "newName");
const plan = await state.planEdits([...]);
await state.applyEditPlan(plan);

Guidelines:
- Always read a file before editing it
- When editing, provide enough context in old_string to make the match unique
- Use find/shared_find to discover project structure
- Use grep/shared_grep to search for patterns across files
- For bulk changes across many files, use the execute tool with state.*`;
- For bulk changes across many files, use the execute tool with state.*`,
readonly: true,
},
{
label: "memory",
description: "Learned facts — save environment details, conventions, user preferences",
maxTokens: 1100,
},
];
}

override getTools(): ToolSet {
Expand Down
46 changes: 46 additions & 0 deletions experimental/multi-session-agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Session Memory Example

Demonstrates the experimental `Session` API for conversation history with automatic compaction.

## Session API

```typescript
import {
Session,
AgentSessionProvider
} from "agents/experimental/memory/session";

export class ChatAgent extends Agent<Env> {
// microCompaction is enabled by default — truncates tool outputs
// and long text in older messages on every append()
session = new Session(new AgentSessionProvider(this), {
compaction: {
tokenThreshold: 10000,
fn: (msgs) => compactMessages(msgs, this.env.AI)
}
});

@callable()
async chat(message: string, messageId?: string): Promise<string> {
await this.session.append({
id: messageId ?? `user-${crypto.randomUUID()}`,
role: "user",
parts: [{ type: "text", text: message }]
});
const response = await generateResponse(this.session.getMessages());
await this.session.append({
id: `assistant-${crypto.randomUUID()}`,
role: "assistant",
parts: [{ type: "text", text: response }]
});
return response;
}
}
```

## Setup

```bash
npm install
npm start
```
13 changes: 13 additions & 0 deletions experimental/multi-session-agent/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable */
// Generated by Wrangler by running `wrangler types env.d.ts --include-runtime false` (hash: 33efd3b17229f92f32173efc2e9ad735)
declare namespace Cloudflare {
interface GlobalProps {
mainModule: typeof import("./src/server");
durableNamespaces: "ChatAgent";
}
interface Env {
AI: Ai;
ChatAgent: DurableObjectNamespace<import("./src/server").ChatAgent>;
}
}
interface Env extends Cloudflare.Env {}
20 changes: 20 additions & 0 deletions experimental/multi-session-agent/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html lang="en" data-theme="workers">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="/favicon.ico" />
<title>Multi-Session Agent</title>
<script>
(() => {
const mode = localStorage.getItem("theme") || "light";
document.documentElement.setAttribute("data-mode", mode);
document.documentElement.style.colorScheme = mode;
})();
</script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions experimental/multi-session-agent/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@cloudflare/agents-multi-session-example",
"version": "0.0.0",
"description": "Single Agent with multiple independent chat sessions via Session API",
"private": true,
"type": "module",
"scripts": {
"start": "vite dev",
"deploy": "vite build && wrangler deploy",
"types": "wrangler types env.d.ts --include-runtime false"
},
"dependencies": {
"@cloudflare/agents-ui": "*",
"@cloudflare/kumo": "^1.15.0",
"@phosphor-icons/react": "^2.1.10",
"agents": "*",
"ai": "^6.0.134",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"workers-ai-provider": "*"
},
"devDependencies": {
"@tailwindcss/vite": "^4",
"tailwindcss": "^4.2.2"
}
}
Binary file added experimental/multi-session-agent/public/favicon.ico
Binary file not shown.
Loading
Loading