agentleFS
hajekimhajekim/agentic-design-patterns-extension/skills/evaluation/SKILL.md

evaluation

Skill1 starsChanged 8 months agoMITView on GitHub

This skill should be used when the user wants to "evaluate agent performance", "agent benchmarking", "LLM evaluation", "agent testing", "measure agent quality", "agent metrics", "hallucination detection", "answer quality scoring", "agent monitoring in production", "LLM observability", "agent evals", "test agent accuracy", "LLM judge", "eval framework", "regression testing agents", "agent quality assurance", "automated agent testing", "agent accuracy metrics", or build evaluation frameworks that measure and monitor agent quality. Also responds to Korean: "에이전트 성능 평가", "LLM 평가 시스템", "에이전트 품질 측정", "환각 탐지", "에이전트 벤치마킹", "프로덕션 모니터링", "에이전트 테스트", "성능 측정", "에이전트 평가해줘", "에이전트 품질 검사해줘", "할루시네이션 잡아줘", "정확도 측정해줘". Also responds to Japanese: "エージェントの評価", "LLM評価システム", "エージェント品質測定", "ハルシネーション検出", "ベンチマーク", "精度測定", "エージェントをテストしたい", "品質チェック", "LLMジャッジ", "本番環境モニタリング" Also responds to Chinese: "智能体性能评估", "LLM评估系统", "智能体质量测量", "幻觉检测", "基准测试", "精度测量", "想测试智能体", "质量检查", "LLM评判者", "生产环境监控".. Apply this skill to design or implement the Evaluation & Monitoring agentic design pattern.

22 other projects use a version of this, 1 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use bdi-mental-states, hosted-agents and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Downey6689Skill

    bdi-mental-states

    Transforms external RDF context into BDI mental states. Invoke when modeling beliefs, desires, and intentions.

    Also in 5 projects that use this

  • Downey6689Skill

    hosted-agents

    Guidance for hosted/sandboxed agents. Invoke when running background agents in isolated VMs or multi-client setups.

    Also in 5 projects that use this

  • DVwebBiz11Skill

    self-improvement-loops

    This skill should be used when the harness, scaffold, workflow, or optimizer itself is the optimization target: recursive self-improvement (RSI) loops, meta-harnesses, self-improving harnesses that mine their own failures and propose bounded edits, evolutionary or population-based search over agent scaffolds, acceptance gates for self-modifying systems, and agentic context evolution where the mechanism that produces context is versioned and evolved. Route governance of a single autonomous loop (locked surfaces, durable logs, rollback, novelty gates, approval boundaries) to harness-engineering, measurement and quality-gate design to evaluation, judge design to advanced-evaluation, and remote sandbox infrastructure to hosted-agents.

    Also in 4 projects that use this

  • mjunaidcaSkill

    building-chatgpt-apps

    Guides creation of ChatGPT Apps with interactive widgets using OpenAI Apps SDK and MCP servers. Use when building ChatGPT custom apps with visual UI components, embedded widgets, or rich interactive experiences. Covers widget architecture, MCP server setup with FastMCP, response metadata, and Developer Mode configuration. NOT when building standard MCP servers without widgets (use building-mcp-servers skill instead).

    Also in 4 projects that use this

  • mjunaidcaSkill

    building-chat-interfaces

    Build AI chat interfaces with custom backends, authentication, and context injection. Use when integrating chat UI with AI agents, adding auth to chat, injecting user/page context, or implementing httpOnly cookie proxies. Covers ChatKitServer, useChatKit, and MCP auth patterns. NOT when building simple chatbots without persistence or custom agent integration.

    Also in 4 projects that use this

  • +7 more from mjunaidca

The file

We split this skill into the rules it gives an agent

