Skip to main content

Lightweight observability and evaluation primitives for multi-agent systems

Project description

AgentGuard SDK (Python)

PyPI License: MIT

Lightweight, zero-dependency observability for multi-agent AI systems. Trace reasoning steps, catch loops, guard budgets, and replay runs deterministically.

Install

pip install agentguard47

With LangChain support:

pip install agentguard47[langchain]

Quickstart

from agentguard import Tracer, LoopGuard, BudgetGuard

tracer = Tracer()
loop_guard = LoopGuard(max_repeats=3)
budget_guard = BudgetGuard(max_tokens=10000)

with tracer.trace("agent.run") as span:
    span.event("reasoning.step", data={"thought": "search docs"})

    loop_guard.check(tool_name="search", tool_args={"query": "agent loops"})
    budget_guard.record_tokens(150)

    with span.span("tool.call", data={"tool": "search"}):
        pass  # call your tool here

Tracing

from agentguard.tracing import Tracer

tracer = Tracer()

with tracer.trace("agent.run", data={"user_id": "u123"}) as span:
    span.event("reasoning.step", data={"step": 1, "thought": "search docs"})
    with span.span("tool.call", data={"tool": "search", "query": "agent loops"}):
        pass

Guards

from agentguard.guards import LoopGuard, BudgetGuard, TimeoutGuard

# Detect repeated tool calls
guard = LoopGuard(max_repeats=3)
guard.check(tool_name="search", tool_args={"query": "agent loops"})

# Track token and call budgets
budget = BudgetGuard(max_tokens=50000, max_calls=100)
budget.record_tokens(150)
budget.record_call()

# Enforce wall-clock time limits
timeout = TimeoutGuard(max_seconds=30)
timeout.start()
timeout.check()  # raises TimeoutExceeded if over limit

Replay

from agentguard.recording import Recorder, Replayer

recorder = Recorder("runs.jsonl")
recorder.record_call("llm", {"prompt": "hi"}, {"text": "hello"})

replayer = Replayer("runs.jsonl")
resp = replayer.replay_call("llm", {"prompt": "hi"})

Evaluation as Code

from agentguard import EvalSuite

result = (
    EvalSuite("traces.jsonl")
    .assert_no_loops()
    .assert_tool_called("search", min_times=1)
    .assert_budget_under(tokens=50000)
    .assert_completes_within(30.0)
    .assert_no_errors()
    .run()
)
print(result.summary)

Auto-Instrumentation

from agentguard import Tracer
from agentguard.instrument import trace_agent, trace_tool

tracer = Tracer()

@trace_agent(tracer)
def my_agent(query):
    return search(query)

@trace_tool(tracer)
def search(q):
    return f"results for {q}"

# Monkey-patch OpenAI/Anthropic (safe if not installed)
from agentguard.instrument import patch_openai, patch_anthropic
patch_openai(tracer)
patch_anthropic(tracer)

CLI

# Summarize trace events
agentguard summarize traces.jsonl

# Human-readable report
agentguard report traces.jsonl

# Open Gantt trace viewer in browser
agentguard view traces.jsonl

# Run evaluation assertions
agentguard eval traces.jsonl

Trace Viewer

agentguard view traces.jsonl --port 8080

Gantt-style timeline with color-coded spans (reasoning, tool, LLM, guard, error), click-to-expand detail panel, and aggregate stats.

Integrations

  • LangChain: agentguard.integrations.langchain

Links

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

agentguard47-0.3.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

agentguard47-0.3.0-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file agentguard47-0.3.0.tar.gz.

File metadata

  • Download URL: agentguard47-0.3.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentguard47-0.3.0.tar.gz
Algorithm Hash digest
SHA256 cb327fba99aaa506de7a923835f973a665a7ddfdbf92148110f3e6a6ce7bd477
MD5 9529afc4baa84f44ce7ddbd6d412f3ec
BLAKE2b-256 2b522b18ad426f90fdf4b76576130bb6917cb5dec1eb78d85d5f02c72ae1592f

See more details on using hashes here.

File details

Details for the file agentguard47-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: agentguard47-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for agentguard47-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3013d91e3c5729b719fd136ab54164ccb2cbd3e7da721d6ae539db8b51ac15a4
MD5 86e6de455279ac6bf55b7d06848a45f4
BLAKE2b-256 5c7a8a0de0459859d65c885afcf956d2846a2738166ea46b3c46b26ff5e37c58

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