Open MercatoDocsSearch docsAPI reference

Framework

Trace capture policy and step metadata

A run can be useful to diagnose without retaining the full customer prompt. Choose which trace fields to capture, how long to keep them, and which role may inspect content when a summary is insufficient.

Every LLM step of an Agent Orchestrator run answers four questions: which model, with which parameters, how many tokens, and at what cost. What a step records is governed by a per-tenant trace capture policy.

Capture levels

LevelWhat a step records
offThe legacy span attributes only (inputTokens, outputTokens, finishReason). Output is byte-identical to earlier releases.
metadataModel, parameters as sent, usage, cost, latency, response id, content hashes and sizes, capture fidelity. No prompt or response content. Default.
fullEverything metadata records, plus the redacted request and response of each step and the packed context payload, stored as encrypted artifacts. See Content capture.

Resolution order

For each run the level is resolved from the most specific source to the least specific:

  1. An unexpired per-agent override (perAgent, optionally time-boxed with until).
  2. The tenant policy: evalLevel for evaluation runs when set, otherwise level.
  3. The deployment default (OM_AGENT_TRACE_CONTENT_DEFAULT, default metadata).

The result is then clamped to the deployment ceiling (OM_AGENT_TRACE_CONTENT_MAX, default full). A level that the ceiling lowers is reported with source deployment. An unrecognized environment value falls back to metadata for the default and never to a looser level. A tenant that never saved a policy uses the deployment default, and per-agent overrides apply only to tenants that saved one.

The resolved capture (level, source, retentionDays, redactPii) is written to the run manifest as om.capture, and the run page shows it.

OM_AGENT_TRACE_CAPTURE=off remains the kill switch for per-step span capture on native runs.

Policy settings

Stored in module config agent_orchestrator/trace_capture_policy per tenant:

FieldMeaning
levelTenant level. Defaults to metadata.
evalLevelOptional level for evaluation runs.
perAgentUp to 200 overrides keyed by agent id, each with level and an optional until expiry.
retentionDays1 to 3650, default 30.
redactPiiDefault false.
includeProviderBodyDefault false.

retentionDays and redactPii apply to captured content and are also recorded in om.capture. includeProviderBody is stored but has no effect: the model SDK does not expose the raw provider request body, so the artifacts are built from the call the runtime made. The settings page keeps it read-only and preserves the stored value on save.

Manage it at /backend/settings/trace-capture, or through GET and PUT /api/agent_orchestrator/trace-capture/settings. Saves go through the undoable command agent_orchestrator.traceCapturePolicy.update and use optimistic locking on the row's updatedAt.

Step span attributes

Each LLM span carries these keys when the level is metadata or above.

AttributeMeaning
gen_ai.operation.name, gen_ai.provider.nameOperation and provider.
gen_ai.request.modelRequested model.
gen_ai.request.temperature, top_p, top_k, max_tokens, seed, stop_sequences, presence_penalty, frequency_penaltyParameters as sent to the provider. Only values actually sent are recorded.
gen_ai.response.model, gen_ai.response.id, gen_ai.response.finish_reasonsWhat the provider answered.
gen_ai.usage.input_tokens, output_tokensToken usage.
gen_ai.usage.cache_read.input_tokens, gen_ai.usage.reasoning.output_tokensCached input and reasoning tokens when reported.
om.cost.micros, om.cost.currency, om.cost.pricing_sourceEstimated cost, see below.
om.latency.msModel call latency.
om.prompt.system.sha256, om.tools.sha256, om.tools.count, om.messages.countHashes and counts for the request, never the text.
om.content.request.sha256, om.content.request.bytes, and the response equivalentsContent hashes and sizes. The hash is computed over the request as sent, before redaction.
om.content.request.key, om.content.response.keyStorage keys of the content artifacts. Only at full, and only when the upload succeeded.
om.content.statusstored, over_cap_truncated (stored, but cut to the byte cap), storage_unavailable (storage unavailable or the upload failed; metadata only), encryption_unavailable (nothing was stored because tenant data encryption is on but unavailable; metadata only), or disabled below full.
om.content.redactions{ rule, count } per redaction rule applied to the stored content.
om.capture.fidelityexact, reconstructed or reported.
om.params.defaultstrue when no request parameters were sent at all, so every parameter was left to the provider default. Not written when any parameter was sent.
om.params.ignoredRequested settings the provider reported as unsupported and dropped (unsupported warnings of the AI SDK), for example temperature and topP on OpenAI reasoning models or seed on the OpenAI Responses API. A dropped setting is not written as gen_ai.request.*; the trace page shows it as "Ignored by the model". Exported over OTLP as the same key.

The legacy keys inputTokens, outputTokens and finishReason are still written, so existing consumers keep working.

Fidelity

Cost in micros

