Skip to main content

Run Tools

Tools for execution tracking — start, report usage, and close agent runs.

Every agent execution that touches OpRelay should open a run at the start and close it at the end. The run_id threads tasks, facts, and failures together for audit and cost tracking.


core_start_run

Begin an execution run. Returns a run_id used for all subsequent reporting.

ParameterTypeRequiredDescription
project_keystringProject identifier
agent_idUUIDExecuting agent
run_idUUIDExplicit run ID (generated if omitted)
summarystringIntent or description (max 2000)
meta_jsonobjectArbitrary metadata
const { run_id } = await oprelay.call("core_start_run", {
project_key: "myproject",
agent_id: "agent-uuid",
summary: "Deploying rate limiter to staging"
});

core_report_usage

Accumulate token usage mid-run. Adds to existing totals — safe to call multiple times per run.

ParameterTypeRequiredDescription
run_idUUIDRun UUID from core_start_run
token_usageobjectUsage object (see fields below)
tracesarrayPer-call trace entries (max 200)

token_usage fields:

FieldTypeDescription
input_tokensnumberInput token count
output_tokensnumberOutput token count
total_tokensnumberTotal token count
cost_usdnumberEstimated cost
modelstringModel identifier (e.g. claude-opus-4)
llm_callsnumberNumber of LLM calls in this batch
prompt_previewstringSanitized prompt excerpt (max 2000)
await oprelay.call("core_report_usage", {
run_id: "run-uuid",
token_usage: {
input_tokens: 8400,
output_tokens: 1200,
cost_usd: 0.028,
model: "claude-opus-4",
llm_calls: 3
}
});

core_end_run

Close a run with final status and summary.

ParameterTypeRequiredDescription
run_idUUIDRun UUID to close
statusstringcompleted, failed, or interrupted
summarystringHuman-readable outcome (max 2000)
meta_jsonobjectFinal metadata
token_usageobjectFinal token usage (same shape as core_report_usage)
tracesarrayFinal trace entries (max 200)
await oprelay.call("core_end_run", {
run_id: "run-uuid",
status: "completed",
summary: "Rate limiter deployed and verified in staging",
token_usage: {
input_tokens: 12400,
output_tokens: 3200,
cost_usd: 0.042,
model: "claude-opus-4",
llm_calls: 7
}
});

core_record_failure

Record a structured failure event linked to a run. Used for dispatch learning and failure resolution matching.

ParameterTypeRequiredDescription
project_keystringProject identifier
run_idUUIDRun that produced the failure
agent_idUUIDAgent that failed
summarystringShort failure description (max 2000)
task_idUUIDAssociated task
errorstringFull error message or stack trace (max 8000)
contextobjectStructured context at time of failure
metaobjectArbitrary metadata
await oprelay.call("core_record_failure", {
project_key: "myproject",
run_id: "run-uuid",
agent_id: "agent-uuid",
task_id: "task-uuid",
summary: "Database connection timeout during migration",
error: "Error: connect ETIMEDOUT 10.0.0.5:5432",
context: { migration: "0042_add_index", attempt: 2 }
});

record_run

v1 run tool. Append a plain audit trail entry for an agent session. Does not require a pre-existing run ID — creates a complete record in one call.

ParameterTypeRequiredDescription
project_keystringProject identifier
agentstringAgent name or identifier (max 128)
summarystringWhat the agent did (max 2000)
ticketstringLinked ticket ID (max 64)
meta_jsonobjectArbitrary metadata
await oprelay.call("record_run", {
project_key: "myproject",
agent: "claude-opus",
ticket: "OPR-429",
summary: "Implemented project isolation. All MCP tools now enforce project_key access."
});

Use core_start_run / core_end_run for new work that needs token tracking. Use record_run for lightweight audit entries or v1 compatibility.