Skip to main content

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]

For Google ADK auto-instrumentation:

pip install "aisquare[adk]"

Quick start

Every trace needs an agent identity on its root span — agent_name is the key the gateway routes traces by. Name your agent explicitly and pre-register it:

# .env: EXPLAINABILITY_GATEWAY_URL, EXPLAINABILITY_API_KEY,
# EXPLAINABILITY_AGENTS=support-bot   <- pre-registers; must equal agent_name below
import aisquare.explainability as sdk

sdk.init_from_env()

with sdk.AgentRunTracer(agent_name="support-bot"):
    with sdk.LLMCallTracer(model="gpt-4o", provider="openai") as llm:
        ...  # your agent logic — nested spans inherit the run's routing identity

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

Using a framework instead of manual tracers? The identity contract is the same — the agent's explicit name becomes agent.name on the root span: Agno Agent(name="support-bot"), LangChain metadata={"agent_name": "support-bot"}, or GovernedAgent(..., agent_name="support-bot").

What the SDK captures

The SDK collects two layers of signal:

Auto-instrumentation (zero tracing code): The AgnoAdapter installs openinference-instrumentation-agno, which automatically wraps every Agno agent run, LLM call, and tool invocation as an OTel span. The Agno Agent(name=...) becomes the trace's routing identity — always name your agents.

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)

Leaf tracers (LLM, tool, routing, ...) always run nested inside an AgentRunTracer — its agent_name is stamped as agent.name on the root span, the attribute the gateway routes the trace by. A trace with no agent identity is rejected at ingest (409 no_agent_identity).

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
EXPLAINABILITY_AGENTS Comma-separated agent names registered at init; must match your AgentRunTracer / framework agent names
AISQUARE_AGENT_NAME The SDK's default agent identity, in two roles: the identity used for policy checks, and (since 1.0.6) the fallback trace identity stamped on spans that would otherwise be rootless so the trace still routes. Keep it equal to your agent_name.

Multiple agents: name each agent in code (AgentRunTracer(agent_name=...) or the framework equivalent) — that per-run name is what routes each trace. AISQUARE_AGENT_NAME holds a single name and is a single-agent convenience only; it cannot distinguish between agents in the same process.

Diagnostics

The SDK ships a built-in health checker:

explainability-doctor

Its agent_identity check warns when no agent identity is configured (the classic precondition for 409 no_agent_identity ingest rejections), and its delivery_backlog check surfaces traces stuck in the local inbox after gateway 409s — with the remediation for each rejection code.

License

MIT

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.1.0.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

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

aisquare-1.1.0-py3-none-any.whl (335.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aisquare-1.1.0.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for aisquare-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ac0a85f126a17f400a6cea0fe45c10925be378f0ed9076ed2dd9efa2caee67b3
MD5 2774f7962e0d1af4aae774c4ffbe515c
BLAKE2b-256 0e7d7929bfe06ab4bb5b39e10f7469c3916278923c087149e055202df734491f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aisquare-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 335.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for aisquare-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ffd64ce27f74c0b4f0e043a4bb1f0379410bb133512d380db40c9e965aaaf7c4
MD5 7c5680587ba0de9881785ee5a5c30185
BLAKE2b-256 b837155a156d870678828d57981328f22ebc81a1c39d58129bcb94f9ef51b524

See more details on using hashes here.

Release history Release notifications | RSS feed

1.2.0

2 files

This release

1.1.0 This release

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page