Creating a run queues it — it does not start execution. This lets you register watchers before the agent starts working.
const run = await client.agent.v1.run.create({ agentId: 'agent_abc123', prompt: 'Search vault vault_xyz for all references to force majeure clauses and compile a summary.',})console.log(run.id) // run_xxxconsole.log(run.status) // "queued"
The agent’s instructions define its general behavior. The run’s guidance adds context for a specific execution:
// Agent instructions: "You analyze contracts for risk."// Run guidance adds specifics for this particular run:const run = await client.agent.v1.run.create({ agentId: agent.id, prompt: 'Analyze the master services agreement in vault vault_abc', guidance: 'Focus on indemnification and limitation of liability. The client is in healthcare, so flag any HIPAA-related concerns.',})
Restrict a run to specific vault objects at runtime. This is useful when you want a general-purpose agent to only work with specific documents for a particular task:
const run = await client.agent.v1.run.create({ agentId: agent.id, prompt: 'Summarize these depositions and identify contradictions.', objectIds: ['obj_depo_001', 'obj_depo_002', 'obj_depo_003'],})
Object scoping is applied at runtime, not at agent creation. This means the same agent can
work with different sets of documents on each run. The agent’s vaultIds restriction (set at
creation) is still enforced — objectIds adds a further narrowing within allowed vaults.
Register a callback URL before executing. You’ll receive a POST when the run completes:
// 1. Create runconst run = await client.agent.v1.run.create({ agentId: agent.id, prompt: 'Analyze the contract...',})// 2. Register watcher BEFORE execawait client.agent.v1.run.watch(run.id, { callbackUrl: 'https://your-app.com/webhooks/agent-complete',})// 3. Executeawait client.agent.v1.run.exec(run.id)// Your webhook receives the result when done
You can replay from a sequence number using either:
Query param: lastEventId
Header: Last-Event-ID
# Stream live (and replay from the beginning)curl -N "https://api.case.dev/agent/v1/run/$RUN_ID/events?lastEventId=0" \ -H "Authorization: Bearer $CASEDEV_API_KEY"
Create an agent, run a complex multi-step task, and get the results:
import Casedev from '@case.dev/sdk'const client = new Casedev({ apiKey: process.env.CASEDEV_API_KEY })// Create a research agentconst agent = await client.agents.create({ name: 'Legal Researcher', instructions: `You are a legal research assistant. When given a topic:1. Search vaults for relevant documents2. Use legal search to find related case law and statutes3. Compile a research memo in markdown4. Upload the memo to the vault5. Return the vault object ID and download URL`,})// Run itconst run = await client.agent.v1.run.create({ agentId: agent.id, prompt: 'Research employment discrimination laws relevant to the documents in vault vault_abc. Upload a report.',})await client.agent.v1.run.exec(run.id)// Wait for completionlet status = await client.agent.v1.run.getStatus(run.id)while (status.status === 'running') { console.log(`Running... ${Math.round(status.durationMs / 1000)}s`) await new Promise((r) => setTimeout(r, 5000)) status = await client.agent.v1.run.getStatus(run.id)}// Get resultsconst details = await client.agent.v1.run.getDetails(run.id)console.log(details.result.output)