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.0

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.0
File Size Uploaded Provenance Actions
timeplus_agentguard-0.3.0.tar.gz 15.7 kB With provenance Details for timeplus_agentguard-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 23.2 kB

Release files / timeplus_agentguard-0.3.0.tar.gz

Download URL timeplus_agentguard-0.3.0.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
670bd50ab0c040d70b4b0ae8c48c8f27b7da54d2ad717c3dbff2f68a1f49b339
BLAKE2b-256 checksum
How to use checksums
9f6388d4020780e5c15553d2aed57281ab836b3d1b62275dc68e56094a6560cb
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.0-py3-none-any.whl

Download URL timeplus_agentguard-0.3.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d985b38fee0109e20d2c10427ec463f64f2baeee7a32004c66fd8bc579e2e949
BLAKE2b-256 checksum
How to use checksums
297e4fae06f5a9f3ee1c74154d50ec8ff46bc75fe778d8197240a6d52e2425c8
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.0

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.0.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.0 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