Skip to main content

AgentX

The top-level client. Create one per process.

Constructor

Class methods

Attributes


Tracer

Accessed via client.tracer. Handles both tracing and CI/CD evaluation.

trace()

Returns a _TraceSpan that works as a decorator or context manager.

flush()

Blocks until all queued traces have been delivered. Call before process exit in scripts or one-shot jobs.

use_span()

Makes span (created on another thread) the active span for the duration of the block, on the calling thread. The active-span stack is thread-local, so a span opened with tracer.trace(...) on the main thread isn’t automatically visible inside a ThreadPoolExecutor worker (or any other thread). Wrap the worker’s body in use_span() to attach its LLM and tool calls to the parent span instead of starting an independent trace.
Safe to call concurrently from multiple threads for the same span: each thread pushes and pops on its own stack.

run_eval()

High-level CI/CD evaluation: creates a run, calls agent_fn for every test case, submits results, finalizes, and returns the gate decision. Raises CIGateFailure (containing the CIRunResult) when fail_on_gate=True and the gate is "fail".

create_ci_run()

submit_result()

finalize_ci_run()

get_ci_run()

evaluate_trace()

Score a previously-recorded trace against a dataset. The agent is not re-run. Returns { run_id, trace_id, rating, justification, status }. trace_id comes from a prior tracer.trace(..., sync=True) call’s span.trace_id.

_TraceSpan

Returned by tracer.trace(). Can be used as a decorator or context manager.

Attributes

Methods

add_tool_call()

Records a tool call made during this span. Safe to call multiple times.

set_error()

Marks this span as failed. Takes precedence over any exception automatically caught by __exit__.

Usage patterns


CI/CD Dataclasses

CIRun

Returned by create_ci_run().

CITestCase

CIQuestionScore

Returned by submit_result().

CIRunResult

Returned by finalize_ci_run() and run_eval().

CIRunStatus

Returned by get_ci_run().

ThresholdViolation


Exceptions

All exceptions inherit from AgentXError.

CIGateFailure


Environment variables