Skip to main content

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

Project description

Copyswarmtrace 🐝

swarmtrace logo

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

Install

bashpip install swarmtrace

Quick Start

pythonfrom tracely import observe

@observe def my_agent(question): # your LLM call here return "answer"

my_agent("What is machine learning?")

Then view your traces:

bashswarmtrace

Multi-Agent Swarm Tracing

pythonfrom tracely import observe

@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

Async Support

pythonimport asyncio from tracely import observe

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

@observe async def async_orchestrator(q): results = await asyncio.gather( async_researcher(q), async_researcher(q + " deep dive") ) return " | ".join(results)

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

CLI Commands

bashswarmtrace # view traces (default: last 100) swarmtrace --limit 50 # view last 50 traces swarmtrace-replay # replay any trace by ID swarmtrace-export --format json # export to JSON swarmtrace-export --format csv # export to CSV

Regression Detection

bashpip install swarmtrace[regression]

pythonfrom tracely.regression import compare

def my_agent(input_text, prompt): return llm.chat(f"{prompt}\n\n{input_text}")

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.", threshold=0.6, # optional, default 0.6 )

Output:

INPUT V1 LATENCY V2 LATENCY 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!

Remote Ingest (SaaS)

pythonfrom tracely import init, observe

init( api_key="your-swarmtrace-api-key", endpoint="https://your-swarmtrace-backend.com", )

@observe def my_agent(q): ...

Or via environment variables:

bashexport SWARMTRACE_API_KEY=your-key export SWARMTRACE_ENDPOINT=https://your-backend.com

Features

FeatureswarmtraceLangSmithOpen Source✅❌Works offline✅❌Any LLM✅❌ LangChain onlyMulti-agent tree✅✅Async support✅✅Regression detection✅❌One decorator setup✅❌Cost per agent✅✅Self-hosted✅❌Pricea DigitalOcean AMD Developer Cloud.

MetricValueHardwareAMD MI300X 192GBSFree$20/month

AMD MI300X Benchmarks

Tested on AMD Instinct MI300X GPU viwarms5 orchestratorsTotal agent calls20Avg orchestrator latency6.1sAvg researcher latency1.8sTrace overhead<1ms per call

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.3.0.tar.gz (15.2 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.3.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for swarmtrace-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9e5feafb1d1b024a38c9d553fc7627dcef696943c8e16271a8e216a4495eac80
MD5 5304647ea6538283de24fb34ddfd3ffa
BLAKE2b-256 2064b987499a3c58a2ca0a63988e30dda282094e02b07e60c61d26d89a62498c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmtrace-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 17.3 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3af60157c5440d074f0cd9a33b9f5f5a36a5071f14851c58e79d57d5bd4db38
MD5 a5e8b7268b44a0ff2ce72fffe277ea14
BLAKE2b-256 e058f4d09c629a89f59fa32db4dbd59145621777206db341ed47e10c281c38ae

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