@deepagents/experimental
A home for unstable, in-progress building blocks that are not yet part of the
stable @deepagents/* surface. APIs here may change without notice.
@deepagents/experimental/providers/codex
codex('gpt-5.5') creates an AI SDK model using an existing ChatGPT login from
codex login. Apps that own user accounts can use createCodexAccounts() for
per-user ChatGPT device sign-in instead. Zukhruf continues to own tools, history,
and turn execution. See the
provider API and credential behavior.
@deepagents/experimental/providers/claude
claude('claude-sonnet-4-6') creates an AI SDK model using the existing Claude Code
login. Apps that own user accounts can use createClaudeAccounts() for per-user
Claude Pro or Max PKCE sign-in instead. It follows the same provider protocol
while Zukhruf owns task execution. See the
provider API and credential behavior.
@deepagents/experimental/coding-agent-reminders
coding-agent-reminders is an experimental event-aware reminder and guard
framework for coding agents. It provides Claude Code hook types, predicates,
context normalization, command I/O, and rule evaluation without prescribing a
reminder catalog. See
src/coding-agent-reminders/README.md
for the public API and lifecycle mapping.
@deepagents/experimental/zukhruf
Zukhruf provides a declaration API and a runtime for durable background agents,
built on @deepagents/context primitives (agent(), ContextEngine, AgentSandbox,
fragments, the stream subsystem).
import {
AgentRuntime,
PgBossTurnQueue,
defineAgent,
defineStack,
} from '@deepagents/experimental/zukhruf';
The public experimental surface contains the pure declaration layer
(defineAgent / defineInstructions / defineTool / defineSandbox),
AgentRuntime, typed runtime plugins, the domain values, and the store/queue
ports and adapters. The optional Hono transport plugin is a separate
@deepagents/experimental/zukhruf/http entry point.
Declarations have a types-only dependency on @deepagents/context.
defineAgent() accepts native AI SDK reasoning, maxOutputTokens,
timeout, toolCallConcurrency, toolApproval, and
experimental_toolApprovalSecret settings. The runtime forwards them to each
turn without adding defaults. If you configure a signing secret, reuse it
across workers and restarts that resume the same approval. A toolApproval
map overrides needsApproval for the listed tools; unlisted tools keep their
own rules. A callback controls every tool call, including tools added by the
runtime. The runtime stores approvals and resumes turns after a decision.
defineAgent() also accepts the AI SDK's stopWhen: one condition or an array
of conditions imported from ai. For example,
[hasToolCall('notify'), isStepCount(6)] stops after a step calls notify or
after six completed steps, whichever happens first. A step can execute several
tool calls before the condition is checked. The default is isStepCount(200),
inherited from agent() in @deepagents/context.
A session has no title until it is renamed or titled, and listHistory gives
its preview, the first message cut at 60 characters. title: { model } on the
root declaration titles a session with that model: each turn of an untitled
session starts a title call beside the turn, from its first message, and the
turn never waits for it. The title is written only while the session has none,
so the first title wins and a rename made meanwhile is kept, and GET /events
announces it. A failed call writes nothing and emits a SessionTitleWarning;
the next turn tries again. Stop leaves a title call running; disposing the
runtime host aborts it. A sub-agent's chat is never titled. Pick a small, fast
model.
If the provider interrupts a response, the runtime retains partial output
and marks the turn failed without automatically retrying it. Compaction
keeps the input token and prompt cache measurements from the last successful
step.
If a response ends midway through a tool's arguments, chat persistence records
that call as output-error with the message
Tool input ended before the call was complete. The incomplete call does not
execute or leave the conversation waiting for client input, so the next queued
user turn can proceed.
The AgentHost returned by AgentRuntime.initialize() exposes enqueue, host
mailbox delivery, observation, approval, denial, worker lifecycle,
model-facing collaboration for declared subagents, and session deletion and
archiving (deleteSession, archiveSession, unarchiveSession, and
listHistory(userId, { archived })), and renaming (setSessionTitle). Its control plane, executor,
status projector, mailbox coordinator,
and injected collaboration-tool implementations are internal wiring. See
src/zukhruf/DESIGN.md for the decided semantics,
TODO.md for the convergence plan, and
BUGS.md for known residue.
Compose infrastructure in a reusable defineStack(async (resources) => ...)
recipe returning { storage }, plus any plugin bindings or host options.
storage is an AgentStorage: the context store, stream manager, turn queue
and mailbox store on one database, the wakes of the sandbox idle stop on their
own queue beside the turn queue, one queue per settle follow-up (the idle
stop's arm and each plugin's conversationAvailable, recorded before the turn
queue releases a settled turn), and admit(tree, work), which runs work
with all four bound to one unit under a per-tree lock. On PostgreSQL,
PostgresAgentStorage.create({ pool, boss }) builds the stores on the host's
pool and the turn queue on PgBoss, refuses a PgBoss on another database with
AgentStorageDatabaseMismatchError, and admits in one transaction under a
per-tree advisory lock. It borrows the pool and PgBoss; register it with
resources.use() so the host closes the stream change source it opened.
For one process, EmbeddedAgentStorage.open({ directory }) keeps the stores in
<directory>/zukhruf.sqlite and pg-boss on PGlite in <directory>/zukhruf.queue,
and closes both. Its admissions run one at a time in one SQLite BEGIN IMMEDIATE transaction; a turn pushed inside one is an outbox row of that
transaction, which a relay pushes to pg-boss after the commit, and open
pushes the rows a killed process left. Work inside admit uses its scope: a
call to the storage itself there rejects with AdmissionScopeError. The
callback receives JavaScript's native AsyncDisposableStack: use
resources.use() for disposable adapters and resources.adopt() for adapters
exposing a cleanup method. Backend choices and startup calls stay explicit.
const stack = defineStack(async (resources) => ({
storage: resources.use(await PostgresAgentStorage.create({ pool, boss })),
multiAgent: Team.codex({ maxConcurrentThreads: 4 }),
}));
multiAgent takes a Team, the collaboration tools and guidance every agent
of the tree gets; omitted, it is Team.codex(), all six tools.
Multi-agent mode: every turn of the root and of each subagent ends its system
prompt with Codex's <multi_agent_mode> message, apart from the guidance, so a
guidance rewrite never removes it. multiAgentMode: 'explicitRequestOnly'
(the default) spawns only when the user, AGENTS.md or a skill asks for it;
'proactive' delegates whenever parallel work could save time or improve
quality.
multiAgent: Team.codex({ multiAgentMode: 'proactive' }),
Direct messaging: a team without DirectMessaging has no send_message or
followup_task, and its guidance does not mention them. Agents still spawn,
wait, and get each child's final answer, as with Codex's
disable_direct_message.
multiAgent: new Team(new Spawning()).with(new Supervision()).with(new Waiting()),
import declaration from './agent.ts';
import stack from './stack.ts';
const runtime = new AgentRuntime(declaration);
await using host = await runtime.initialize(stack);
await using worker = await host.work();
Importing the recipe or constructing the runtime opens nothing.
runtime.initialize(stack) opens and validates one stack, then returns the
ready host without starting workers. info, plugin(), observe(), and HTTP
plugin projection are available on that host. Host disposal waits for startup,
drains active queue and plugin workers, closes plugins, then releases the
registered adapters in reverse order. Startup failures roll back resources.
Stopping a worker alone keeps its host and adapters available.
Every host initializes from a defineStack recipe. A recipe can return shared
adapters without registering them with resources; those adapters remain
caller-owned. Host and worker disposal always wait for active work. Only
registered adapters are released by host disposal.
An agent's sandbox is defineSandbox(environment, options), where
environment is a @deepagents/context sandbox environment that gives each
chat its own sandbox (see
one-off and chat sandboxes).
An environment that can stop its sandboxes (Docker, Apple container,
microsandbox) requires idleTimeoutMs: the runtime stops a chat's sandbox,
keeping its files, once the chat has been idle that many milliseconds, and the
next turn starts it again. 0 stops it as soon as the chat is idle and false
never stops it while the chat is idle; there is no default. Archiving a session
stops its sandboxes at once, whatever their idleTimeoutMs. The virtual and
Daytona environments take no idleTimeoutMs.
import { DockerSandboxEnvironment } from '@deepagents/context';
import { defineSandbox } from '@deepagents/experimental/zukhruf';
const sandbox = defineSandbox(
new DockerSandboxEnvironment({ namespace: 'analytics', image: 'node:lts' }),
{ idleTimeoutMs: 10 * 60_000 },
);
A chat waiting on an approval is not idle, so its sandbox keeps running, and
each sub-agent's sandbox stops on its own declaration's idle time. See the
sandbox idle stop in src/zukhruf/DESIGN.md.
The host lazily acquires one sandbox handle per agent declaration and
conversation from the agent's sandbox declaration. Later turns and plugins
borrow the same handle; they must leave disposal to the host. A failed
acquisition is retried on the next request. Host disposal closes the held
handles after its workers stop; closing a handle never stops or removes the
chat's sandbox.
host.deleteSession(conversation) deletes a session and every sub-agent chat
under it: it stops their turns, waiting at most 10 s for a running one, removes
each sandbox through its environment's delete, then their mail, streams and
chats, and refuses the session's id from then on, for every user. Data the
host keeps per conversation (a volume, an object-storage prefix) is the host's
to remove: the stack's conversationDataCleanup gets every deleted
conversation once their sandboxes are gone, and its rejection aborts the
delete, which a second call finishes.
host.archiveSession(conversation) hides a session from listHistory,
refuses its new turns, scheduled ones included, interrupts its turns as Stop
does and stops its sandboxes; host.unarchiveSession(conversation) brings it
back and runs nothing. host.setSessionTitle(conversation, title) renames a session
with the trimmed title, and rejects an empty one with EmptySessionTitleError.
See session delete and archive in
src/zukhruf/DESIGN.md.
const stack = defineStack(async (resources) => ({
storage: resources.use(await PostgresAgentStorage.create({ pool, boss })),
conversationDataCleanup: async (conversations) => {
for (const { chatId } of conversations) await removeChatVolume(chatId);
},
}));
Zukhruf discovers immediate skills/<name>/SKILL.md children from each
configured sandbox once per conversation. It persists only the ordered catalog
(name, description, and model-visible path) in chat metadata so later turns
and process restarts reconstruct the same prompt fragment without rediscovery.
Skill bodies, scripts, references, and assets remain in the sandbox. Providers
may preinstall or mount them, or opt into the existing uploadDirectory support
when creating the sandbox.