multiagent-trace-middleware
Real-time tracing middleware for Python agents. Build terminal UIs or desktop apps that display your LangGraph/LangChain agent execution with hierarchical visualization, color-coded agents, and live status updates.
What is this for?
When building apps that integrate Python AI agents (LangGraph, LangChain, etc.), you often need to display what your agent is doing in real-time. This middleware hooks into your agent and emits structured events that your UI can consume to show:
- Which agent is currently running (with customizable colors for each agent)
- Hierarchical nesting levels (main agent → subagent → sub-subagent)
- Tool calls and their results (with arguments and completion status)
- Agent thinking/reasoning in real-time
- Todo list updates as agents work through tasks
Perfect for building:
- Terminal-based agent UIs (like the screenshots above)
- Desktop applications with agent monitoring
- Web dashboards showing agent execution
- Debugging tools for multi-agent systems
Features
- Agent Hierarchy Tracking: Automatically tracks parent-child relationships between agents
- Event Emission: Emits structured events for thinking, tool calls, tool results, and completions
- Dual Output: Supports both EventBus (programmatic) and JSON stdout (terminal apps)
- Color Support: Customizable foreground/background colors per agent for UI display
- Level Tracking: Automatic nesting level calculation (0=root, 1=subagent, etc.)
Installation
pip install multiagent-trace-middleware
Or with uv:
uv add multiagent-trace-middleware
Quick Start
from multiagent_trace_middleware import AgentObserverMiddleware, get_event_bus
# Add middleware to your main agent
middleware = [
AgentObserverMiddleware(
"main",
fg_color="#FFFFFF",
bg_color="#1E88E5"
),
]
# Add middleware to subagents
subagent_middleware = [
AgentObserverMiddleware(
"researcher",
fg_color="#000000",
bg_color="#4CAF50"
),
]
# Subscribe to events
def on_event(event_type, agent_name, fg_color, bg_color, level, data):
print(f"[L{level}] {agent_name}: {event_type}")
get_event_bus().subscribe(on_event)
Event Types
| Event Type | Description |
|---|---|
agent_change |
Emitted when switching between agents |
thinking |
AI reasoning/content output |
tool_call |
Tool invocation with arguments |
tool_result |
Tool execution results |
completion |
Agent completion messages |
todos |
Todo list updates |
message |
Raw message objects (EventBus only) |
JSON Output Format
When emit_json=True (default), events are written to stdout as JSON:
{
"type": "tool_call",
"timestamp": "2024-01-15T10:30:00.000000",
"agent_name": "researcher",
"agent_level": 1,
"agent_fg_color": "#000000",
"agent_bg_color": "#4CAF50",
"tool_name": "search",
"tool_call_id": "call_abc123",
"args": {"query": "example"}
}
API Reference
AgentObserverMiddleware
AgentObserverMiddleware(
name: str, # Agent name for display
fg_color: str = "#000000", # Foreground color (hex)
bg_color: str = "#ffffff", # Background color (hex)
emit_json: bool = True, # Emit JSON to stdout
emit_events: bool = True, # Emit to EventBus
)
EventBus
from multiagent_trace_middleware import get_event_bus
bus = get_event_bus()
bus.subscribe(callback) # Subscribe to events
bus.unsubscribe(callback) # Unsubscribe
bus.clear() # Clear all listeners
Agent Tree
from multiagent_trace_middleware import get_agent_tree, reset_agent_tree
tree = get_agent_tree()
node = tree.current # Get current agent node
level = tree.current_level # Get current nesting level
reset_agent_tree() # Reset tree (useful for testing)
License
MIT
Release files for multiagent-trace-middleware 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| multiagent_trace_middleware-0.1.0.tar.gz | 202.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| multiagent_trace_middleware-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 213.5 kB
Release files / multiagent_trace_middleware-0.1.0.tar.gz
| Download URL | multiagent_trace_middleware-0.1.0.tar.gz |
|---|---|
| Size | 202.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea667b2d88bfaf7fa26f6118907e909f01c2111a07d12489eef4ca1b2e0fa7d0
|
|
BLAKE2b-256 checksum How to use checksums |
504e3c3dcd74c6447ed31c961f54b06c44d9eaee2feec902ed1445b40da67ab0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 27, 2025.
Transparency logRelease files / multiagent_trace_middleware-0.1.0-py3-none-any.whl
| Download URL | multiagent_trace_middleware-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b61504bcd2069f3e3405b075d0d2e63c893dcec92a2fa96804e426889c673741
|
|
BLAKE2b-256 checksum How to use checksums |
231e9a1a683c6270481407e904b5b3e62b7da1de9aab1d9846908922e5efa3a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 27, 2025.
Transparency log