Skip to main content

Termination Correctness (term_corr)

Contents​

Metric Description​

Termination correctness is a trace-level metric: it measures whether an agent stopped at the right moment on a full OpenInference-format trace. It scores the stop, not whether each result was obtained (Task Completion), whether the SOP was followed (Plan Adherence), whether the plan was a good one (Plan Quality), or whether the path was cheap (Trajectory Efficiency).

The score runs from 0 (the agent stopped while work was still reachable, or never produced its own close-out) to 100 (it stopped as soon as the reachable work was settled).

Where the criteria come from

  • If you pass definition_of_done as a non-empty string, that free text is split into atomic outcomes. A result the text forbids — an end-state action such as booking, sending, paying, or deleting — is replaced by its absence (for example, "no reservation was made"). Doing that forbidden action leaves the absence outcome still remaining, which scores 0. When the text both requires a result and forbids it, the forbid wins. Tone, language, and format rules are not turned into absence outcomes. A value that is not a string fails evaluation.
  • If you omit the key, send null, "", or whitespace only, the metric generates atomic outcomes from the trace’s system and user prompts. A result either prompt forbids becomes an absence outcome the same way. When the prompts conflict, the system prompt wins. Confirmation codes and similar proof artifacts are included only when the prompts asked for them.
  • If neither source yields usable outcomes, evaluation exits with no score.

How it is judged

  1. Locate the stop. The stop is the last LLM, TOOL, RETRIEVER, or GUARDRAIL in list order. An action output or a guardrail verdict can be the close-out. A guardrail with status ERROR is a tripwire, not a stop the agent chose, so the row before it is the stop. A failed run, or a model turn that still requested tools and never closed out, is not a decision to stop (no score, and no model is called). A run that ends on a sub-agent’s close-out, or with an empty answer, scores 0.
  2. Judge each outcome on the compact trajectory. Each outcome is done, blocked, remaining, or not_applicable. Guardrail rows stay in that trajectory as unscored context, with their verdict, so a policy check can be cited. The judge does not choose the score.
  3. Score the stop in code. Any outcome still remaining is 0, including a violated absence. Nothing left and no continuation is 100, including a task that is fully blocked. Scored work after the latest evidence row lowers the score to the share of duration and tokens spent before that point (equal weight when both were recorded). A measurement the continuation does not have is dropped. When neither was recorded, the score is the share of scored rows before that point. The closing assistant answer is not extra work. A run that ends on a tool or retriever counts that action as extra work unless the action itself settled an outcome. A guardrail row is never extra work. If every outcome is not_applicable, the metric returns no score (null).
Important

This metric does not give partial credit for outcomes that were only partly obtained, and it does not score plan quality, SOP adherence, tool-name correctness, or efficiency. Pair it with Task Completion when you need whether the requested results were obtained, with Plan Adherence when procedure fidelity matters, with Plan Quality when the executed work should be judged against a generated gold plan, and with Trajectory Efficiency when path cost matters.

How to interpret the score​

  • 100: reachable work was settled, and the agent did not keep working after that.
  • Less than 100: the agent stopped too early, did something the criteria forbid, or kept working after the work was settled. 0 also covers a run that ended on a sub-agent’s response or with an empty answer.
  • No score (null): every outcome was not applicable, the run failed or never closed out, or success criteria could not be resolved.

Evaluation returns no score when the payload is not a non-empty list of span objects, when definition_of_done is not a string, when no system or user prompts are found (and definition_of_done was omitted), when no success criteria can be extracted or generated, when the run failed or ended without a close-out, or when every outcome is not applicable.

API usage​

Prerequisites

After the environment variables are configured, the next step is to create a JSON payload. term_corr scores a whole trace. An inline trace is scored with POST /evaluate: send trace and omit span_id. A stored trace is scored with POST /runs/trace.

Shortname: term_corr

Default threshold: 80

