Skip to main content

Explainability SDK for tracing, graphing, and policy auditing of AI agents

Project description

AISquare Explainability SDK

Lightweight Python SDK for tracing, graphing, and policy auditing of AI agents. Captures execution traces from any Python agent (Agno, LangChain, plain Python) and delivers them to the AISquare Explainability Gateway.

Installation

pip install aisquare[explainability]

For Agno auto-instrumentation:

pip install aisquare[explainability,agno]

Quick start

import aisquare.explainability as sdk

# Reads EXPLAINABILITY_GATEWAY_URL and EXPLAINABILITY_API_KEY from environment
sdk.init_from_env(service_name="my-agent")

# Run your agent — Agno is auto-instrumented, all spans captured automatically
agent.print_response("...")

# IMPORTANT for short-lived scripts: flush ensures traces reach the gateway
# before the process exits. Long-running services don't need this.
sdk.flush()

What the SDK captures

The SDK collects two layers of signal:

Auto-instrumentation (zero-code): The AgnoAdapter installs openinference-instrumentation-agno, which automatically wraps every Agno agent run, LLM call, and tool invocation as an OTel span.

Manual tracers (governance-grade): Nine context-manager tracers you can add to any Python code — framework-agnostic:

Tracer Purpose
AgentRunTracer Wraps a full agent run as the root span
LLMCallTracer Records an LLM inference call with I/O and token counts
ToolCallTracer Records a tool invocation with parameters, result, and errors
RetrievalTracer Records a RAG retrieval with documents and scores
HumanInterventionTracer Records a human-in-the-loop review or correction
RoutingTracer Records a routing/delegation decision with selected and rejected paths
DecisionTracer Records a general decision point with options, selected, and rejected paths
PolicyGateTracer Records a policy-gate evaluation with the policies checked and the allow/deny outcome
MemoryTracer Records memory read/write operations

Decorators are also available: @trace_tool and @trace_retrieval.

Manual instrumentation (any framework)

import aisquare.explainability as sdk

sdk.init_from_env()

with sdk.AgentRunTracer(agent_name="MyAgent", run_id="abc-123") as run:
    run.set_input("User query")

    with sdk.LLMCallTracer(model="gpt-4o-mini", provider="openai") as llm:
        response = call_openai(...)
        llm.set_input_messages([{"role": "user", "content": "..."}])
        llm.set_output_messages([{"role": "assistant", "content": response}])
        llm.set_token_counts(prompt=100, completion=50)

    with sdk.RoutingTracer(decision_type="tool_selection") as rt:
        rt.set_selected("web_search", reason="Query requires fresh data")
        rt.set_rejected([{"name": "cached_search", "reason": "Cache is stale"}])

    run.set_output("Agent final answer")

sdk.flush()

Environment variables

Variable Description
EXPLAINABILITY_GATEWAY_URL Gateway base URL for trace ingest
EXPLAINABILITY_API_KEY API key for trace ingest

Diagnostics

The SDK ships a built-in health checker:

explainability-doctor

License

MIT

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

aisquare-1.0.5.tar.gz (439.8 kB view details)

Uploaded Source

Built Distribution

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

aisquare-1.0.5-py3-none-any.whl (211.9 kB view details)

Uploaded Python 3

File details

Details for the file aisquare-1.0.5.tar.gz.

File metadata

  • Download URL: aisquare-1.0.5.tar.gz
  • Upload date:
  • Size: 439.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aisquare-1.0.5.tar.gz
Algorithm Hash digest
SHA256 b18fc0075007bad431efbdef64b45f343f1adc28fe80de49d8b0e945c3d9aca9
MD5 ccd181bf2ad31c8d7c3caac7a6e7e952
BLAKE2b-256 e4542e06339fc5d32a9e7a6fb61352ca7e258a352f7423066eb9a9ac2b8b59f2

See more details on using hashes here.

File details

Details for the file aisquare-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: aisquare-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 211.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aisquare-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 bed32ac5f5d8424dae1e9e00a15fa5eeb5c5fcdb04ca357bcbc67be3936f9ea5
MD5 b34c04942d92b739e3d2e7cd809879c5
BLAKE2b-256 e1e699dcb2f9df83eeffc2a20f6dee80eb804cd3e419f07afbec317388eab69f

See more details on using hashes here.

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