用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tools-only/X-Skills --skill backend-architect命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| title | Agent Evaluation |
| description | Metrics, patterns, and tools for measuring custom agent effectiveness |
| tags | ["agents","testing","guide"] |
Quick nav: Why Evaluate? · Metrics to Track · Implementation · Example · Tools
When you create custom agents in .claude/agents/, you're encoding specialized expertise into reusable workflows. But how do you know if your agents are actually effective?
Without evaluation, you're building blind:
With evaluation, you iterate with confidence:
Core principle: Agents are code. Like all code, they need tests, metrics, and observability.
What to measure:
How to track:
# Post-response hook: .claude/hooks/log-response-quality.sh
# Triggered after each agent response
# Log structure:
{
"timestamp": "2026-02-10T14:32:00Z",
"agent_id": "backend-architect",
"task_completed": true,
"correctness_score": 4.5, # User rating 1-5
"hallucinations": 0,
"response_tokens": 1250
}
Implementation tip: Use user feedback prompts (thumbs up/down) or automated checks (test suite passing after agent code generation).
What to measure:
How to track:
# Post-tool-use hook: .claude/hooks/log-tool-usage.sh
# Triggered after each tool call
# Log structure:
{
"timestamp": "2026-02-10T14:32:05Z",
"agent_id": "backend-architect",
"tool_name": "Read",
"tool_success": true,
"tool_parameters": {"file_path": "src/auth.ts"},
"execution_time_ms": 45
}
Implementation tip: Use Claude Code hooks system (see examples/hooks/) to automatically log tool calls.
What to measure:
How to track:
# Session-end hook: .claude/hooks/log-performance.sh
# Triggered at end of session
# Log structure:
{
"timestamp": "2026-02-10T14:35:00Z",
"agent_id": "backend-architect",
"session_duration_s": 180,
"input_tokens": 3500,
"output_tokens": 2800,
"total_cost_usd": 0.15,
"context_utilization": 0.42
}
Implementation tip: Parse Claude Code session logs or use MCP observability tools.
What to measure:
How to track:
# Manual feedback collection
# After agent completes task, prompt user:
"Rate this agent's performance (1-5): _"
# Log:
{
"timestamp": "2026-02-10T14:35:10Z",
"agent_id": "backend-architect",
"user_rating": 5,
"user_comment": "Perfect analysis of auth flow",
"would_use_again": true
}
Implementation tip: Add feedback prompts to agent templates or use post-session surveys.
Use Case: Automatically track all agent interactions without manual intervention
Setup:
# .claude/hooks/post-tool-use.sh
#!/bin/bash
# Triggered after every tool call
AGENT_ID=$(echo "$CLAUDE_AGENT_ID" | jq -r)
TOOL_NAME=$(echo "$CLAUDE_TOOL_NAME" | jq -r)
TOOL_SUCCESS=$(echo "$CLAUDE_TOOL_SUCCESS" | jq -r)
# Append to metrics log
echo "{\"timestamp\":\"$(date -Iseconds)\",\"agent\":\"$AGENT_ID\",\"tool\":\"$TOOL_NAME\",\"success\":$TOOL_SUCCESS}" \
>> .claude/logs/agent-metrics.jsonl
Pros: Zero manual overhead, complete coverage, time-series data Cons: Requires parsing Claude Code environment variables (may change across versions)
Use Case: Regression testing to ensure agent improvements don't break existing capabilities
Setup:
# tests/agents/backend-architect.test.sh
#!/bin/bash
# Test 1: Agent correctly identifies hexagonal architecture layers
echo "Test: Hexagonal architecture analysis"
RESULT=$(claude agent backend-architect "Analyze src/auth.ts for layer violations")
if echo "$RESULT" | grep -q "domain layer"; then
echo "✅ PASS: Identified layers"
else
echo "❌ FAIL: Did not identify layers"
exit 1
fi
# Test 2: Agent recommends correct patterns
echo "Test: Pattern recommendations"
RESULT=$(claude agent backend-architect "Improve error handling in src/api.ts")
if echo "$RESULT" | grep -q "Result<T, E>"; then
echo "✅ PASS: Recommended Result pattern"
else
echo "❌ FAIL: Incorrect pattern"
exit 1
fi
Pros: Automated, catches regressions, CI/CD integration Cons: Requires maintenance, may have false positives/negatives
Use Case: Compare two versions of agent to determine which performs better
Setup:
# .claude/agents/backend-architect-v1.md (control)
name: backend-architect
version: 1.0
instructions: |
You are a backend architect specializing in...
[original instructions]
# .claude/agents/backend-architect-v2.md (experiment)
name: backend-architect-v2
version: 2.0
instructions: |
You are a backend architect specializing in...
[modified instructions with new pattern emphasis]
Evaluation:
# Run same task with both agents, compare metrics
# Task: "Analyze src/auth.ts for security issues"
# Version 1 metrics:
# - Response time: 45s
# - Issues found: 3
# - User rating: 4/5
# Version 2 metrics:
# - Response time: 38s
# - Issues found: 5 (2 additional critical issues)
# - User rating: 5/5
# Conclusion: Version 2 is more thorough and faster → promote to production
Pros: Data-driven decisions, quantifiable improvements Cons: Requires discipline to run controlled experiments
Use Case: Continuously improve agent based on real-world usage data
Setup:
# After agent completes task
echo "How would you rate this response? (1-5, or 'skip'): "
read RATING
if [ "$RATING" != "skip" ]; then
echo "Any specific feedback?: "
read COMMENT
# Log feedback
echo "{\"timestamp\":\"$(date -Iseconds)\",\"agent\":\"$AGENT_ID\",\"rating\":$RATING,\"comment\":\"$COMMENT\"}" \
>> .claude/logs/agent-feedback.jsonl
fi
# Weekly: Review feedback.jsonl, identify patterns
# Monthly: Update agent instructions based on aggregated feedback
Pros: Aligns agent with actual user needs, identifies edge cases Cons: Requires manual review and action on feedback
Full template available: examples/agents/analytics-with-eval/ includes complete agent definition, hooks, analysis scripts, and report template.
# .claude/agents/analytics-agent.md
---
name: analytics-agent
description: SQL query generator with evaluation hooks
version: 1.0
tools:
- Read
- Write
- Bash
hooks:
post_response: .claude/hooks/log-analytics-metrics.sh
---
# Analytics Agent
You are an expert SQL analyst helping users query databases.
## Evaluation Criteria
After each query:
1. **Correctness**: Does query produce expected results?
2. **Performance**: Query execution time < 5s?
3. **Safety**: No destructive operations (DELETE, DROP, TRUNCATE)?
[ ]
# .claude/hooks/log-analytics-metrics.sh
#!/bin/bash
# Triggered after analytics-agent response
# Extract query from response (naive grep, improve with jq)
QUERY=$(echo "$CLAUDE_RESPONSE" | grep -oP 'SELECT.*?;')
if [ -n "$QUERY" ]; then
# Test query (requires database connection)
EXEC_TIME=$( (time psql -U user -d db -c "$QUERY") 2>&1 | grep real | awk '{print $2}')
# Check for destructive operations
if echo "$QUERY" | grep -iE 'DELETE|DROP|TRUNCATE'; then
SAFETY="FAIL"
else
SAFETY="PASS"
fi
# Log metrics
echo "{\"timestamp\":\"$(date -Iseconds)\",\"query\":\"$QUERY\",\"exec_time\":\"$EXEC_TIME\",\"safety\":\"$SAFETY\"}" \
>> .claude/logs/analytics-metrics.jsonl
fi
# Monthly review: Analyze metrics
jq -s 'group_by(.safety) | map({safety: .[0].safety, count: length})' \
.claude/logs/analytics-metrics.jsonl
# Output:
# [
# {"safety": "PASS", "count": 127},
# {"safety": "FAIL", "count": 3}
# ]
# Action: Review 3 failed queries, update agent instructions to prevent future violations
What it provides:
How to adapt for Claude Code:
.claude/agents/ configStatus: Production-ready, actively maintained, TypeScript + Python
Hooks system: .claude/hooks/ for automated logging (see examples/hooks/README.md)
Agents directory: .claude/agents/ for custom agent definitions (see guide/ultimate-guide.md Section 4)
MCP observability: Use MCP servers for advanced logging and metrics aggregation
Week 1: Add basic logging hook (tool calls only) Week 2: Add user feedback prompt (manual ratings) Week 3: Build dashboard to visualize metrics Week 4: Run first A/B test on agent configuration
Don't track metrics you won't act on. Prioritize:
Manual evaluation doesn't scale. Use:
Metrics are useless without action:
Next steps:
Template: See examples/agents/analytics-with-eval/ for complete implementation with hooks, scripts, and report template