AgentX
The top-level client. Create one per process.
Constructor
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | AGENTX_API_KEY env var | Workspace API key |
base_url | str | AGENTX_API_BASE_URL or SDK default | Override API base URL (self-hosted) |
workspace_id | str | AGENTX_WORKSPACE_ID env var | Explicit workspace ID — required when the API key belongs to a different user than the workspace being targeted |
Class methods
| Method | Returns | Description |
|---|---|---|
AgentX.from_env() | AgentX | Construct from AGENTX_API_KEY environment variable |
Attributes
| Attribute | Type | Description |
|---|---|---|
client.tracer | Tracer | Production tracer and CI/CD evaluation |
client.evaluations | EvaluationsRunner | Dataset-driven evaluation runner |
Tracer
Accessed via client.tracer. Handles both production tracing and CI/CD evaluation.
trace()
_TraceSpan that works as a decorator or context manager.
| Parameter | Description |
|---|---|
name | Agent or operation label shown in the UI |
input | Initial input (context manager only; overrides captured function args) |
metadata | Arbitrary key-value metadata (not indexed, max 16 KB) |
framework | "langchain", "crewai", "openai-agents", "anthropic", or custom |
model | LLM model name, e.g. "gpt-4o" |
session_id | Groups traces from the same session or conversation thread |
flush()
run_eval()
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()
{ run_id, trace_id, rating, justification, status }.
_TraceSpan
Returned by tracer.trace(). Can be used as a decorator or context manager.
Attributes
| Attribute | Type | Description |
|---|---|---|
span.input | Any | Agent input. Assign in context manager to override captured args. |
span.output | Any | Agent output. Must be set manually in context manager mode. |
span.tool_calls | list | Accumulated tool calls. Append with add_tool_call(). |
Methods
add_tool_call()
set_error()
__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 fromAgentXError.
| Exception | When raised |
|---|---|
AgentXError | Base class for all SDK errors |
AgentXAuthError | Invalid or missing API key |
AgentXAPIError | Unexpected API error. Has .status_code: int | None attribute. |
DatasetNotFound | Dataset ID does not exist or is not accessible |
CINotEnabled | Dataset exists but ci.enabled is False |
CIRunExpired | CI run was not finalized within 2 hours |
CIGateFailure | Gate is "fail" and fail_on_gate=True. Has .result: CIRunResult attribute. |
CIGateFailure
Environment variables
| Variable | Description |
|---|---|
AGENTX_API_KEY | Workspace API key (required) |
AGENTX_API_BASE_URL | Override API base URL for self-hosted deployments |
AGENTX_WORKSPACE_ID | Explicit workspace ID — injected into every request automatically |

