Skip to content

latent.agents.eval.items

Run an agent on eval items, one result per item, with no eval extra.

run_items runs the agent on each EvalItem and awaits a callback with each ItemResult as it completes: it retries a failed row, grades a max-iterations give-up as a non-answer, and stops only on auth or quota errors. It needs only latent's core dependencies (no Prefect, MLflow or pandas), so it runs inside an agent image installed without latent[eval].

latent.flows.agent_inference_flow builds its DataFrame flows on the same single-question inference and result-row shape defined here.

Classes

EvalItem

EvalItem(key: str, question: str, row: Mapping[str, Any] = dict())

One question for run_items.

key identifies the item to the caller and becomes the inference row's id. row holds what the agent factory needs to build an agent for this item (a channel, a persona); its entries are carried onto the inference row as extra columns.

ItemResult

ItemResult(item: EvalItem, status: ItemStatus, attempts: int, attempt_latencies_ms: tuple[float, ...], inference: dict[str, Any])

What run_items reports for one item.

status:

  • "ok": the agent finished without an error event.
  • "max_iterations": the agent gave up at its iteration limit (an Error event with code "max_iterations"). Grade it as a non-answer. It is never retried.
  • "errored": every attempt raised, timed out or ended in an error event. Do not grade it.

attempts counts agent attempts, attempt_latencies_ms holds one wall-clock duration per attempt, and inference is the final attempt's row in run_agent_inference's shape: output, tool_calls, token counts, and error, the final attempt's error or None.

Functions

run_items

run_items(make_agent: Callable[[EvalItem], Any], items: Sequence[EvalItem], concurrency: int, attempt_timeout_s: float, retries: int, on_result: Callable[[ItemResult], Awaitable[None]]) -> None

Run the agent on each item and report each result as it completes.

A plain async function: no Prefect import and no result cache, so it is safe inside another orchestrator, and a restarted caller skips the items it already recorded by passing only the rest.

Each attempt builds a fresh agent with make_agent(item) (concurrent items never share agent state) and runs under attempt_timeout_s, agent construction included. An attempt that raises, times out, or ends in an Error event is retried up to retries more times. An Error with code "max_iterations" ends the item at once with status "max_iterations": a retry would bill the same calls for the same give-up. ItemResult describes the statuses.

on_result is awaited once per item, inside the item's concurrency slot: at most concurrency items are running or being reported.

The run stops on the first auth or quota error, re-raised as litellm raised it: AuthenticationError, PermissionDeniedError, BudgetExceededError, or RateLimitError with rate_limit_type == "budget". Every later item would fail the same way, so the items in flight are cancelled and none of them is reported. A vendor 429 (throttling) is not quota: it is a row error and is retried. An exception from on_result stops the run the same way.

Raises: ValueError: concurrency < 1, retries < 0, or an attempt_timeout_s that is not a positive finite number.

Attributes

ItemStatus