Client library for Agent In The Loop confidence evaluation API
Project description
agent-in-the-loop
A lightweight Python client for the Agent In The Loop (AITL) confidence evaluation API. Send your LLM agent's execution context to the AITL backend and receive a structured confidence score — with optional OpenTelemetry trace ID auto-detection.
Installation
pip install agent-in-the-loop
Requires Python 3.10+.
Quick Start
from agent_in_the_loop import evaluate_confidence
result = evaluate_confidence(
context="The agent searched the web, found 3 sources, and summarised them.",
trace_id="your-trace-id-here",
endpoint="https://your-aitl-backend.example.com",
api_key="your-api-key",
)
print(result.score) # int, 1-10
print(result.explanation) # str, human-readable reasoning
Environment Variables
Instead of passing endpoint and api_key on every call, set them as environment variables:
| Variable | Description | Default |
|---|---|---|
AGENT_IN_THE_LOOP_ENDPOINT |
Base URL of the AITL backend | http://localhost:6006 |
AGENT_IN_THE_LOOP_API_KEY |
Bearer token for authentication | (required) |
export AGENT_IN_THE_LOOP_ENDPOINT=https://your-aitl-backend.example.com
export AGENT_IN_THE_LOOP_API_KEY=your-api-key
from agent_in_the_loop import evaluate_confidence
result = evaluate_confidence(
context="Agent context here...",
trace_id="your-trace-id",
)
OpenTelemetry Integration
If your application already uses OpenTelemetry tracing, TraceIdCapture automatically captures the current trace ID so you never need to pass it manually.
from opentelemetry.sdk.trace import TracerProvider
from agent_in_the_loop import TraceIdCapture, evaluate_confidence
# Register the processor once at startup
provider = TracerProvider()
provider.add_span_processor(TraceIdCapture())
tracer = provider.get_tracer("my-agent")
with tracer.start_as_current_span("agent-run"):
# trace_id is captured automatically — no need to pass it
result = evaluate_confidence(
context="Agent finished reasoning step...",
)
print(result.score)
TraceIdCapture implements the OpenTelemetry SpanProcessor interface and stores the active trace ID in a ContextVar, providing full thread-safety and async-safety.
API Reference
evaluate_confidence
evaluate_confidence(
context: str,
trace_id: str | None = None,
*,
endpoint: str | None = None,
api_key: str | None = None,
timeout: float = 30.0,
) -> AgentLoopResult
| Parameter | Type | Description |
|---|---|---|
context |
str |
Conversation and graph flow to evaluate |
trace_id |
str | None |
Trace ID for the agent run. Auto-detected when TraceIdCapture is registered |
endpoint |
str | None |
Backend base URL. Falls back to AGENT_IN_THE_LOOP_ENDPOINT |
api_key |
str | None |
Bearer token. Falls back to AGENT_IN_THE_LOOP_API_KEY |
timeout |
float |
HTTP request timeout in seconds (default 30.0) |
Raises:
ValueError— iftrace_idcannot be resolved orapi_keyis missingrequests.HTTPError— on non-2xx HTTP responses
AgentLoopResult
A frozen dataclass with two fields:
| Field | Type | Description |
|---|---|---|
score |
int |
Confidence score from 1 (low) to 10 (high) |
explanation |
str |
Human-readable explanation of the score |
TraceIdCapture
An OpenTelemetry SpanProcessor that captures the trace ID on span start. Register it with your TracerProvider as shown above.
Running Tests
pip install -e ".[test]"
pytest
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Commit your changes (
git commit -m "Add my feature") - Push to the branch (
git push origin feature/my-feature) - Open a Pull Request
License
MIT — see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agent_in_the_loop-0.2.0.tar.gz.
File metadata
- Download URL: agent_in_the_loop-0.2.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48a65710ded99d42efb0e33dc62360cc7be6d8d9fd252e6698ac5414896f2cf1
|
|
| MD5 |
51b9f15bfec0670f552808eaf2cff0ac
|
|
| BLAKE2b-256 |
e97afae17dba0c59f5020a0865d5d201c6b169149dcf18804859658801193bf4
|
Provenance
The following attestation bundles were made for agent_in_the_loop-0.2.0.tar.gz:
Publisher:
publish.yml on benarush/AITL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_in_the_loop-0.2.0.tar.gz -
Subject digest:
48a65710ded99d42efb0e33dc62360cc7be6d8d9fd252e6698ac5414896f2cf1 - Sigstore transparency entry: 1429568130
- Sigstore integration time:
-
Permalink:
benarush/AITL@a9039defddc33e2795b0baf425b6736c79f16de6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/benarush
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a9039defddc33e2795b0baf425b6736c79f16de6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file agent_in_the_loop-0.2.0-py3-none-any.whl.
File metadata
- Download URL: agent_in_the_loop-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f2a4f06e0c8ae277fb8ddeef5d8179d554b1ffbf4d073d61d92f472c84cb8a6
|
|
| MD5 |
e7edb9d429cd22d4d9ec8e054ed0d8f3
|
|
| BLAKE2b-256 |
cfef1d52dc48dc3fa82af2595c29e6ec4d7817a64f485c0a27aeeccaddf86574
|
Provenance
The following attestation bundles were made for agent_in_the_loop-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on benarush/AITL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_in_the_loop-0.2.0-py3-none-any.whl -
Subject digest:
5f2a4f06e0c8ae277fb8ddeef5d8179d554b1ffbf4d073d61d92f472c84cb8a6 - Sigstore transparency entry: 1429568149
- Sigstore integration time:
-
Permalink:
benarush/AITL@a9039defddc33e2795b0baf425b6736c79f16de6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/benarush
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a9039defddc33e2795b0baf425b6736c79f16de6 -
Trigger Event:
push
-
Statement type: