Skip to main content

pytest for AI agents — trace, debug and catch regressions in LLM swarms

Project description

readme = '''

swarmtrace logo

swarmtrace

pytest for AI agents — trace, debug and catch regressions in LLM swarms

PyPI


Demo

Watch the live demo: https://www.loom.com/share/a0bb4d18816c4991a2de9a02c3cfe597


Install

pip install swarmtrace

Quick Start

from litai import LLM
from tracely import observe

llm = LLM(model="anthropic/claude-haiku-4-5-20251001")

@observe
def my_agent(question):
    return llm.chat(question)

my_agent("What is machine learning?")

Multi-Agent Swarm Tracing

@observe
def researcher(q):
    return llm.chat(f"Research: {q}")

@observe
def summarizer(text):
    return llm.chat(f"Summarize: {text}")

@observe
def orchestrator(q):
    research = researcher(q)
    return summarizer(research)

orchestrator("What is AGI?")

Output:

[swarmtrace] ▶ orchestrator started (id=2b914f91)
[swarmtrace]   ▶ researcher started (id=ffbf1215)
[swarmtrace]   done: researcher | 3.4s | 7in/330out | $0.0013
[swarmtrace]   ▶ summarizer started (id=4fc29468)
[swarmtrace]   done: summarizer | 0.8s | 338in/78out | $0.0005
[swarmtrace] done: orchestrator | 4.2s | 7in/78out | $0.0003

Token Budget Manager

Never let agents burn unlimited tokens again:

from tracely import observe
from tracely.budget import budget

@observe
@budget(max_tokens=500, warn_at=0.8)
def agent(q):
    return llm.chat(q)

agent("What is AI?")
agent("What is ML?")
agent("What is AGI?")

Output:

[swarmtrace] Budget: agent [████████░░░░░░░░░░░░] 203/500 tokens (41%)
[swarmtrace] WARNING: agent [█████████████████░░░] 437/500 tokens (87%) near limit!
[swarmtrace] OVER BUDGET: agent [███████████████████████] 697/500 tokens

Tool Attention — 95% Token Reduction

Based on arXiv:2604.21816 — reduces tool token overhead using semantic similarity:

from tracely.tool_attention import ToolAttention

tools = [
    {"name": "web_search", "description": "Search the web", "schema": {"query": "string"}},
    {"name": "code_exec", "description": "Execute Python code", "schema": {"code": "string"}},
    {"name": "image_gen", "description": "Generate images", "schema": {"prompt": "string"}},
    {"name": "send_email", "description": "Send an email", "schema": {"to": "string"}},
    {"name": "db_query", "description": "Query a database", "schema": {"sql": "string"}},
]

ta = ToolAttention(tools=tools)
active_tools = ta.select("write and run a python script", k=3)

Output:

[ToolAttention] Indexed 5 tools | Full schema: ~55 tokens
[ToolAttention] Selected 3/5 tools in 0.012s
[ToolAttention] Tokens: 55 to 17 (69.1% reduction)
[ToolAttention]   code_exec
[ToolAttention]   write_file
[ToolAttention]   api_call

Web Scraping Tracing

from tracely.scraper import scrape
from tracely import observe

@observe
def research_agent(topic):
    web_data = scrape("https://news.ycombinator.com")
    return llm.chat(f"Summarize this about {topic}: {web_data[:500]}")

research_agent("AI news")

Async Support

import asyncio

@observe
async def async_researcher(q):
    return llm.chat(q)

@observe
async def async_orchestrator(q):
    research, summary = await asyncio.gather(
        async_researcher(q),
        async_summarizer(q)
    )
    return f"{research} | {summary}"

asyncio.run(async_orchestrator("What is quantum computing?"))

CLI Commands

swarmtrace                        # view all traces with rich colors + agent tree
swarmtrace-replay <id>            # replay any trace instantly
swarmtrace-export --format json   # export to JSON
swarmtrace-export --format csv    # export to CSV

Regression Detection

from tracely.regression import compare

compare(
    my_agent,
    inputs=["What is ML?", "How does Python work?", "What is an API?"],
    version_a_prompt="You are a helpful assistant.",
    version_b_prompt="Reply only in emojis."
)

Output:

INPUT                     V1      V2     SIMILARITY  REGRESSION?
What is ML?               3.7s    1.5s   0.1         YES
How does Python work?     3.0s    1.1s   0.15        YES
What is an API?           3.1s    1.0s   0.15        YES

Result: 3/3 regressions detected
WARNING: Your new prompt may have regressed!

Features

Feature swarmtrace LangSmith
Open Source YES NO
Works offline YES NO
Any LLM YES NO LangChain only
Multi-agent tree YES YES
Async + thread safe YES YES
Token budget manager YES NO
Tool Attention ISO scoring YES NO
Regression detection YES NO
Web scraping tracing YES NO
One decorator setup YES NO
Self-hosted YES NO
Price Free $20/month

Benchmarks — AMD MI300X (192GB)

Tested on AMD Instinct MI300X GPU via DigitalOcean AMD Developer Cloud.

Metric Value
Hardware AMD MI300X 192GB
Swarms 5 orchestrators
Total agent calls 20
Avg orchestrator latency 6.1s
Avg researcher latency 1.8s
Trace overhead less than 1ms per call
AMD MI300X Benchmark

Roadmap

  • PostgreSQL backend for production scale
  • Web dashboard UI
  • Native OpenAI/Anthropic exact token counts
  • PII redaction for sensitive traces
  • Distributed agent support

Built with love at AMD Hackathon 2026 by Ravi

'''

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

swarmtrace-0.1.6.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

swarmtrace-0.1.6-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file swarmtrace-0.1.6.tar.gz.

File metadata

  • Download URL: swarmtrace-0.1.6.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for swarmtrace-0.1.6.tar.gz
Algorithm Hash digest
SHA256 641780fb5317fc4a826b9f54e1934b441d67399e125a6aa9e7c9d2c6e60176ce
MD5 b69a8b5e5012ae551b3db1d41136d907
BLAKE2b-256 c58f001ec42ef954b818f732e8fe6fd18c0741aaf7e29942e23e779da0278623

See more details on using hashes here.

File details

Details for the file swarmtrace-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: swarmtrace-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for swarmtrace-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7097538a2d4bd2090ca06ca0f541bc2441bc1be179bf23abba84948b32a3132d
MD5 2cc35daa6651ad82427050db82665d03
BLAKE2b-256 622979efbd5194f3660fa3c9e5f6e972b2b661f948a252f43adec85fcebc38c3

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