Skip to main content
Use run() to create the execution context for one agent run. Events recorded inside the callback are connected to the same run and session.

When to use this

Use run tracking when you want to inspect the full path from user input to final outcome.

How it works

run() creates an async context. The SDK attaches runId, sessionId, workspaceId, agentId, spanId, and parentSpanId to events recorded inside that context. Nested run() calls inherit the parent run and create child span relationships. When a root run() callback returns or throws without an explicit outcome(), the SDK records a technical COMPLETED or FAILED outcome automatically. Call outcome() when you also know whether the business task succeeded, partially succeeded, or failed; the SDK will not add a duplicate automatic outcome.

Example

You can also pass only an agent name.

Semantic helpers

What you can see in Lynx

Run tracking powers:
  • Session timelines
  • Agent decision history
  • Context and memory snapshots
  • Error and slow-step analysis
  • Root cause candidates with evidence

Notes

Keep stable identifiers stable. Use the same agentId for the same agent across deployments. Use appVersion, deploymentId, and promptVersion when you need to compare behavior before and after a change.

Next steps