@kuralle-agents/cf-agent
v0.6.1
Published
Kuralle agent integration for Cloudflare Workers with AIChatAgent
Maintainers
Readme
@kuralle-agents/cf-agent
Run Kuralle agents on Cloudflare Workers using Durable Objects — CF owns persistence, WebSocket, and stream resumability; Kuralle owns agent orchestration.
Install
npm install @kuralle-agents/cf-agentPeers: agents (Cloudflare Agents SDK), zod.
What it does
KuralleAgent extends CF's AIChatAgent. Subclass it, implement two methods, and your Kuralle agent runs as a Durable Object with automatic SQLite persistence, multi-client sync, and resumable streaming.
Key exports:
KuralleAgent(aliasCfChatAgent) — abstract base class; extend and implementgetAgents()andgetDefaultAgentId().BridgeSessionStore— bridges KuralleSessionStoreinterface to CF's SQLite storage.OrchestrationStore— Durable Object KV for orchestration state.SqlPersistentMemoryStore— DO SQLite-backedPersistentMemoryStorefor USER/MEMORY blocks.createSSEResponse— helper for streaming SSE responses from Workers.
Usage
import { KuralleAgent } from '@kuralle-agents/cf-agent';
import { defineAgent } from '@kuralle-agents/core';
import { createOpenAI } from '@ai-sdk/openai';
interface Env {
OPENAI_API_KEY: string;
}
export class SupportAgent extends KuralleAgent<Env> {
protected getAgents() {
const openai = createOpenAI({ apiKey: this.env.OPENAI_API_KEY });
return [
defineAgent({
id: 'support',
instructions: 'You are a helpful support agent.',
model: openai('gpt-4o-mini'),
}),
];
}
protected getDefaultAgentId() {
return 'support';
}
}
export default SupportAgent;wrangler.toml — declare the Durable Object:
[[durable_objects.bindings]]
name = "SUPPORT_AGENT"
class_name = "SupportAgent"
[[migrations]]
tag = "v1"
new_sqlite_classes = ["SupportAgent"]Working memory blocks
KuralleAgent wires SqlPersistentMemoryStore into defaultWorkingMemoryStore automatically via DO SQLite. Override in getRuntimeConfig() or disable by overriding getWorkingMemoryStore() to return undefined.
import { SqlPersistentMemoryStore } from '@kuralle-agents/cf-agent';
protected getRuntimeConfig() {
return {
defaultWorkingMemoryStore: new SqlPersistentMemoryStore(this.getSql()),
};
}Flows and routing
Attach flows for structured SOPs or routes + routing: { mode: 'structured' } for triage — same defineAgent primitive as Node/Bun. No runtime differences.
Related
@kuralle-agents/core— runtime and agent primitives.@kuralle-agents/hono-server— HTTP/SSE router for Node.js or Bun.- Cloudflare Agents SDK
