Back to Documentation

Agent Execution

Run agents and monitor their execution in real-time.

Run an Agent

const run = await client.agents.run(agentId, {
  input: "Help me find a product",
  sessionId: "user-123",
  stream: true
});

for await (const event of run) {
  if (event.type === 'message') {
    console.log('Agent:', event.content);
  } else if (event.type === 'tool_call') {
    console.log('Calling tool:', event.name);
  }
}

Execution Options

Streaming

Receive responses as they're generated.

Timeout

Set maximum execution time.

Max Iterations

Limit tool call loops.

Monitor Runs

// Get run status
const status = await client.runs.get(runId);
console.log('Status:', status.state);
console.log('Duration:', status.duration);
console.log('Tokens used:', status.usage.totalTokens);

// List recent runs
const runs = await client.runs.list({ agentId, limit: 10 });