om.cost.micros is the estimated cost in millionths of the currency unit (an integer), computed from the token counts and the price table. Prices come from the built-in table and can be overridden with OM_AGENT_MODEL_PRICING (JSON, per one million tokens); the currency is OM_AGENT_COST_CURRENCY. Cached and reasoning tokens have no separate price. When a model has no known price, om.cost.pricing_source is set to unknown and om.cost.micros and om.cost.currency are omitted.

Content capture

At the full level each LLM step uploads two artifacts and the context assembler uploads one more per run. They are written to the agent-trace-content storage namespace, encrypted, and scoped to the run's tenant and organization.

ArtifactSchemaHolds
LLM requestom.llm_request.v1Provider, model, system prompt, messages, tool definitions, response format and parameters.
LLM responseom.llm_response.v1Finish reason, content parts, structured object, usage and provider metadata.
Context payloadom.context_payload.v1The packed context records, screened untrusted text and the retrieval query. Referenced by the context bundle's payloadRef.

A failed upload never fails the run: the step records om.content.status = storage_unavailable and keeps its metadata.

With tenant data encryption on, content is never written to storage unencrypted. If the encryption service is missing, the KMS is unhealthy, or no data key can be resolved for the tenant, the upload is skipped and the step records encryption_unavailable. The same rule applies to the other offloaded payloads (full run output, tool request/response, integrity evidence) and to agent-produced file artifacts, which are marked as failed captures. When an operator turns encryption off (TENANT_DATA_ENCRYPTION=false), artifacts are stored unencrypted, like every other encrypted column in that mode. Blobs of either form stay readable.

Where the failure shows up on the trace page:

Redaction

Content is redacted before it is stored. Secret-looking object keys and secret strings (session tokens, authorization headers, bearer and basic credentials) are always removed. With redactPii on, emails, phone numbers, IBANs and card numbers are replaced as well. File and image parts are replaced by { type: 'file', mediaType, bytes, sha256 }, so binary data is never stored. Every rule that fired is counted in om.content.redactions.

Size cap

Each artifact is capped at OM_AGENT_TRACE_CONTENT_MAX_BYTES (default 1 MiB). Over the cap the largest messages are truncated first and replaced with { _truncated: true, originalBytes }, and the step status becomes over_cap_truncated.

Reading content

Captured content is served by GET /api/agent_orchestrator/runs/:id/artifact?kind=llm_request|llm_response|context_payload&key=…:

The other artifact kinds (output, tool_request, tool_response, raw_output) keep their earlier behavior, including 502 when the object is missing.

Retention

The agent_orchestrator:trace-content-retention worker runs once a day per organization (a schedule registered by the module's tenant setup; for organizations that existed before the worker shipped, register it with yarn mercato agent_orchestrator trace-retention:schedule [--tenant <id>] [--org <id>]). It reads content keys from the database, from llm spans and context bundles created before the retention cutoff, and deletes those objects. It walks the rows in creation order from a per-organization cursor (kept in tenant-scoped module config as trace_content_retention_cursor:<organizationId>:<llm_span|context_bundle>), so a run that was missed, a lowered retentionDays or a backlog larger than one run (10,000 rows per row family) is caught up by the next runs. A key that has not expired yet holds the cursor so the next run retries it. A key whose delete fails is reported (reportError code agent_orchestrator.trace_content_retention_delete_failed, plus a scoped warning log), and the cursor moves past it, so that key is not retried and has to be removed by hand. An object that is already gone counts as deleted, and when storage is unavailable the organization is skipped until the next run. Span and bundle rows are append-only and are not changed: the route answers 410 from the key's age.

A bucket lifecycle rule that expires objects under the agent-trace-content prefix after your longest retentionDays remains a useful backstop for objects no span or bundle references.

Captured content counts against the tenant's attachment storage quota.

Permissions

FeatureGrants
agent_orchestrator.trace.viewReading traces, step metadata and the current capture policy.
agent_orchestrator.trace.view_contentChanging the capture policy and reading captured content. It depends on trace.view, is held by admin and superadmin through the module wildcard, and is not part of any narrower default role.

Saving the policy needs both agent_orchestrator.agents.manage and agent_orchestrator.trace.view_content.

Environment variables

VariableDefaultPurpose
OM_AGENT_TRACE_CAPTUREonoff disables per-step span capture on native runs.
OM_AGENT_TRACE_CONTENT_DEFAULTmetadataDeployment default level.
OM_AGENT_TRACE_CONTENT_MAXfullDeployment ceiling. Set metadata to forbid content capture everywhere.
OM_AGENT_TRACE_CONTENT_MAX_BYTES1048576Byte cap per content artifact.
OM_AGENT_MODEL_PRICINGbuilt-in tableJSON price override.
OM_AGENT_COST_CURRENCYUSDCurrency label for cost.

See also Exporting agent traces to OpenTelemetry.

Check with a synthetic conversation

Run one test turn containing an invented customer reference and ordinary text. Inspect the trace as a user with trace access, then as a user allowed to view captured content. Confirm that both the retained fields and access match the policy you chose.

Previous: Running agent evals in CI · Next: Exporting agent traces to OpenTelemetry