Distributed tracing and observability for AI agents. Datadog for AI Agents.
Project description
๐ traceweave
Distributed Tracing & Observability for AI Agents
See exactly what your AI agents are doing. Debug multi-agent systems like a pro.
English | ็ฎไฝไธญๆ | ๆฅๆฌ่ช | ํ๊ตญ์ด | Espaรฑol
Quick Start ยท Features ยท Integrations ยท Dashboard ยท Examples
Think of it as Datadog for AI Agents. Trace every agent decision, tool call, and LLM interaction with beautiful visualizations and zero-config instrumentation.
๐ Trace: multi-agent-research id=a3f2c1d8...
โโโ โ
๐ multi-agent-research โโโโโโโโโโโโโโโโโโโโโโโโ 12.3s tokens: 8.2k cost: $0.15
โ โโโ โ
๐ค planner โโโโโโโโโโโโโโโโโโโโโโ 3.2s tokens: 2.1k cost: $0.04
โ โ โโโ โ
๐ง plan-generation โโโโโโโโโโโโโโโโโโโโโโ 2.1s tokens: 1.8k cost: $0.03
โ โโโ โ
๐ค researcher โโโโโโโโโโโโโโโโโโโโโโ 5.1s tokens: 3.4k cost: $0.06
โ โ โโโ โ
๐ง web-search โโโโโโโโโโโโโโโโโโโโโโ 0.6s tokens: - cost: -
โ โ โโโ โ
๐ง arxiv-search โโโโโโโโโโโโโโโโโโโโโโ 0.3s tokens: - cost: -
โ โ โโโ โ
๐ง analyze-results โโโโโโโโโโโโโโโโโโโโโโ 3.1s tokens: 2.8k cost: $0.05
โ โโโ โ
๐ค writer โโโโโโโโโโโโโโโโโโโโโโ 4.8s tokens: 1.9k cost: $0.04
โ โ โโโ โ
๐ง write-report โโโโโโโโโโโโโโโโโโโโโโ 4.2s tokens: 1.9k cost: $0.04
โ โโโ โ
๐ค reviewer โโโโโโโโโโโโโโโโโโโโโโ 2.4s tokens: 0.8k cost: $0.01
โ โโโ โ
๐ง review-report โโโโโโโโโโโโโโโโโโโโโโ 2.1s tokens: 0.8k cost: $0.01
โฐโโ Summary โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โฑ Duration: 12.3s โ ๐ข Spans: 11 โ ๐ Tokens: 8.2k โ ๐ฐ Cost: $0.15
Why traceweave?
Building with AI agents? You've probably experienced:
- ๐คฏ "Why did my agent do that?" โ No visibility into agent reasoning chains
- ๐ธ "Where are my tokens going?" โ Can't track costs across nested agent calls
- ๐ "Which step failed?" โ Debugging multi-agent pipelines is a nightmare
- ๐ "How long does each step take?" โ No performance profiling for agents
traceweave solves all of this with 2 lines of code.
๐ Quick Start
pip install traceweave
from agent_trace import tracer, trace_agent, trace_tool
from agent_trace.dashboard.tui import print_trace
@trace_tool("calculator")
def add(a: int, b: int) -> int:
return a + b
@trace_agent("math-agent")
def math_agent(question: str) -> int:
return add(2, 3)
# Trace everything
with tracer.start_trace("math-task"):
answer = math_agent("What is 2 + 3?")
# Visualize
print_trace(tracer.get_all_traces()[-1])
โจ Features
๐ฏ Zero-Config Auto-Instrumentation
Automatically trace OpenAI, Anthropic, and LangChain with a single line:
from agent_trace.integrations import instrument_all
instrument_all() # That's it! All LLM calls are now traced.
๐ค Elegant Decorators
@trace_agent("researcher") # Trace agent functions
@trace_tool("web-search") # Trace tool calls
@trace_llm(model="gpt-4") # Trace LLM calls with token tracking
๐ Token & Cost Tracking
Automatic token counting and cost estimation for all major models:
with tracer.start_span("my-llm-call", SpanKind.LLM) as span:
response = call_llm(prompt)
span.set_token_usage(
prompt_tokens=1500,
completion_tokens=500,
model="claude-3-sonnet",
prompt_cost_per_1k=0.003,
completion_cost_per_1k=0.015,
)
๐ฅ๏ธ Beautiful Terminal Dashboard
traceweave tui # Live-updating terminal dashboard
๐ Web Dashboard
traceweave dashboard # Opens at http://localhost:8420
Dark-themed, real-time web dashboard with:
- Interactive trace tree visualization
- Token usage analytics
- Cost breakdown per agent/tool
- Timeline waterfall view
๐ค Export Anywhere
from agent_trace.exporters import export_json, export_chrome
# Save as JSON
export_json(trace, "my-trace.json")
# Export to Chrome DevTools format (open in chrome://tracing)
export_chrome(trace, "my-trace.chrome.json")
๐ Integrations
OpenAI
from agent_trace.integrations.openai_integration import instrument_openai
instrument_openai()
# All OpenAI calls are now traced automatically!
client = openai.OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
Anthropic
from agent_trace.integrations.anthropic_integration import instrument_anthropic
instrument_anthropic()
# All Anthropic calls are now traced!
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-3-sonnet-20240229",
messages=[{"role": "user", "content": "Hello!"}]
)
LangChain
from agent_trace.integrations.langchain_integration import AgentTraceCallbackHandler
handler = AgentTraceCallbackHandler()
chain = prompt | llm | output_parser
chain.invoke({"input": "..."}, config={"callbacks": [handler]})
๐ Examples
| Example | Description |
|---|---|
| Simple Demo | Minimal example โ trace in 10 lines |
| Multi-Agent Research | 4-agent team with tools, LLM calls, and cost tracking |
Run the built-in demo:
traceweave demo
๐๏ธ Architecture
traceweave/
โโโ agent_trace/
โ โโโ core/ # Core tracing engine
โ โ โโโ models.py # Pydantic data models (Span, Trace, TokenUsage)
โ โ โโโ tracer.py # Main tracer with context management
โ โ โโโ span.py # Span context manager
โ โ โโโ context.py # Thread-safe context propagation
โ โ โโโ decorators.py # @trace_agent, @trace_tool, @trace_llm
โ โโโ integrations/ # Framework auto-instrumentation
โ โ โโโ openai_integration.py
โ โ โโโ anthropic_integration.py
โ โ โโโ langchain_integration.py
โ โโโ dashboard/ # Visualization
โ โ โโโ tui.py # Rich terminal dashboard
โ โ โโโ server.py # Web dashboard (single HTML, no build step)
โ โโโ exporters/ # Export formats
โ โ โโโ json_exporter.py
โ โ โโโ chrome_exporter.py
โ โโโ cli.py # CLI commands
โโโ examples/ # Demo scripts
๐ Key Concepts
| Concept | Description |
|---|---|
| Trace | A complete operation (e.g., "research task"). Contains a tree of spans. |
| Span | A single unit of work (agent call, tool use, LLM request). |
| SpanKind | Type of span: AGENT, TOOL, LLM, CHAIN, RETRIEVER |
| TokenUsage | Token counts + cost estimation per LLM call |
๐ฆ Installation
# Core only
pip install traceweave
# With specific integrations
pip install traceweave[openai]
pip install traceweave[anthropic]
pip install traceweave[langchain]
# Everything
pip install traceweave[all]
Requirements: Python 3.9+
๐ค Contributing
Contributions welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing) - Open a Pull Request
๐ License
MIT License โ see LICENSE for details.
Built with โค๏ธ for the AI agent community
If you find traceweave useful, please โญ star the repo!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file traceweave-0.1.2.tar.gz.
File metadata
- Download URL: traceweave-0.1.2.tar.gz
- Upload date:
- Size: 40.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6445ca6dd564d4a8562e511902487fec7152fd342887d1891b5ae48488c4ed3b
|
|
| MD5 |
85bd81a7981ff925a140bc6eadaf4a2e
|
|
| BLAKE2b-256 |
8297cb6b729543613683f5e44aeb487a6f7837f81d7ec6631e0d57bd80ba45aa
|
File details
Details for the file traceweave-0.1.2-py3-none-any.whl.
File metadata
- Download URL: traceweave-0.1.2-py3-none-any.whl
- Upload date:
- Size: 34.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5992b3fd160e163343ab4da955afaf80130309129085c77206be33b93e439ae
|
|
| MD5 |
7984675891a705afc6d2af5526e9f92b
|
|
| BLAKE2b-256 |
40187e289054864b9938e16b275a5bf3a1cd7f1c9a5fff64ddc29f5ba4aa8d85
|