Inputs (each object in data)

  • trace (list[object] required): An OpenInference-format trace — an ordered list of span dictionaries that share a trace_id and are linked by parent_id. The metric reads, among other fields:
    • Identity and nesting — context.span_id, parent_id, openinference.span.kind (LLM, TOOL, RETRIEVER, and GUARDRAIL can be the stop; AGENT wrappers are skipped).
    • Status — status.status_code. ERROR on the stop means the run failed. ERROR on a GUARDRAIL is a tripwire and is skipped.
    • LLM conversation — llm.input_messages.* (a non-empty system or user prompt is required when definition_of_done is omitted), llm.output_messages.* (close-out text, and whether the turn still requested tools).
    • Tool / retriever / guardrail payloads — tool.name, input.value / output.value. An action output can be the close-out.
    • Timing and tokens — start_time / end_time, and token counts when present. Extra work after the settle point is scored from these. When both are missing, the score falls back to the share of scored rows.

For annotated span/trace examples and the attribute map Aegis reads, see OpenInference spans and traces.

metric_args

  • definition_of_done (str, optional): Ground-truth success criteria as free text. A result that text forbids is replaced by its absence. When the key is omitted, empty, or whitespace-only, atomic outcomes are generated from the trace’s system and user prompts. A non-string value fails evaluation.

Evaluation metadata​

On successful evaluation that reaches the judge, the metric returns eval_metadata with:

  • outcomes (dict[int, str]): The atomic outcomes — each index mapped to its text.

When any outcome is still reachable or blocked, it also includes:

  • open_outcomes (list[dict]): Outcomes that are remaining or blocked, each with:
    • outcome (str): Outcome text.
    • state (str): remaining or blocked.
    • reason (str): Concise justification for that state.

A fully blocked task can still score 100 when nothing continued after it. Those blocked outcomes are still listed here.

When scored rows continued after the work was settled, it also includes:

  • extra_work (list[dict]): Those continuation rows. Each entry has:
    • index (int | str): Compact identity. A logged span keeps its integer index. A reconstructed turn is named by its step_id (for example 3/wave1).
    • kind (str, optional): Span kind, when recorded.
    • name (str, optional): Span or tool name, when recorded.
    • args_brief (str, optional): Truncated arguments, when recorded.
    • output_brief (str, optional): Truncated output, when recorded.
    • duration_ms (number, optional): Row duration, when recorded. A missing measurement is omitted, not sent as 0.
    • tokens (number, optional): Row token total, when recorded. A missing measurement is omitted, not sent as 0.

Early exits that never reach the judge (failed run, empty answer, sub-agent close-out, no criteria) return eval_metadata: null.

Example: inline trace

POST /evaluate. Send trace and omit span_id.

import json
import os

import requests
from dotenv import load_dotenv

load_dotenv(override=True)

_API_KEY = os.getenv("AEGIS_API_KEY")
_BASE_URL = os.getenv("AEGIS_API_BASE_URL")
_EVALUATE_URL = f"{_BASE_URL}/evaluate"


def post_evaluate(payload: dict) -> requests.Response:
"""POST JSON payload to single evaluation; returns the raw response."""
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {_API_KEY}",
}
return requests.post(
_EVALUATE_URL,
headers=headers,
data=json.dumps(payload),
)


