camelAI Documentation

Guides

Migrate from OpenAI Agents SDK or LangGraph to camelRun v2

Map OpenAI Agents SDK and LangGraph concepts to camelRun v2: keyed agents, tools, CamelFS repos, approvals, workflows, and structured output.

View as Markdown

In the OpenAI Agents SDK and LangGraph, the agent loop runs inside your application process and you operate a session database or checkpointer. In camelRun v2, the model loop, history, compaction, repository state, and pending human inputs persist inside camelRun while your code defines tools and starts runs.

Side-by-side example

OpenAI Agents SDK (TypeScript):

ts
import { Agent, run, tool } from "@openai/agents";

const lookupOrder = tool({
  name: "lookupOrder",
  description: "Look up an order by ID",
  parameters: { type: "object", properties: { orderId: { type: "string" } }, required: ["orderId"] },
  execute: async ({ orderId }) => orders.get(orderId),
});

const agent = new Agent({ name: "Support", instructions: "You help with orders.", tools: [lookupOrder] });
const result = await run(agent, "Where is order 42?");
console.log(result.finalOutput);

camelRun v2 (@camelai/run):

ts
import { CamelRun, defineTool } from "@camelai/run";

const client = new CamelRun({
  baseUrl: "https://run.camelai.com",
  apiKey: process.env.CAMELRUN_API_KEY!,
});

const lookupOrder = defineTool({
  name: "lookupOrder",
  description: "Look up an order by ID",
  parameters: {
    type: "object",
    properties: { orderId: { type: "string" } },
    required: ["orderId"],
  },
  execute: async ({ orderId }: { orderId: string }) => orders.get(orderId),
});

const agent = await client.agents.upsert("support-user-123", {
  instructions: "You help with orders.",
  tools: [lookupOrder],
});

const run = await agent.run("Where is order 42?");
console.log(run.text);
client.close();

For multi-worker servers or serverless functions (where a single process should not hold a tool WebSocket), expose tools via HTTP webhook tools (tools: [{ name, description, parameters, url, headers }]) or a signed MCP server (mcpServers: [{ name, url, auth: { type: "runtime" } }]). See Tools.

OpenAI Agents SDK mapping

OpenAI Agents SDKcamelRun v2
Agent(name, instructions, tools, model)client.agents.upsert(key, { instructions, tools, model }) (PUT /v2/agents/:key)
Runner.run(agent, input), finalOutputagent.run(prompt) -> run.text (POST /v2/agents/:idOrKey/runs)
Runner.run_streamedagent.stream(prompt) or SSE GET /v2/agents/:idOrKey/events?after=0&runId=...
@function_tool / tool()defineTool() (local WebSocket), HTTP webhook url, or mcpServers
Sessions (SQLiteSession, Redis)Keyed agents (PUT /v2/agents/:key) with automatic compaction and agent.history()
output_typeoutputSchema JSON Schema -> run.output (with automatic validation and one repair attempt)
agent.as_tool()builtins: ["delegate"] (delegate, spawn_agent, send_message, wait_agent)
Tool approval (needs_approval)requiresApproval: true on a tool, or signed MCP agent-runtime/approval; resume with agent.answerInput()
RunContextWrappertoolIdentity: { subject, context } on the agent + actor on each run, signed into MCP runtime JWTs
WebSearchToolbuiltins: ["web_search", "web_fetch"]
CodeInterpreterToolbuiltins: ["codemode"] (QuickJS sandbox) and builtins: ["bash"] (persistent Linux container over /workspace)
MCPServerStreamableHttpmcpServers on an agent or definition
max_turnsmaxSteps (1..100, default 25) plus spendLimitUsd per agent and per run
HandoffsNot built-in: use builtins: ["delegate"] or route between keyed agents using POST /v2/decisions

LangGraph mapping

LangGraphcamelRun v2
create_react_agentclient.agents.upsert(key, { model, instructions, tools, builtins })
Checkpointer + thread_idAgent key (for example thread-${threadId})
graph.get_state(config)GET /v2/agents/:idOrKey and GET /v2/agents/:idOrKey/history
interrupt() / Command(resume=...)ask_human, requiresApproval: true, or MCP elicitation/create -> POST /v2/agents/:idOrKey/inputs/:inputId
graph.stream(..., stream_mode="messages")agent.stream(prompt) / SSE GET /v2/agents/:idOrKey/events
with_structured_outputoutputSchema on POST /v2/agents/:idOrKey/runs or POST /v2/runs
Custom StateGraph / durable multi-step flowReplay workflows (POST /v2/agents/:idOrKey/workflows with wf.agent, wf.parallel, wf.bash, wf.step)
Long-term StoreCamelFS repositories (/v2/repos) and dreaming (/workspace/MEMORY.md)
Time travel (get_state_history)agent.fork({ key, atSeq }) (POST /v2/agents/:idOrKey/fork), which forks both conversation history and the CamelFS repository