8 rules. 0 are common, 8 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 21 edited versions we read keep these.

  • 8

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Rule of thumb: Every production agent needs evaluation and monitoring — this isn't optional, it's how you know the agent is doing its job.

    line 27
  2. Distinctive:

    Create a golden evaluation dataset (representative queries + expected outputs)

    line 53
  3. Distinctive:

    Run baseline evaluation before every deployment

    line 64
  4. Distinctive:

    LLM-as-judge: Use a separate LLM to evaluate responses — scalable and correlates well with human judgment

    line 427
  5. Distinctive:

    Latency + cost + quality: Don't optimize one metric at the expense of others — track the triad

    line 430
  6. Distinctive:

    Evaluating only happy paths: Test edge cases, ambiguous queries, and adversarial inputs

    line 435
  7. Distinctive:

    Ignoring failed evaluations: Every failed test case is a debugging opportunity — investigate them

    line 438
  8. Distinctive:

    Self-evaluation: Don't use the same model to evaluate its own outputs — use a separate judge

    line 439

“Common” is measured: kept by at least 6 in 10 of the 21 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Evaluation & Monitoring Pattern

Overview

The Evaluation & Monitoring Pattern establishes systematic methods for measuring agent quality, detecting degradation, and maintaining performance standards over time. Without evaluation, you cannot know if your agent is actually working correctly — and without monitoring, you won't know when it stops working.

Core Principle: You can't improve what you don't measure — define quality metrics before deployment, not after problems surface.

When This Skill Applies

Activate this pattern when:

  • An agent is being deployed to production and performance must be tracked
  • Agent behavior needs to be compared before and after changes
  • Hallucination rates, accuracy, or helpfulness must be measured quantitatively
  • A/B testing of different agent configurations is needed
  • Regulatory compliance requires audit trails and performance documentation
  • You need to detect agent drift or degradation over time

Rule of thumb: Every production agent needs evaluation and monitoring — this isn't optional, it's how you know the agent is doing its job.

Evaluation Dimensions

DimensionWhat It MeasuresEvaluation Method
CorrectnessIs the answer right?Ground truth comparison, expert review
FaithfulnessAre claims grounded in context?RAG evaluation, hallucination detection
RelevanceDoes response address the question?LLM-as-judge, human ratings
CompletenessAre all aspects covered?Checklist evaluation
SafetyIs output appropriate/harmless?Safety classifier, policy compliance
LatencyHow fast does the agent respond?P50/P95/P99 timing metrics
CostWhat is the per-query cost?Token counting, API cost tracking

DEFINE → PLAN → ACTION Workflow

DEFINE

Establish evaluation requirements:

  1. What does "good" mean for this specific agent? (Domain-specific criteria)
  2. What ground truth data is available? (Golden datasets, human labels)
  3. What metrics matter most? (Accuracy, safety, cost, latency — prioritize)
  4. How frequently should the agent be evaluated? (Continuous vs. periodic)
  5. What triggers a production alert? (Threshold-based, anomaly-based)

PLAN

Design the evaluation architecture:

  1. Create a golden evaluation dataset (representative queries + expected outputs)
  2. Choose evaluation methods: LLM-as-judge, human review, automated metrics
  3. Design the monitoring pipeline: what to log, where, and how to alert
  4. Plan A/B testing framework for comparing agent versions
  5. Define remediation process when evaluation detects problems

ACTION

Implement evaluation and monitoring:

  1. Build automated evaluation pipeline with golden dataset
  2. Instrument the agent with logging (latency, tokens, errors)
  3. Set up dashboards and alerts for key metrics
  4. Run baseline evaluation before every deployment
  5. Monitor production traffic continuously for drift

Implementation: LLM-as-Judge Evaluation

Automated Quality Assessment

from google import genai
from dataclasses import dataclass
from typing import List, Optional
import json
import re

@dataclass
class EvaluationResult:
    query: str
    response: str
    reference_answer: Optional[str]
    correctness: float      # 0.0 to 1.0
    relevance: float
    faithfulness: float
    overall_score: float
    reasoning: str
    passed: bool

