camelAI Documentation

Concepts

camelRun v2 concepts: durable agents, runs, CamelFS, and tools

How camelRun v2 works: durable keyed agents, CamelFS repos and session VMs, runs, queue and steer modes, compaction, dreaming, forking, and tools.

View as Markdown

camelRun v2 is built around two primitives: durable keyed agents (AgentDO) and Git-backed repositories with session VMs (CamelFS). Every piece of agent state (configuration, conversation history, compactions, runs, pending inputs, schedules, workflow step caches, and voice sessions) persists in camelRun rather than your application process.

Durable keyed agents

You address an agent by its key (your own identifier such as user-123 or thread-9f2c) or its generated id (agt_...).

ts
const agent = await client.agents.upsert("user-123", {
  model: "azure/gpt-6.2-sol",
  instructions: "You help users troubleshoot deployments.",
  builtins: ["files", "bash", "web_search", "human"],
  repoId: repo.repoId,
  branch: "refs/heads/main",
  spendLimitUsd: 10,
  idleTtlSeconds: 86400,
});
  • PUT /v2/agents/:key creates the agent on first call (201) and updates its configuration on subsequent calls (200), preserving conversation history.
  • You can pass prompt directly in PUT /v2/agents/:key to create or update the agent and kick off its first run in a single HTTP round-trip.
  • Each agent receives a scoped agentToken (agt_tok_<tenantId>.<agentId>.<secret>). That token can run, stream, read history, and answer non-signed inputs on that single agent, and returns 403 on deletion or config changes.
  • idleTtlSeconds controls automatic expiration after inactivity.
  • Deleting an agent (DELETE /v2/agents/:idOrKey) cancels in-flight work, destroys its Durable Object state, and frees the key.

CamelFS repositories and session VMs

