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-0.2.0.tar.gz (9.8 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-0.2.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tracerazor_langgraph-0.2.0.tar.gz
Algorithm Hash digest
SHA256 724ae2dc96aae293f674969f7f62c6f33e34e4711e96563d5efd80ff635fae75
MD5 abe6c1f5d4f0554d09c6b8442d828219
BLAKE2b-256 c902acfac339879bebb6aff414b0f73142d23c9b5c4678072b0df26133400b75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tracerazor_langgraph-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0cec36fdb6c01e2272af5bd6a87570d155b0ec0f4cd8119bf0ca3a1ba6dc8b4
MD5 6fc838f087ce965cb932d6406b77b3e4
BLAKE2b-256 fb35ad707f1cc3bf1a6ddcff2c21190a01da9c321d4ec731a7051ff9f6864de1

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