Skip to main content

Client library for Agent In The Loop confidence evaluation API

Project description

agent-in-the-loop

PyPI version Python License: MIT CI

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 — if trace_id cannot be resolved or api_key is missing
  • requests.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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-feature)
  3. Commit your changes (git commit -m "Add my feature")
  4. Push to the branch (git push origin feature/my-feature)
  5. 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

agent_in_the_loop-0.2.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agent_in_the_loop-0.2.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

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

Hashes for agent_in_the_loop-0.2.0.tar.gz
Algorithm Hash digest
SHA256 48a65710ded99d42efb0e33dc62360cc7be6d8d9fd252e6698ac5414896f2cf1
MD5 51b9f15bfec0670f552808eaf2cff0ac
BLAKE2b-256 e97afae17dba0c59f5020a0865d5d201c6b169149dcf18804859658801193bf4

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_in_the_loop-0.2.0.tar.gz:

Publisher: publish.yml on benarush/AITL

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agent_in_the_loop-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agent_in_the_loop-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f2a4f06e0c8ae277fb8ddeef5d8179d554b1ffbf4d073d61d92f472c84cb8a6
MD5 e7edb9d429cd22d4d9ec8e054ed0d8f3
BLAKE2b-256 cfef1d52dc48dc3fa82af2595c29e6ec4d7817a64f485c0a27aeeccaddf86574

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page