DeepAgents
Give a LangChain agent subagents, skills, memory files and a filesystem on a bucket, ask before a tool runs, and test it offline.
The LangChain adapter runs an agent with DeepAgents
when its langchain({ ... }) options select a deep capability: subagents, skills, memory,
backend or interruptOn. RelKit then builds the agent with DeepAgents’ createDeepAgent. Tools,
access rules, the thread, streaming and traces stay with RelKit, as for every agent; see
Agent adapters and LangChain adapter.
The example on this page is a support agent. It asks a person before it delegates a stock check to a subagent, and keeps its notes, skills and memory file in a bucket.
Install DeepAgents
From this guide’s application/package root, install only its selected requirements:
bun add @langchain/core@1.2.9 @langchain/langgraph@1.4.14 @relkit/langchain@0.12.2 @relkit/local@0.12.2 deepagents@1.13.3 langchain@1.5.10 langsmith@0.10.8
Keep these owner-specific versions and the lockfile together. Runtime SDKs belong in dependencies; build/type tooling belongs in devDependencies. Installing an adapter does not supply its optional SDK peers or enable the feature’s configuration.
An agent that selects a deep capability without the deepagents package fails with
RELKIT_DEEPAGENTS_UNAVAILABLE, which names the version to install.
Declare a subagent
A subagent is an agent like any other. Its description tells the parent when to delegate to it.
export const inventory = defineAgent({
id: "inventory",
runtime: langchain(),
description: "Checks whether an order's items are in stock.",
input: question,
output: answer,
instructions: "Answer the delegated stock question in one sentence.",
tools: [],
limits: { maxSteps: 3, maxToolCalls: 2, timeoutMs: 30_000 },
});
The parent delegates with DeepAgents’ task tool. A subagent runs on the parent’s model unless it
declares one, shares the parent’s thread with its own checkpoint namespace, and counts toward the
parent’s limits. It sees the task the parent wrote, not the parent’s input.
Give the agent a filesystem on a bucket
DeepAgents’ file tools (ls, read_file, write_file, edit_file and the search tools) work on a
backend. Pass a RelKit bucket as backend and the files live in that bucket:
export default defineBucket({
id: "support.workspace",
profile: "agent-workspace",
visibility: "private",
maxObjectBytes: 256_000,
allowedContentTypes: ["text/markdown", "text/plain"],
});
- Each thread has a private part of the bucket. The files of one agent on one thread are stored under a prefix of their own. Another thread, or another agent, does not see them.
- Files are text. A
.mdfile is stored astext/markdown, any other astext/plain, so the bucket above allows those two types. - Bind the bucket’s profile to a provider as for any bucket; see Storage.
To share files across threads, such as skills that every conversation uses, pass a native
DeepAgents backend such as FilesystemBackend as backend instead of a bucket.
Declare persistence
An interrupt needs a checkpointer, which keeps the waiting run. The memory store is LangGraph’s long-term store.
// In-memory drivers for the example; use a supported driver in production.
export const checkpoints = defineCheckpointerDb({
id: "support.checkpoints",
client: new MemorySaver(),
});
export const memory = defineMemoryDb({
id: "support.memory",
client: new InMemoryStore(),
});
Before you choose a driver:
- RelKit never calls a saver’s or a store’s
.setup()and never runs its migrations. Initialize the driver yourself before the server starts. - The supported drivers are listed in LangGraph, persistence, and resume.
Redis works as a checkpointer.
RedisStoredoes not satisfydefineMemoryDb’s types with the tested versions, so a Redis memory store is not supported. - Agents do not run on Cloudflare Workers:
relkit checkreportsRELKIT_WORKERS_PROVIDER_UNSUPPORTEDfor theagent-stateprofile. Agents run on Bun and Node.
Define the agent
export default defineAgent({
id: "support.research",
runtime: langchain({
subagents: [inventory],
skills: ["/skills/"],
memory: ["/AGENTS.md"],
backend: workspace,
checkpointer: checkpoints,
store: memory,
interruptOn: { task: { allowedDecisions: ["approve", "reject"] } },
}),
model: "default",
input: question,
output: answer,
instructions: "Delegate stock checks to the inventory agent. Keep what you learn in /AGENTS.md.",
tools: [],
stateProfile: "default",
client: { public: true },
chat: { input: "message", output: "answer" },
controls: ["stop"],
limits: { maxSteps: 10, maxToolCalls: 6, timeoutMs: 60_000 },
});
skills names folders that hold one folder per skill, each with a SKILL.md whose front matter has a
name and a description. The model sees the list of skills and reads a skill’s file when it needs
it. memory names files whose content goes into the model’s instructions.
DeepAgents reads both from the backend when a run starts and keeps what it read in the thread’s
checkpoint (tested with deepagents 1.13.3):
- Memory files are read once per thread, at its first run. A memory file written later on the
same thread does not reach the instructions; the agent reads it with
read_file. - Skills are read at each run until the thread has found one, then kept.
With a bucket as backend, a thread’s skills and memory files are therefore the ones that thread wrote itself. Put skills and memory that every thread needs on a native backend.
Ask before a tool runs
interruptOn names the tools a person must decide on, and the decisions they may take. Here every
delegation waits for approve or reject.
- The run waits before the tool runs. The thread’s status becomes
waiting. Its waiting request names the tool and its arguments, and gives the schema of the reply:{ decisions: [{ type: "approve" }] }, or{ type: "reject", message }. - Resume the same thread with that reply and
resume: true, as for a graph interrupt. The tool then runs once and the run continues. - A resumed step starts from its beginning. Work done before the interrupt in the same step runs again, so put an irreversible effect after the interrupt or make it idempotent.
A RelKit tool asks for approval through its own approval policy; see
Approvals.
Test it offline
createTestModel from @relkit/langchain/testing answers with scripted turns. Return it from the
model registry and the agent runs without a network or an API key. The subagent inherits the model,
so one script holds the turns of both, in the order they run.
// One scripted model answers for the agent and the subagent, which inherits the agent's model.
const model = createTestModel({
script: [
{
type: "tool-call",
callId: "delegate-1",
toolId: "task",
input: { description: "Is order o1 in stock?", subagent_type: "inventory" },
},
{ type: "final", output: { answer: "Order o1 is in stock." } },
{
type: "tool-call",
callId: "skill-1",
toolId: "write_file",
input: { file_path: "/skills/refunds/SKILL.md", content: skill },
},
{
type: "tool-call",
callId: "memory-1",
toolId: "write_file",
input: { file_path: "/AGENTS.md", content: "Customer 42 prefers email." },
},
{ type: "final", output: { answer: "Order o1 is in stock." } },
{
type: "tool-call",
callId: "recall-1",
toolId: "read_file",
input: { file_path: "/AGENTS.md" },
},
{ type: "final", output: { answer: "I will email you." } },
],
});
// Every model profile resolves to the scripted model; nothing leaves the process.
const modelRegistry = {
resolveModel: () => ({ id: model.modelId, model: model.languageModel }),
};
createTestBucketFake from @relkit/testing holds the bucket in memory; pass its client as
bucketBackend. The first run stops at the interrupt with GraphInterruptedError, and the second
resumes it on the same thread:
await expect(
invokeAgent({ ...common, input: { message: "Is order o1 in stock?" } }),
).rejects.toBeInstanceOf(GraphInterruptedError);
const output = await invokeAgent({
...common,
input: { decisions: [{ type: "approve" }] },
resume: true,
});
The test then checks that both files are in the bucket, and that a third run on the same thread
lists the skill and reads the memory file back. A final turn is a call to relkit_output, the tool
RelKit gives every model to return the agent’s output. Reference:
LangChain API.