if __name__ == "__main__":
# Minimal OpenInference-style trace (list of spans). Real traces include more.
trace = [
{
"name": "AgentRun",
"context": {
"trace_id": "0x3c25552ecfec75f0dfa5baad5a544c4c",
"span_id": "0x145e3c64b3b99a77",
},
"parent_id": None,
"start_time": "2026-07-08T11:07:57.720000Z",
"end_time": "2026-07-08T11:08:00.332983Z",
"status": {"status_code": "OK"},
"attributes": {"openinference.span.kind": "AGENT"},
},
{
"name": "Table Host",
"context": {
"trace_id": "0x3c25552ecfec75f0dfa5baad5a544c4c",
"span_id": "0x083b5fc1127d658a",
},
"parent_id": "0x145e3c64b3b99a77",
"start_time": "2026-07-08T11:07:57.725590Z",
"end_time": "2026-07-08T11:08:00.332983Z",
"status": {"status_code": "OK"},
"attributes": {"openinference.span.kind": "AGENT"},
},
{
"name": "response",
"context": {
"trace_id": "0x3c25552ecfec75f0dfa5baad5a544c4c",
"span_id": "0x64e5562a83068b87",
},
"parent_id": "0x083b5fc1127d658a",
"start_time": "2026-07-08T11:07:57.729073Z",
"end_time": "2026-07-08T11:07:59.573356Z",
"status": {"status_code": "OK"},
"attributes": {
"openinference.span.kind": "LLM",
"llm.input_messages.0.message.role": "system",
"llm.input_messages.0.message.content": (
"You are a dining assistant. Do not book a table."
),
"llm.input_messages.1.message.role": "user",
"llm.input_messages.1.message.content": (
"Find a table for 4 in Lisbon on 18 Nov, "
"prix fixe under $80. Do not reserve it."
),
"llm.tools.0.tool.json_schema": {
"type": "function",
"function": {
"name": "search_tables",
"parameters": {"type": "object"},
},
},
"llm.output_messages.0.message.tool_calls.0.tool_call.id": (
"call_search"
),
"llm.output_messages.0.message.tool_calls.0.tool_call.function.name": (
"search_tables"
),
},
},
{
"name": "search_tables",
"context": {
"trace_id": "0x3c25552ecfec75f0dfa5baad5a544c4c",
"span_id": "0x6c9868e6283f0ed1",
},
"parent_id": "0x083b5fc1127d658a",
"start_time": "2026-07-08T11:07:59.574350Z",
"end_time": "2026-07-08T11:07:59.589819Z",
"status": {"status_code": "OK"},
"attributes": {
"openinference.span.kind": "TOOL",
"tool.name": "search_tables",
"tool.call.id": "call_search",
"input.value": {
"city": "Lisbon",
"date": "18 Nov",
"party": 4,
},
"output.value": "tables: [{id: TB-7, price: 48}]",
},
},
{
"name": "response",
"context": {
"trace_id": "0x3c25552ecfec75f0dfa5baad5a544c4c",
"span_id": "0xbbbbbbbbbbbbbbbb",
},
"parent_id": "0x083b5fc1127d658a",
"start_time": "2026-07-08T11:07:59.610000Z",
"end_time": "2026-07-08T11:08:00.300000Z",
"status": {"status_code": "OK"},
"attributes": {
"openinference.span.kind": "LLM",
"llm.input_messages.0.message.role": "system",
"llm.input_messages.0.message.content": (
"You are a dining assistant. Do not book a table."
),
"llm.input_messages.1.message.role": "user",
"llm.input_messages.1.message.content": (
"Find a table for 4 in Lisbon on 18 Nov, "
"prix fixe under $80. Do not reserve it."
),
"llm.output_messages.0.message.role": "assistant",
"llm.output_messages.0.message.contents.0.message_content.type": (
"text"
),
"llm.output_messages.0.message.contents.0.message_content.text": (
"I found a matching Lisbon table at $48. I did not reserve it."
),
},
},
]

# Send trace and omit span_id.
payload = {
"metric_shortname": "term_corr",
"threshold": 80,
"model_slug": "o4-mini",
"trace": trace,
# Omit definition_of_done to generate atomic outcomes
# from system + user prompts in the trace instead.
"metric_args": {
"definition_of_done": (
"A matching table for 4 in Lisbon on 18 Nov, "
"with prix fixe under $80, was found. "
"No reservation was made."
),
},
}

response = post_evaluate(payload)
response.raise_for_status()
print(json.dumps(response.json(), indent=2))

Example: stored trace

POST /runs/trace. trace_id is the integer id of the stored trace. Omit spans.

import json
import os

import requests
from dotenv import load_dotenv

load_dotenv(override=True)

_API_KEY = os.getenv("AEGIS_API_KEY")
_BASE_URL = os.getenv("AEGIS_API_BASE_URL")
_TRACE_RUN_URL = f"{_BASE_URL}/runs/trace"


def post_trace_run(payload: dict) -> requests.Response:
"""POST JSON payload to a trace run; returns the raw response."""
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {_API_KEY}",
}
return requests.post(
_TRACE_RUN_URL,
headers=headers,
data=json.dumps(payload),
)


if __name__ == "__main__":
payload = {
"trace_id": 42,
"threshold": 80,
"model_slug": "o4-mini",
"is_blocking": True,
"selected_metrics": {
"term_corr": {
"threshold": 80,
# Omit definition_of_done to generate atomic outcomes
# from system + user prompts in the trace instead.
"metric_args": {
"definition_of_done": (
"A matching table for 4 in Lisbon on 18 Nov, "
"with prix fixe under $80, was found. "
"No reservation was made."
),
},
},
},
}

response = post_trace_run(payload)
response.raise_for_status()
print(json.dumps(response.json(), indent=2))