class AgentEvaluator:
    """Evaluate agent responses using LLM-as-judge methodology."""

    def __init__(self, judge_model_name: str = "gemini-2.5-flash"):
        self.client = genai.Client()
        self.judge_model_name = judge_model_name

    def evaluate_response(
        self,
        query: str,
        response: str,
        reference_answer: Optional[str] = None,
        context: Optional[str] = None
    ) -> EvaluationResult:
        """Evaluate a single agent response across multiple dimensions."""

        eval_prompt = f"""You are an expert evaluator for AI agent responses.
Evaluate the following response on three dimensions, each scored 0.0 to 1.0.

Query: {query}
{"Reference Answer: " + reference_answer if reference_answer else ""}
{"Context Provided: " + context[:500] if context else ""}
Agent Response: {response}

Score each dimension:
1. Correctness (0.0-1.0): Is the response factually accurate?
   - 1.0 = Completely correct
   - 0.5 = Partially correct with some errors
   - 0.0 = Factually wrong or misleading

2. Relevance (0.0-1.0): Does the response address the query?
   - 1.0 = Directly and completely answers the question
   - 0.5 = Partially addresses the question
   - 0.0 = Off-topic or misunderstood the question

3. Faithfulness (0.0-1.0): Are claims grounded in the context?
   - 1.0 = All claims supported by provided context
   - 0.5 = Mix of grounded and ungrounded claims
   - 0.0 = Claims contradict or go beyond the context
   (Score 0.7 if no context was provided — can't verify grounding)

Output as JSON:
{{
  "correctness": X.X,
  "relevance": X.X,
  "faithfulness": X.X,
  "reasoning": "Brief explanation of scores"
}}"""

        result = self.client.models.generate_content(model=self.judge_model_name, contents=eval_prompt)

        # Parse JSON response
        match = re.search(r'\{[\s\S]+\}', result.text)
        if match:
            scores = json.loads(match.group())
        else:
            scores = {"correctness": 0.5, "relevance": 0.5, "faithfulness": 0.5, "reasoning": "Parse error"}

        overall = (scores["correctness"] + scores["relevance"] + scores["faithfulness"]) / 3

        return EvaluationResult(
            query=query,
            response=response,
            reference_answer=reference_answer,
            correctness=scores["correctness"],
            relevance=scores["relevance"],
            faithfulness=scores["faithfulness"],
            overall_score=overall,
            reasoning=scores.get("reasoning", ""),
            passed=overall >= 0.7  # 70% threshold
        )

    def evaluate_dataset(
        self,
        test_cases: List[dict],
        agent_fn
    ) -> dict:
        """Evaluate agent across a full test dataset.

        Args:
            test_cases: List of {query, reference_answer, context} dicts
            agent_fn: Function that takes query → response string

        Returns:
            Aggregate evaluation report
        """
        results = []

        for i, test_case in enumerate(test_cases):
            print(f"Evaluating test case {i+1}/{len(test_cases)}...")

            # Get agent response
            response = agent_fn(test_case["query"])

            # Evaluate response
            result = self.evaluate_response(
                query=test_case["query"],
                response=response,
                reference_answer=test_case.get("reference_answer"),
                context=test_case.get("context")
            )
            results.append(result)

        # Aggregate metrics
        passed = sum(1 for r in results if r.passed)
        avg_correctness = sum(r.correctness for r in results) / len(results)
        avg_relevance = sum(r.relevance for r in results) / len(results)
        avg_faithfulness = sum(r.faithfulness for r in results) / len(results)
        avg_overall = sum(r.overall_score for r in results) / len(results)

        # Find problematic cases
        failed_cases = [r for r in results if not r.passed]

        return {
            "total_cases": len(results),
            "passed": passed,
            "pass_rate": f"{passed/len(results):.1%}",
            "avg_correctness": f"{avg_correctness:.2f}",
            "avg_relevance": f"{avg_relevance:.2f}",
            "avg_faithfulness": f"{avg_faithfulness:.2f}",
            "avg_overall": f"{avg_overall:.2f}",
            "failed_cases": [
                {
                    "query": r.query,
                    "score": r.overall_score,
                    "reason": r.reasoning
                }
                for r in failed_cases
            ]
        }

# Example usage
evaluator = AgentEvaluator()

test_cases = [
    {
        "query": "What is the capital of France?",
        "reference_answer": "Paris",
        "context": "France is a country in Western Europe. Its capital and largest city is Paris."
    },
    {
        "query": "Explain how RAG works",
        "reference_answer": "RAG retrieves relevant documents and uses them as context for generation",
        "context": None
    }
]

