Creating a run queues it — it does not start execution. This lets you register watchers before the agent starts working.
Copy
Ask AI
const run = await client.agents.runs.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:
Copy
Ask AI
// Agent instructions: "You analyze contracts for risk."// Run guidance adds specifics for this particular run:const run = await client.agents.runs.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.',})
Register a callback URL before executing. You’ll receive a POST when the run completes:
Copy
Ask AI
// 1. Create runconst run = await client.agents.runs.create({ agentId: agent.id, prompt: 'Analyze the contract...',})// 2. Register watcher BEFORE execawait client.agents.runs.watch(run.id, { callbackUrl: 'https://your-app.com/webhooks/agent-complete',})// 3. Executeawait client.agents.runs.exec(run.id)// Your webhook receives the result when done
Create an agent, run a complex multi-step task, and get the results:
Copy
Ask AI
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.agents.runs.create({ agentId: agent.id, prompt: 'Research employment discrimination laws relevant to the documents in vault vault_abc. Upload a report.',})await client.agents.runs.exec(run.id)// Wait for completionlet status = await client.agents.runs.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.agents.runs.getStatus(run.id)}// Get resultsconst details = await client.agents.runs.getDetails(run.id)console.log(details.result.output)