Skip to main content

TraceRazor LangGraph/LangChain callback - token efficiency auditing

Project description

tracerazor-langgraph

LangGraph/LangChain callback adapter for TraceRazor.

Automatically captures every LLM call and tool call from your LangGraph graph with zero manual instrumentation.

v0.2.0 — New Metrics:

  • Semantic Continuity (CSD) — Detects when your agent's reasoning drifts topic mid-execution
  • Adherence Scoring (IAR) — After optimizing, validates that fixes actually improved metrics

Install

pip install tracerazor-langgraph
pip install tracerazor-langgraph[langgraph]  # includes langgraph

Requires the tracerazor binary:

cargo build --release
export TRACERAZOR_BIN=/path/to/TraceRazor/target/release/tracerazor

Usage

from tracerazor_langgraph import TraceRazorCallback
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI

callback = TraceRazorCallback(
    agent_name="support-agent",
    threshold=70,
)

model = ChatOpenAI(model="gpt-4o-mini")
agent = create_react_agent(model, tools=[...])

result = agent.invoke(
    {"messages": [HumanMessage(content="I want a refund")]},
    config={"callbacks": [callback]},
)

# After the agent finishes:
report = callback.analyse()
print(report.markdown())

# CI/CD gate — raises AssertionError if TAS < threshold:
callback.assert_passes()

API

TraceRazorCallback(agent_name, framework, threshold, task_value_score, tracerazor_bin)

param default description
agent_name "langgraph-agent" shown in all reports
framework "langgraph" framework label
threshold 70.0 minimum TAS for assert_passes()
task_value_score 1.0 answer quality (0–1)
tracerazor_bin auto path to binary; falls back to TRACERAZOR_BIN env var

callback.analyse() → TraceRazorReport

Finalise and submit the trace. Returns the report.

callback.assert_passes()

Raise AssertionError if TAS < threshold.

callback.set_task_value_score(score: float)

Update quality score before calling analyse().

Multi-Agent Workflows

For workflows with multiple graphs or nodes, use a separate callback for each agent:

from tracerazor_langgraph import TraceRazorCallback

# Agent 1: Triage
triage_callback = TraceRazorCallback(agent_name="triage-agent")
triage_result = triage_graph.invoke(input, config={"callbacks": [triage_callback]})
triage_report = triage_callback.analyse()

# Agent 2: Resolution
resolution_callback = TraceRazorCallback(agent_name="resolution-agent")
resolution_result = resolution_graph.invoke(triage_result, config={"callbacks": [resolution_callback]})
resolution_report = resolution_callback.analyse()

# Aggregate metrics
total_tokens = triage_report.total_tokens + resolution_report.total_tokens
avg_efficiency = (triage_report.tas_score + resolution_report.tas_score) / 2

Each agent is audited independently, enabling per-agent optimization. See Multi-Agent Guide for complete example with cost analysis.

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

tracerazor_langgraph-1.0.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

tracerazor_langgraph-1.0.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file tracerazor_langgraph-1.0.0.tar.gz.

File metadata

  • Download URL: tracerazor_langgraph-1.0.0.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for tracerazor_langgraph-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3b0677d6a3e9a6f32a24e8d61c005ca7c635341a7fff5e8aa1981a2cacf71212
MD5 5f72c7a7f63fcd22807477d4fe3e62c9
BLAKE2b-256 58aa1f075ac206959258f50b78ce452308db07fc409e7e3e71cb193371c5d176

See more details on using hashes here.

File details

Details for the file tracerazor_langgraph-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tracerazor_langgraph-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4208ec33b36fccac4cb70291a343380410c4d5c9c7f04dc83497c7bfb70672a9
MD5 0325b75fc30b8b2f76cb58bb46afdeb5
BLAKE2b-256 7bede34f88eb250c7f5310a33a3afffc5eee780fb3779beafc62d6bfe4a00863

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