def my_agent(query: str) -> str:
    client = genai.Client()
    return client.models.generate_content(model='gemini-2.5-flash', contents=query).text

report = evaluator.evaluate_dataset(test_cases, my_agent)
print(f"Pass rate: {report['pass_rate']}")
print(f"Average score: {report['avg_overall']}")

Implementation: Production Monitoring

Agent Telemetry Logger

import time
import json
import logging
from typing import Optional
from dataclasses import dataclass, asdict

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("agent_monitor")

@dataclass
class AgentTrace:
    trace_id: str
    timestamp: float
    query: str
    response: str
    latency_ms: float
    input_tokens: int
    output_tokens: int
    estimated_cost_usd: float
    error: Optional[str] = None
    model: str = "gemini-2.5-flash"

class AgentMonitor:
    """Production monitoring for agent deployments."""

    def __init__(self, alert_thresholds: dict = None):
        self.traces: list = []
        self.thresholds = alert_thresholds or {
            "max_latency_ms": 5000,
            "min_pass_rate": 0.80,
            "max_error_rate": 0.05,
            "max_cost_per_query": 0.01
        }

    def record_trace(self, trace: AgentTrace):
        """Record an agent interaction for monitoring."""
        self.traces.append(trace)

        # Log to observability system (in production: send to Cloud Logging, DataDog, etc.)
        logger.info(json.dumps({
            "event": "agent_trace",
            **asdict(trace)
        }))

        # Real-time alerting
        self._check_alerts(trace)

    def _check_alerts(self, trace: AgentTrace):
        """Check if this trace violates any alert thresholds."""
        if trace.latency_ms > self.thresholds["max_latency_ms"]:
            logger.warning(f"LATENCY ALERT: {trace.latency_ms:.0f}ms > {self.thresholds['max_latency_ms']}ms")

        if trace.estimated_cost_usd > self.thresholds["max_cost_per_query"]:
            logger.warning(f"COST ALERT: ${trace.estimated_cost_usd:.4f} > ${self.thresholds['max_cost_per_query']}")

        if trace.error:
            logger.error(f"AGENT ERROR: {trace.error[:200]}")

    def get_dashboard_stats(self, last_n: int = 100) -> dict:
        """Get dashboard-ready statistics for the last N traces."""
        recent = self.traces[-last_n:] if len(self.traces) > last_n else self.traces
        if not recent:
            return {"message": "No traces recorded yet"}

        errors = [t for t in recent if t.error]
        avg_latency = sum(t.latency_ms for t in recent) / len(recent)
        p95_latency = sorted(t.latency_ms for t in recent)[int(len(recent) * 0.95)]
        total_cost = sum(t.estimated_cost_usd for t in recent)

        return {
            "traces_analyzed": len(recent),
            "avg_latency_ms": f"{avg_latency:.0f}",
            "p95_latency_ms": f"{p95_latency:.0f}",
            "error_rate": f"{len(errors)/len(recent):.1%}",
            "total_cost_usd": f"${total_cost:.4f}",
            "avg_cost_per_query": f"${total_cost/len(recent):.5f}",
            "total_input_tokens": sum(t.input_tokens for t in recent),
            "total_output_tokens": sum(t.output_tokens for t in recent),
            "status": "healthy" if len(errors)/len(recent) < self.thresholds["max_error_rate"] else "degraded"
        }

# Instrumented agent wrapper
def monitored_agent(query: str, agent_fn, monitor: AgentMonitor) -> str:
    """Wrap any agent function with production monitoring."""
    import uuid
    trace_id = str(uuid.uuid4())[:8]
    start_time = time.time()
    error = None
    response = ""
    input_tokens = len(query) // 4  # Estimate
    output_tokens = 0

    try:
        response = agent_fn(query)
        output_tokens = len(response) // 4  # Estimate
    except Exception as e:
        error = str(e)
        response = "An error occurred. Please try again."

    latency_ms = (time.time() - start_time) * 1000

    trace = AgentTrace(
        trace_id=trace_id,
        timestamp=start_time,
        query=query,
        response=response[:500],  # Truncate for storage
        latency_ms=latency_ms,
        input_tokens=input_tokens,
        output_tokens=output_tokens,
        estimated_cost_usd=(input_tokens / 1000 * 0.00015) + (output_tokens / 1000 * 0.0006),
        error=error
    )

    monitor.record_trace(trace)
    return response

