llmauditor.go

Overview

This file implements an LLM Auditor Agent that evaluates answers generated by large language models (LLMs) through a two-step process involving critique and revision. It provides a structured framework for auditing LLM outputs by leveraging specialized sub-agents:

  1. Critic Agent: Reviews a question-answer pair, identifies claims, verifies their accuracy or reliability, and produces a detailed assessment with justifications and references.

  2. Reviser Agent: Takes the critic's findings and minimally revises the original answer text to correct inaccuracies or improve balance while preserving style and length.

The file defines the core prompt templates, callback functions to process model responses, and a factory function to instantiate the auditor agent as a sequential composition of the critic and reviser sub-agents.

This agent is designed to be integrated into workflows requiring high-trust verification of LLM-generated content, particularly in journalistic or editorial contexts where factual accuracy and transparency are critical.


Constants


Functions

afterCritic

func afterCritic(ctx agent.CallbackContext, llmResponse *model.LLMResponse, llmResponseError error) (*model.LLMResponse, error)

afterReviser

func afterReviser(ctx agent.CallbackContext, llmResponse *model.LLMResponse, llmResponseError error) (*model.LLMResponse, error)

GetLLMAuditorAgent

func GetLLMAuditorAgent(ctx context.Context, model model.LLM) agent.Agent

Implementation Details and Algorithms


Interaction with Other System Components


Usage Example

ctx := context.Background()
model := YourLLMImplementation{} // satisfies model.LLM interface

llmAuditor := GetLLMAuditorAgent(ctx, model)

// Use llmAuditor to evaluate question-answer pairs.
// The agent first critiques the answer, then revises it based on findings.

Mermaid Diagram

classDiagram
class LLMAuditorAgent {
+GetLLMAuditorAgent(ctx, model) Agent
}
class CriticAgent {
+CriticPrompt: string
+afterCritic(ctx, llmResponse, err) (*LLMResponse, error)
}
class ReviserAgent {
+ReviserPrompt: string
+afterReviser(ctx, llmResponse, err) (*LLMResponse, error)
}
class SequentialAgent {
+SubAgents: []Agent
}
LLMAuditorAgent --> SequentialAgent : creates
SequentialAgent --> CriticAgent : runs first
SequentialAgent --> ReviserAgent : runs second
CriticAgent --> afterCritic
ReviserAgent --> afterReviser

This documentation covers all significant aspects of the llmauditor.go file, including purpose, key functions, implementation details, system interactions, and a structural diagram. For details on the agent framework, lifecycle callbacks, and sequential agents, refer to LLM Integration and Agents, Agent Lifecycle and Callbacks, and Sequential Agent.