Mutable v1 volumes and multi-path mounts are replaced in v2 by CamelFS, a content-addressed Git-like repository service (/v2/repos):

  • An agent binds to at most one repository (repoId) and branch (branch, default refs/heads/main). If you omit repoId and enable file or bash tools, camelRun provisions a repository automatically (or you can call PUT /v2/agents/:idOrKey/repo).
  • Inside the agent's session VM (builtins: ["bash"]), the bound repository is mounted at /workspace with a persistent bash shell. Every command runs atomically and commits changed files back to the branch.
  • File tools (builtins: ["files"]) and the /v2/repos/:repoId/* API read and write commits directly. When a VM is active for the same agent, CamelFS applies API/tool file writes directly into the live /workspace and commits the new tree without conflicts.

See Files and CamelFS.

Runs, queueing, and steering

Sending a prompt to POST /v2/agents/:idOrKey/runs creates a run (RunRecord) with status queued, running, input_required, completed, failed, or cancelled.

An agent executes one active run at a time. You control what happens when a new prompt arrives while a run is active:

SettingBehavior
whileRunning: "queue" (default)Enqueues the prompt to execute after the active run finishes.
whileRunning: "steer"Injects the prompt mid-turn into the active run after its current step (emitting steer_applied). The steer run sets batchedInto to the active run ID.

Key rules for steering and queueing:

  • Spend limits require queueing: A run that specifies spendLimitUsd must use whileRunning: "queue". Passing spendLimitUsd with whileRunning: "steer" returns 400 invalid_spend_limit. Steering an active run keeps the active run's existing spend limit.
  • Attachments require queueing: Runs with files attachments must use whileRunning: "queue" and a configured repository.
  • Actor isolation: If you pass actor (requires a tenant API key), a steer from a different actor than the active run queues as its own run instead of steering.
  • Batch queue mode: Configuring queue: { mode: "batch", windowMs: 1500 } merges consecutive queued prompts arriving within windowMs into a single turn (follower runs record batchedInto). Runs with a per-run spendLimitUsd or an actor always execute individually, even in batch mode.

Waiting, polling, and aborting

  • wait: true (default) waits for the run to settle before returning. Pass wait: false (or call agent.submit()) to return the queued run immediately and follow it over SSE (GET /v2/agents/:idOrKey/events) or poll GET /v2/agents/:idOrKey/runs/:runId.
  • Pass idempotencyKey to make retries safe. Look up a run by key at GET /v2/agents/:idOrKey/runs/:key?by=idempotency-key (agent.getRunByKey(key)).
  • POST /v2/agents/:idOrKey/abort (agent.abort()) aborts the active run and cancels queued runs. Pass { keepQueued: true } to abort only the active run and let queued runs proceed.

Compaction, context reset, and dreaming

Automatic and manual compaction

As conversation history grows toward the model's context window, camelRun compacts older messages into a summary while preserving the full raw message log in GET /v2/agents/:idOrKey/history.

  • Trigger compaction manually with POST /v2/agents/:idOrKey/compact (agent.compact({ summary?, keepLast? })).
  • Reset the model's active context with POST /v2/agents/:idOrKey/reset-context (agent.resetContext({ summary?, keepLast? })). With keepLast: 0 and no summary, messages and compactions are cleared; otherwise a new compaction boundary is recorded at the cutoff.

Dreaming (memory consolidation)

When dreaming: { enabled: true, idleSeconds: 3600 } is configured on an agent, camelRun runs a background memory-consolidation pass after the agent has been idle for idleSeconds, summarizing recent work into /workspace/MEMORY.md in the agent's repository and emitting dream_completed. You can also trigger it on demand with POST /v2/agents/:idOrKey/dream (agent.dream()).

Forking

POST /v2/agents/:idOrKey/fork (agent.fork({ key?, atSeq? })) creates a new independent agent from an existing one:

  • Copies the source agent's configuration, messages up to atSeq (or the latest sequence), and applicable compaction summary.
  • Forks the source agent's CamelFS repository lineage so the forked agent gets its own independent repo and commit history sharing underlying content-addressed objects.
  • Returns { id, key, agentToken, repoId, lineage, branch, commit, forkedFrom: { agentId, atSeq } }.

Where tools run

MechanismHow you configure itBest for
Local WebSocket toolsPass defineTool({ name, description, parameters, execute }) in toolsLong-lived servers or local scripts where tools run in your process over /v2/agents/:idOrKey/ws
HTTP webhook toolsPass { name, description, parameters, url, headers?, requiresApproval? } in toolsStateless HTTP endpoints, serverless functions, and multi-worker backends
Remote MCP serversPass mcpServers: [{ name, url, headers?, auth?, audience?, allowTools? }]Third-party MCP servers or your own signed tool servers using runtime JWTs (auth: { type: "runtime" })
Built-in suitesPass builtins: ["files", "images", "bash", "codemode", "delegate", "workflows", "web_search", "web_fetch", "human"]Ready-made workspace files, SVG rendering, Firecracker bash VMs, QuickJS codemode, sub-agents, replay workflows, web access, and human input

See Tools for full details and schemas.

People in the loop

A run pauses with status: "input_required" whenever:

  • The model calls ask_human (builtins: ["human"]).
  • The model calls a custom tool configured with requiresApproval: true.
  • A signed MCP server (auth: { type: "runtime" }) returns resultType: "input_required" requesting agent-runtime/approval or elicitation/create (form or url mode).

Inspect pending inputs with GET /v2/agents/:idOrKey/inputs and resume the run with POST /v2/agents/:idOrKey/inputs/:inputId (agent.answerInput(inputId, { approved, answer, wait, actor })). See Human input.

Definitions, schedules, and stateless runs

  • Definitions (PUT /v2/definitions/:slug): Reusable agent configurations referenced by definition: "<slug>" when upserting agents or creating channels. See Definitions.
  • Schedules (POST /v2/agents/:idOrKey/schedules): Recurring wake-ups via intervalSeconds or cronExpr. See Schedules and dreaming.
  • Stateless runs and decisions: One-shot calls at POST /v2/runs and classification at POST /v2/decisions without persisting an agent. See Stateless runs and decisions.