Pattern-Specific Evaluation Criteria

The dimensions above apply universally. When evaluating agents built with a specific pattern, add these targeted metrics.

RAG

MetricWhat to MeasureMethod
Retrieval relevanceAre retrieved documents relevant to the query?precision@k, recall@k
FaithfulnessDoes the answer stay within the retrieved context?Claim extraction + context overlap
Hallucination rate% of responses with claims not grounded in contextLLM-as-judge (flag unsupported claims)
Answer correctnessDoes the final answer match ground truth?Exact match or LLM-as-judge

Minimum test set: queries paired with known ground truth answers and their correct source documents.


Routing

MetricWhat to MeasureMethod
Routing accuracy% of requests sent to the correct handlerLabel vs. routed-to comparison
Misroute rateHow often an incorrect handler receives a requestCount of label ≠ route
Confidence calibrationWhen uncertain, does the router still route correctly?Confidence score vs. accuracy correlation
Edge case handlingDoes ambiguous input fail gracefully, not silently?Manual adversarial test cases

Minimum test set: labeled queries with the correct handler pre-assigned for each.


Exception Handling

MetricWhat to MeasureMethod
Retry success rate% of initially-failed requests that succeed after retryInject failures, count recoveries
Fallback activation rateHow often fallback triggers vs. expected frequencyCompare to baseline failure rate
Recovery latencyTime from failure to successful responseP50/P95 timing across failure scenarios
False positive rateIs the circuit breaker opening too aggressively?Count unnecessary circuit opens

Minimum test set: simulated failure scenarios — timeouts, malformed responses, rate limit errors.


Multi-Agent Collaboration

MetricWhat to MeasureMethod
Task completion rate% of multi-step tasks reaching a final resultEnd-to-end task success count
Subtask qualityIs each agent's individual output correct?Per-agent LLM-as-judge
Termination safetyDoes the system terminate within a bounded number of steps?Step counter with max-step limit
Handoff fidelityIs context preserved correctly across agent handoffs?Compare input/output at each handoff boundary

Minimum test set: complex tasks requiring at least 3 agent handoffs with verifiable intermediate outputs.


When to add eval for other patterns: Prioritize patterns where quality can be measured quantitatively. Patterns like reflection, planning, and guardrails each have natural metrics — output improvement rate, plan step coverage, and policy violation rate respectively.

Key Takeaways

  • Golden datasets: Curate representative test cases with reference answers — these are your ground truth
  • LLM-as-judge: Use a separate LLM to evaluate responses — scalable and correlates well with human judgment
  • Three core metrics: Correctness, relevance, faithfulness cover most quality dimensions for RAG+generation agents
  • Monitor in production: Offline evals aren't enough — instrument every production query
  • Latency + cost + quality: Don't optimize one metric at the expense of others — track the triad
  • Alert thresholds: Define what triggers an alert before deployment — not after an incident

Anti-Patterns to Avoid

  • Evaluating only happy paths: Test edge cases, ambiguous queries, and adversarial inputs
  • Single-metric optimization: Maximizing accuracy while ignoring latency/cost leads to unusable systems
  • No production monitoring: Eval benchmarks ≠ production performance — real traffic behaves differently
  • Ignoring failed evaluations: Every failed test case is a debugging opportunity — investigate them
  • Self-evaluation: Don't use the same model to evaluate its own outputs — use a separate judge

Related Skills

Combine this skill with others for common scenarios:

ScenarioSkills to Combine
Continuous quality improvement loopEvaluation + Reflection + Learning & Adaptation
Production monitoring stackEvaluation + Exception Handling + Resource-Aware
Safe agent with metricsEvaluation + Guardrails + Human-in-the-Loop
RAG pipeline quality assuranceEvaluation + RAG + Prompt Chaining

References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.