Observability middleware for multi-agent LangGraph/LangChain workflows. Track agent trees, emit events, and trace execution across nested agents.
Project description
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
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 multiagent_trace_middleware-0.1.0.tar.gz.
File metadata
- Download URL: multiagent_trace_middleware-0.1.0.tar.gz
- Upload date:
- Size: 202.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea667b2d88bfaf7fa26f6118907e909f01c2111a07d12489eef4ca1b2e0fa7d0
|
|
| MD5 |
dde5e7459c722215cc28efd37f75cc6d
|
|
| BLAKE2b-256 |
504e3c3dcd74c6447ed31c961f54b06c44d9eaee2feec902ed1445b40da67ab0
|
Provenance
The following attestation bundles were made for multiagent_trace_middleware-0.1.0.tar.gz:
Publisher:
publish.yml on atom2ueki/multiagent-trace-middleware
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
multiagent_trace_middleware-0.1.0.tar.gz -
Subject digest:
ea667b2d88bfaf7fa26f6118907e909f01c2111a07d12489eef4ca1b2e0fa7d0 - Sigstore transparency entry: 729144118
- Sigstore integration time:
-
Permalink:
atom2ueki/multiagent-trace-middleware@5324a0ffbff588365b25fb1839bc58b5145443ab -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/atom2ueki
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5324a0ffbff588365b25fb1839bc58b5145443ab -
Trigger Event:
release
-
Statement type:
File details
Details for the file multiagent_trace_middleware-0.1.0-py3-none-any.whl.
File metadata
- Download URL: multiagent_trace_middleware-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b61504bcd2069f3e3405b075d0d2e63c893dcec92a2fa96804e426889c673741
|
|
| MD5 |
5a72c5c51a8b72e7c8f5d587a18e4e8c
|
|
| BLAKE2b-256 |
231e9a1a683c6270481407e904b5b3e62b7da1de9aab1d9846908922e5efa3a5
|
Provenance
The following attestation bundles were made for multiagent_trace_middleware-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on atom2ueki/multiagent-trace-middleware
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
multiagent_trace_middleware-0.1.0-py3-none-any.whl -
Subject digest:
b61504bcd2069f3e3405b075d0d2e63c893dcec92a2fa96804e426889c673741 - Sigstore transparency entry: 729144119
- Sigstore integration time:
-
Permalink:
atom2ueki/multiagent-trace-middleware@5324a0ffbff588365b25fb1839bc58b5145443ab -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/atom2ueki
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5324a0ffbff588365b25fb1839bc58b5145443ab -
Trigger Event:
release
-
Statement type: