From f9431241735eb80886b2cd50b5ab1c325dd4e549 Mon Sep 17 00:00:00 2001 From: Sesetti Mohana Krishna Date: Mon, 5 Jan 2026 21:04:45 +0530 Subject: [PATCH 1/2] docs: add VerifierAgent pattern for output verification --- .gitignore | 42 +++----- .../verification/verifier_agent_crew.md | 101 ++++++++++++++++++ .../verification/verifier_agent_crew.py | 48 +++++++++ 3 files changed, 164 insertions(+), 27 deletions(-) create mode 100644 docs/examples/verification/verifier_agent_crew.md create mode 100644 docs/examples/verification/verifier_agent_crew.py diff --git a/.gitignore b/.gitignore index adebfb42c7..b9a75bcaa4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,28 +1,16 @@ -.DS_Store -.pytest_cache -__pycache__ +# Python virtual environment +venv/ +.venv/ + +# Python cache +__pycache__/ +*.pyc + +# Build artifacts +build/ dist/ -.env -assets/* -.idea -test/ -docs_crew/ -chroma.sqlite3 -old_en.json -db/ -test.py -rc-tests/* -*.pkl -temp/* -.vscode/* -crew_tasks_output.json -.codesight -.mypy_cache -.ruff_cache -.venv -test_flow.html -crewairules.mdc -plan.md -conceptual_plan.md -build_image -chromadb-*.lock +*.egg-info/ + +# OS files +.DS_Store +Thumbs.db diff --git a/docs/examples/verification/verifier_agent_crew.md b/docs/examples/verification/verifier_agent_crew.md new file mode 100644 index 0000000000..6305564f37 --- /dev/null +++ b/docs/examples/verification/verifier_agent_crew.md @@ -0,0 +1,101 @@ +# VerifierAgent Pattern: Validating Agent Outputs in CrewAI + +## Overview + +In multi-agent systems, Large Language Model (LLM) agents may generate outputs that are +factually incorrect, inconsistent, or hallucinated. While CrewAI enables powerful +agent orchestration, it does not enforce output validation by default. + +This example demonstrates a **VerifierAgent pattern**, where a secondary agent is used +to evaluate and validate the output of a primary agent before it is accepted or used +downstream. + +--- + +## Problem + +- LLM agents can hallucinate facts +- Incorrect outputs may propagate through agent pipelines +- High-stakes workflows require an additional validation step + +Without verification, agent-based systems risk producing unreliable results. + +--- + +## Solution: VerifierAgent Pattern + +The VerifierAgent pattern introduces a dedicated agent responsible for: +- Fact-checking +- Logical validation +- Hallucination detection +- Confidence scoring + +This separates **generation** from **verification**, improving overall reliability. + +--- + +## Architecture + +```text +User Query + ↓ +Generator Agent + ↓ +Verifier Agent + ↓ +Decision (Accept / Reject / Revise) +``` +## How It Works + +A Generator Agent produces an initial response. + +A Verifier Agent reviews the response for factual accuracy and consistency. + +The Verifier Agent returns a structured evaluation. + +The result can be used to accept, reject, or revise the output. + +## Example Implementation + +A runnable example is provided in: + +verifier_agent_crew.py +This example includes: + +One Generator Agent + +One Verifier Agent + +Sequential task execution + + +## Sample Output + + +{ + "verdict": "incorrect", + "confidence": 0.45, + "issues": [ + "Incorrect factual claim regarding climate change causes" + ], + "suggested_fix": "Revise the response using verified scientific sources" +} + + +## When to Use This Pattern +Research assistants + +Enterprise decision systems + +RAG pipelines + +High-stakes AI workflows + +Multi-agent collaboration systems + +## Limitations +Verification quality depends on the underlying LLM + +This pattern reduces risk but does not guarantee correctness + +For critical applications, combine with external tools or trusted data sources \ No newline at end of file diff --git a/docs/examples/verification/verifier_agent_crew.py b/docs/examples/verification/verifier_agent_crew.py new file mode 100644 index 0000000000..7e8b556cea --- /dev/null +++ b/docs/examples/verification/verifier_agent_crew.py @@ -0,0 +1,48 @@ +from crewai import Agent, Task, Crew, Process + +# ----------------------------- +# Agents +# ----------------------------- +generator_agent = Agent( + role="Content Generator", + goal="Generate a clear and accurate answer to the given question", + backstory="Expert assistant generating initial responses", + verbose=True +) + +verifier_agent = Agent( + role="Verifier Agent", + goal="Verify factual accuracy and detect hallucinations", + backstory="Critical evaluator of AI outputs", + verbose=True +) + +# ----------------------------- +# Tasks +# ----------------------------- +generate_task = Task( + description="Explain the primary causes of climate change in simple terms.", + expected_output="A factually correct explanation of climate change causes.", + agent=generator_agent +) + +verify_task = Task( + description=( + "Review the previous response for factual accuracy and hallucinations.\n" + "Return JSON with verdict, confidence, issues, suggested_fix." + ), + expected_output="A JSON verification report.", + agent=verifier_agent +) + +# ----------------------------- +# Crew +# ----------------------------- +crew = Crew( + agents=[generator_agent, verifier_agent], + tasks=[generate_task, verify_task], + process=Process.sequential +) + +if __name__ == "__main__": + print(crew.kickoff()) From d6ed1e6776bb1e46d4326bc93f1f48b0d27ce09f Mon Sep 17 00:00:00 2001 From: Sesetti Mohana Krishna Date: Mon, 5 Jan 2026 21:27:06 +0530 Subject: [PATCH 2/2] chore: restore original .gitignore --- .gitignore | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index b9a75bcaa4..adebfb42c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,28 @@ -# Python virtual environment -venv/ -.venv/ - -# Python cache -__pycache__/ -*.pyc - -# Build artifacts -build/ -dist/ -*.egg-info/ - -# OS files .DS_Store -Thumbs.db +.pytest_cache +__pycache__ +dist/ +.env +assets/* +.idea +test/ +docs_crew/ +chroma.sqlite3 +old_en.json +db/ +test.py +rc-tests/* +*.pkl +temp/* +.vscode/* +crew_tasks_output.json +.codesight +.mypy_cache +.ruff_cache +.venv +test_flow.html +crewairules.mdc +plan.md +conceptual_plan.md +build_image +chromadb-*.lock