Skip to main content

agentradar-sdk — Python SDK

PyPI version Python 3.10+ License: MIT

AI agent observability SDK — track runs, LLM executions, tool calls, errors, latency, and performance metrics in your AgentRadar dashboard.


Installation

pip install agentradar-sdk

Quick Start

from agentradar import AgentRadar

ar = AgentRadar(
    api_key="ar_live_your_key_here",
    # endpoint defaults to "https://api.agent-radar.in"
)

with ar.start_run(
    agent_name="CustomerSupportAgent",
    input={"question": "Where is my order?"},
) as run:
    # 1. Log an LLM call
    run.log_llm_call(
        model_name="gpt-4o",
        provider="openai",
        duration_ms=850.0,
        token_usage={"prompt_tokens": 42, "completion_tokens": 15},
    )

    # 2. Track a tool call (with automatic duration measurement)
    with run.track_tool("search_orders", input={"order_id": "123"}) as tool:
        tool.set_output({"status": "shipped", "carrier": "FedEx"})

The run is automatically marked success on clean exit, or failed if an exception escapes the with block.


API Key Configuration

Get your API key from the AgentRadar dashboard at https://agent-radar.in under Settings → API Keys. Keys are prefixed with ar_live_.

For interactive OpenAPI/Swagger reference, visit https://api.agent-radar.in/docs.

# Option 1: Pass directly
ar = AgentRadar(api_key="ar_live_...")

# Option 2: Environment variable (AGENTRADAR_API_KEY or AR_API_KEY)
# export AGENTRADAR_API_KEY=ar_live_...
ar = AgentRadar()

Asynchronous Agents (AsyncAgentRadar)

For async agent frameworks (LangChain, AutoGen, CrewAI, FastAPI):

import asyncio
from agentradar import AsyncAgentRadar

async def main():
    async with AsyncAgentRadar(api_key="ar_live_...") as ar:
        async with ar.start_run("ResearchAgent", input={"topic": "Agent observability"}) as run:
            run.log_llm_call(model_name="claude-3-5-sonnet", provider="anthropic", duration_ms=450.0)
            with run.track_tool("web_search", input={"q": "Observability"}) as tool:
                tool.set_output({"count": 10})

asyncio.run(main())

Tracking Tool Calls & LLM Calls

Convenience Context Managers

Tool Calls (run.track_tool)

Automatically starts timer, logs tool_call, catches exceptions (logging error), and logs tool_result with duration:

with run.track_tool("database_query", input={"user_id": 42}) as tool:
    result = db.query(user_id=42)
    tool.set_output(result)

LLM Reasoning (run.track_llm)

with run.track_llm(model_name="gpt-4o", provider="openai", input={"prompt": "Summarize"}) as llm:
    completion = openai_client.chat.completions.create(...)
    llm.set_result(
        output={"text": completion.choices[0].message.content},
        token_usage={"prompt_tokens": 100, "completion_tokens": 50},
    )

Manual Logging Helpers

LLM Call

run.log_llm_call(
    model_name="claude-3-5-sonnet",
    provider="anthropic",
    input={"prompt": "..."},
    output={"response": "..."},
    duration_ms=1200.0,
    token_usage={"prompt_tokens": 100, "completion_tokens": 50},
)

Tool Call & Result

run.log_tool_call(name="web_search", input={"query": "latest AI news"})
run.log_tool_result(name="web_search", output={"results": [...]}, duration_ms=350.0)

Error Logging

run.log_error(
    error_type="ToolTimeoutError",
    error_message="Tool timed out after 30s",
    name="web_search",
)

Custom Events

run.log_custom_event(
    name="workflow_checkpoint",
    metadata={"step": 2, "state": "validating"},
)

Manual Run Lifecycle (Without Context Manager)

If you need manual control over run boundaries:

run = ar.start_run(agent_name="PipelineAgent", input={"batch_id": 99})
run.start()

# Do agent work...
run.log_tool_call(name="process_item")

run.finish(status="success")  # or status="failed"
ar.flush()

Single Event Ingestion & Health Check

# Check backend health
status = ar.check_health()
print(f"Backend status: {status.status}, version: {status.version}")

# Direct single-event ingestion
ar.send_event({
    "event_id": "...",
    "run_id": "...",
    "agent_name": "...",
    "event_type": "custom",
    "timestamp": "2026-10-16T12:00:00Z"
})

Configuration Options

Parameter Default Environment Variable Description
api_key "" AGENTRADAR_API_KEY, AR_API_KEY Your project API key (ar_live_...)
endpoint https://api.agent-radar.in AGENTRADAR_ENDPOINT, AR_ENDPOINT AgentRadar platform backend URL
auth_token None AGENTRADAR_AUTH_TOKEN, AR_AUTH_TOKEN Optional Bearer JWT for platform API access
timeout 10.0 — HTTP request timeout in seconds
max_retries 3 — Max retries for transient 5xx/network errors
batch_size 50 — Events per batch (auto-flush trigger)
enabled True — Set False to disable all telemetry
include_payloads False — Send input/output content (may contain PII)

Privacy & Payload Gating

By default, input and output payloads are not sent to protect sensitive user data and credentials.

# Enable payload capture (only if your data is safe to transmit)
ar = AgentRadar(api_key="ar_live_...", include_payloads=True)

Error Handling & Resilience

The SDK automatically retries on transient network errors and server errors (500, 502, 503, 504) with exponential backoff:

from agentradar.exceptions import AuthenticationError, APIError, NetworkError

try:
    ar.flush()
except AuthenticationError:
    print("Invalid or revoked API key")
except APIError as e:
    print(f"API error ({e.status_code}): {e}")
except NetworkError:
    print("Could not reach AgentRadar backend after retries")

Local Development & Testing

git clone https://github.com/GoodGuyAdy/AgentRadar
cd AgentRadar
pip install -e ".[dev]"
pytest

License

MIT — see LICENSE.

Metadata

Release files for agentradar-sdk 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agentradar-sdk 0.1.1
File Size Uploaded Provenance
agentradar_sdk-0.1.1.tar.gz 18.1 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for agentradar-sdk 0.1.1
File Interpreter ABI Platform
agentradar_sdk-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 34.3 kB

Release files / agentradar_sdk-0.1.1.tar.gz

Download URL agentradar_sdk-0.1.1.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fa06ccd49d8d6cbe0eefe5ecdacf4674ef1b93ae62ead727aa14405cb15dbccd
BLAKE2b-256 checksum
How to use checksums
badc82921fe746cc546f3d50257398eb5fd33f1170012159604a0af8cd28fb93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Release files / agentradar_sdk-0.1.1-py3-none-any.whl

Download URL agentradar_sdk-0.1.1-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8bb34511a6fa11ff300ebcd70e62e53caeebf65a84b0f08b90a0db91ad114ae4
BLAKE2b-256 checksum
How to use checksums
b4ea6fb3626cc9ecca638581e5ed506f4358d2bcc5f5f4e1a9b1428cbe72435a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

Security for agentradar-sdk 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for agentradar_sdk-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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