Skip to main content

AgentGuard Python SDK

PyPI version License

Python SDK for AgentGuard — a real-time security monitoring, governance, and synchronous tool-call blocking platform for AI coding agents.

Features

  • OpenTelemetry Tracing — thread-safe singleton tracer with OTLP HTTP exporter
  • Auto-Instrumentation — enable_instrumentors() automatically traces OpenAI SDK calls
  • Span Helpers — manual and context-manager APIs with session/run/task context
  • Agent Scope Tracking — SpanContext ties spans to session_id, run_id, task_id

Installation

pip install timeplus-agentguard

The distribution is named timeplus-agentguard; the import name is agentguard.

CLI Tools

Organize and govern AI coding agents:

./agentguard_cli - OpenTelemetry tracing for sessions and tasks

  • session_start - Start a new agent session
    ./agentguard_cli session_start result session-123
    
  • session_end - End a session with status
    ./agentguard_cli session_end session-123 depleted incomplete
    
  • session_trace - Create trace for an existing session
    ./agentguard_cli session_trace trace-id-456 resource-789
    

Attributes

Sessions get extended with these attributes:

  • session.id - The session ID
  • session.status - Final evaluation result
  • run.id - Associated code run ID
  • task.id - Associated specific code task ID

Configuration

Requires Python 3.10+.

Quick Start

from agentguard import AgentGuard

# Create the singleton tracer
ag = AgentGuard(
    agent_id="claude-code-1",
    deployment_id="prod",
    otlp_endpoint="http://localhost:4318",
)

# Enable auto-instrumentation for OpenAI SDK
ag.enable_instrumentors()

# Manual span (must call .end())
span = ag.start_span(
    "session_start",
    session_id="ses_abc123",
    run_id="run_xyz",
    task_id="task_001",
)
# ... do work ...
span.end()

# Context-manager span (auto-ends, parent automatically set from OTel context)
with ag.start_as_current_span(
    "tool_call",
    session_id="ses_abc123",
    run_id="run_xyz",
    task_id="task_001",
):
    # ... do work ...
    pass

# Flush and shutdown
ag.shutdown()

Context Manager with Explicit Parent

from agentguard import AgentGuard
from opentelemetry.trace import set_span_in_context
from opentelemetry.context import get_current

ag = AgentGuard()

with ag.start_as_current_span("parent") as parent:
    # Set explicit parent context for child
    ctx = set_span_in_context(parent, get_current())
    with ag.start_as_current_span("child", context=ctx) as child:
        pass

Configuration

Parameter Env Var Default
agent_id AGENTGUARD_AGENT_ID hostname
deployment_id AGENTGUARD_DEPLOYMENT_ID "local"
deployment_name AGENTGUARD_DEPLOYMENT_NAME "Local Dev"
otlp_endpoint OTEL_EXPORTER_OTLP_ENDPOINT None (uses OTel default)

Parameter values take priority over environment variables.

Documentation

Development

git clone https://github.com/timeplus-io/agentguard
cd sdk/python
uv sync --dev
ruff check src/ tests/
pytest

License

Apache 2.0

Metadata

Release files for timeplus-agentguard 0.3.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 timeplus-agentguard 0.3.1
File Size Uploaded Provenance Actions
timeplus_agentguard-0.3.1.tar.gz 16.1 kB With provenance Details for timeplus_agentguard-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for timeplus-agentguard 0.3.1
File Interpreter ABI Platform Actions
timeplus_agentguard-0.3.1-py3-none-any.whl Python 3 none any Details for timeplus_agentguard-0.3.1-py3-none-any.whl

Total release size: 23.8 kB

Release files / timeplus_agentguard-0.3.1.tar.gz

Download URL timeplus_agentguard-0.3.1.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
905ff882829e322261f9044c103fe994c7ec63ffbbbde4fe64620e57d88c01f9
BLAKE2b-256 checksum
How to use checksums
a2b779725643a63ce850765bf5d118bf37f917853db18d1fcc8a1c6845b56a46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Release files / timeplus_agentguard-0.3.1-py3-none-any.whl

Download URL timeplus_agentguard-0.3.1-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62e6f9915a8c94f86ef1eced8ecfe97aad74780471be91ac9bdc7497321c26c1
BLAKE2b-256 checksum
How to use checksums
26aa850c42f8b07ea194779317cab7d34105162c784627028db32f2c739ac3dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Security for timeplus-agentguard 0.3.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for timeplus_agentguard-0.3.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 Nov 26, 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files Full provenance

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