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.4.tar.gz (416.7 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.4-py3-none-any.whl (199.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aisquare-1.0.4.tar.gz
  • Upload date:
  • Size: 416.7 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.4.tar.gz
Algorithm Hash digest
SHA256 bec6f00083f9f4c9e584fd89b7cae4825fe57313cf1ae681c5acd9d1154398f2
MD5 85900fdcec657a801ee0806f72284e18
BLAKE2b-256 20fd20c4de4ffbfab4098d77f2dff9524cc0881a1712065d6271d5b7bbb3512d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aisquare-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 199.6 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5936ba5dcd0889216c6d25332ff12a37e9c53a6f50fba4cbb2404c90ec9aceec
MD5 917d57e0a094a65274f3d2a3f0456de8
BLAKE2b-256 b260c9caa8b55c1ccf78cc7dcc91af920f45cb886ee0fd0d55a6716e3d7c1cf9

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