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. Attach a callback to your LangChain / LangGraph run, then get a structured confidence score for the whole agent run — no manual context or trace-ID wiring required.
Installation
pip install "agent-in-the-loop[langchain]"
The langchain extra is required because agent runs are captured via a LangChain callback handler (get_agent_guard). Requires Python 3.9+.
Quick Start
from agent_in_the_loop import get_agent_guard, evaluate_confidence
# agent_name must be a stable, unique name for this agent graph — the
# backend uses it to track the graph's network profile across runs.
guard = get_agent_guard("research-agent")
# Attach the guard to your LangGraph / LangChain invocation
graph.invoke(inputs, config={"callbacks": [guard]})
# context, trace_id, and agent_name are all picked up automatically from
# the guard above — nothing else to pass in.
result = evaluate_confidence(api_key="your-api-key")
print(result.score) # int, 1-10
print(result.explanation) # str, human-readable reasoning
Environment Variables
The SDK always talks to the managed AITL backend at https://api.trellar.io — this is fixed and cannot be overridden via an environment variable or function argument.
Instead of passing api_key on every call, set it as an environment variable:
| Variable | Description | Default |
|---|---|---|
AGENT_IN_THE_LOOP_API_KEY |
Bearer token for authentication | (required) |
export AGENT_IN_THE_LOOP_API_KEY=your-api-key
from agent_in_the_loop import get_agent_guard, evaluate_confidence
guard = get_agent_guard("research-agent")
graph.invoke(inputs, config={"callbacks": [guard]})
result = evaluate_confidence()
How It Works
get_agent_guard(agent_name) returns a LangChain callback handler that:
- Records every LLM, tool, and chain/graph lifecycle event fired during the run (
on_llm_start,on_tool_end,on_chain_start, etc.), in order. - Captures the root run's
run_idas thetrace_idfor the whole graph. - Registers itself in a
ContextVaras the "active" guard for the current thread/async task, soevaluate_confidence()can find it automatically — no need to pass it around.
Once the graph run finishes, calling evaluate_confidence() sends the accumulated events, trace ID, and agent name to the AITL backend and returns a confidence score.
Different graphs in the same codebase must use different agent_name values.
API Reference
get_agent_guard
get_agent_guard(agent_name: str) -> BaseCallbackHandler
| Parameter | Type | Description |
|---|---|---|
agent_name |
str |
Stable, unique name identifying this agent graph (e.g. "research-agent") |
Returns a LangChain callback handler bound to agent_name. Pass it to graph.invoke(..., config={"callbacks": [guard]}).
Raises:
ValueError— ifagent_nameis empty or blank
evaluate_confidence
evaluate_confidence(
*,
api_key: str | None = None,
timeout: float = 30.0,
) -> AgentLoopResult
| Parameter | Type | Description |
|---|---|---|
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) |
context, trace_id, and agent_name are all resolved automatically from the active guard created by get_agent_guard — there is no way to pass them manually. Requests are always sent to the fixed backend domain (https://api.trellar.io); there is no way for callers to redirect them elsewhere.
Raises:
ValueError— if no active guard is found, itstrace_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 |
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
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.3.tar.gz.
File metadata
- Download URL: agent_in_the_loop-0.2.3.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
867b41053bc766db5403062f123f0adcf0d63724a4ebd00a72b336720caba829
|
|
| MD5 |
0361ae27e2710c950d5cbde0af3ad78d
|
|
| BLAKE2b-256 |
028bd2e979d4b8c628c71581badbb53b5d1070617ca43e1ac0d8bb4cfa505d20
|
Provenance
The following attestation bundles were made for agent_in_the_loop-0.2.3.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.3.tar.gz -
Subject digest:
867b41053bc766db5403062f123f0adcf0d63724a4ebd00a72b336720caba829 - Sigstore transparency entry: 2176387854
- Sigstore integration time:
-
Permalink:
benarush/AITL@57b63042d1c4b9b58323fdf82fd484bdd0174d17 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/benarush
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@57b63042d1c4b9b58323fdf82fd484bdd0174d17 -
Trigger Event:
push
-
Statement type:
File details
Details for the file agent_in_the_loop-0.2.3-py3-none-any.whl.
File metadata
- Download URL: agent_in_the_loop-0.2.3-py3-none-any.whl
- Upload date:
- Size: 13.9 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 |
73ad80f313d90c2c38d4a576800a848d0c5c75394e1382d2efb20598729a8d84
|
|
| MD5 |
1489028af9bc3e90b082f84442f6b53f
|
|
| BLAKE2b-256 |
15152bcdd3bed2b25ce3680dd19ae768dc85e2104c9087dbc64dfe56c995bec3
|
Provenance
The following attestation bundles were made for agent_in_the_loop-0.2.3-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.3-py3-none-any.whl -
Subject digest:
73ad80f313d90c2c38d4a576800a848d0c5c75394e1382d2efb20598729a8d84 - Sigstore transparency entry: 2176388259
- Sigstore integration time:
-
Permalink:
benarush/AITL@57b63042d1c4b9b58323fdf82fd484bdd0174d17 -
Branch / Tag:
refs/tags/v0.2.3 - Owner: https://github.com/benarush
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@57b63042d1c4b9b58323fdf82fd484bdd0174d17 -
Trigger Event:
push
-
Statement type: