Observed since 20 Oct, 21:40 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Agent quality analysis and repair SDK for OpenTelemetry traces
Agent quality analysis and repair SDK for OpenTelemetry traces
AgentCoach analyzes agent execution traces to detect quality issues, identify root causes, and provide actionable recommendations for improvement. It works with OpenTelemetry/OpenInference-style traces and supports runtime repair loops.
# Clone the repository
git clone <repo-url>
cd agentcoach
# Install in development mode
pip install -e .
# Or install with dev dependencies
pip install -e ".[dev]"
agentcoach init
This creates:
agentcoach.yaml - Configuration file.env.example - Environment variables templateagentcoach analyze --trace examples/sample_trace.json --out results/
This generates:
results/report.json - Structured findingsresults/report.html - Interactive HTML reportOpen results/report.html in your browser to see:
agentcoach init
# Basic analysis
agentcoach analyze --trace path/to/trace.json --out output_dir/
# With custom config
agentcoach analyze --trace trace.json --out results/ --config agentcoach.yaml
# With LLM judge (requires API keys in .env)
agentcoach analyze --trace trace.json --out results/ --llm-judge
# Repair with heuristics only
agentcoach repair --trace trace.json --out repaired/
# Repair with LLM provider
agentcoach repair --trace trace.json --out repaired/ --llm-provider openai
agentcoach canary --report results/report.json --suite canary_tests/
from agentcoach import load_trace, analyze_trace
from agentcoach.report import generate_report
# Load and analyze trace
trace = load_trace("path/to/trace.json")
findings = analyze_trace(trace)
# Generate reports
generate_report(trace, findings, "output_dir/")
from agentcoach.langgraph import QualityGuardNode
# Create quality guard node
quality_guard = QualityGuardNode(
contract_schema="schemas/default_contract.json",
policy_pack="schemas/default_policy.json",
auto_repair=True,
)
# Add to your LangGraph
from langgraph.graph import StateGraph
graph = StateGraph(AgentState)
graph.add_node("quality_guard", quality_guard)
graph.add_edge("draft_answer", "quality_guard")
graph.add_edge("quality_guard", END)
app = graph.compile()
See examples/langgraph_demo.py for a complete example.
# Output contract schema
contract_schema: schemas/default_contract.json
# Policy pack
policy: schemas/default_policy.json
# LLM Judge
llm_judge:
enabled: false
provider: openai # openai, anthropic, or sap
# Detector configuration
detectors:
schema:
enabled: true
grounding:
enabled: true
require_citations: true
tool_use:
enabled: true
loops:
enabled: true
max_repeats: 3
state:
enabled: true
policy_tone:
enabled: true
consistency:
enabled: false
Create a .env file (see .env.example):
# OpenAI
OPENAI_API_KEY=your_key_here
OPENAI_MODEL=gpt-4o-mini
# Anthropic
ANTHROPIC_API_KEY=your_key_here
ANTHROPIC_MODEL=claude-3-5-sonnet-20241022
# SAP BTP AI Core
AICORE_BASE_URL=https://api.ai.prod.eu-central-1.aws.ml.hana.ondemand.com
AICORE_CLIENT_ID=your_client_id
AICORE_CLIENT_SECRET=your_client_secret
AICORE_RESOURCE_GROUP=default
AICORE_MODEL=gpt-4
AgentCoach supports OpenTelemetry and simplified trace formats:
{
"trace_id": "trace-001",
"spans": [
{
"span_id": "span-1",
"name": "agent_run",
"kind": "agent",
"attributes": {
"input.value": "User query",
"output.value": "Agent response"
}
},
{
"span_id": "span-2",
"parent_span_id": "span-1",
"name": "retrieval",
"kind": "retrieval",
"attributes": {
"retrieval.query": "search query",
"documents": [
{"content": "Retrieved document text"}
]
}
}
]
}
from langchain_core.tracers import LangChainTracer
import json
tracer = LangChainTracer()
result = graph.invoke(input, config={"callbacks": [tracer]})
# Export trace
with open("trace.json", "w") as f:
json.dump(tracer.runs[0].dict(), f)
# Run all tests
pytest
# Run with coverage
pytest --cov=agentcoach --cov-report=html
# Run specific test
pytest tests/test_schema_detector.py -v
Validates output against JSON schema contracts.
Checks:
Verifies answers are grounded in evidence.
Checks:
Detects tool execution failures.
Checks:
Identifies infinite loops and planning failures.
Checks:
Tracks constraint loss.
Checks:
Enforces policy compliance.
Checks:
Multi-run variance analysis (MVP stub).
AgentCoach provides actionable recommendations:
--- system_prompt
+++ system_prompt
You are a helpful assistant.
+
+Always format your response as JSON with:
+{"answer": "...", "confidence": 0.0-1.0, "citations": [...]}
def call_tool_with_retry(tool_name, args, max_retries=2):
for attempt in range(max_retries + 1):
try:
return execute_tool(tool_name, args)
except Exception as e:
if attempt < max_retries:
args = fix_tool_args(tool_name, args, error=str(e))
else:
return {"error": str(e)}
Generate regression tests from failures:
agentcoach canary --report results/report.json --suite canary_tests/
This creates:
canary_tests/cases.jsonl - Test casescanary_tests/test_canary.py - Pytest fileImplement the run_agent() function and run:
pytest canary_tests/test_canary.py -v
agentcoach/
├── agentcoach/
│ ├── __init__.py
│ ├── cli.py # CLI commands
│ ├── models.py # Data models
│ ├── trace_ingest.py # Trace parsing
│ ├── config.py # Configuration
│ ├── contracts.py # Schema validation
│ ├── report.py # Report generation
│ ├── repair.py # Runtime repair
│ ├── judge.py # LLM judge adapters
│ ├── canary.py # Test generation
│ ├── langgraph.py # LangGraph integration
│ └── detectors/ # Quality detectors
├── schemas/ # Default schemas
├── examples/ # Example code
├── tests/ # Test suite
└── README.md
Contributions welcome! Please:
pytest and ruff checkMIT License - see LICENSE file for details.
Built for analyzing agent quality with OpenTelemetry/OpenInference traces.
examples/ directoryMade with ❤️ for better agent quality
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.1.0 | 30 Dec 2025 | 11 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 21:40 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:14afebbd468827d4e0acb972bf6bde9efc69f034036905abdf8594080c3929fa