liveBook · Manning

Evaluation and feedback

As explained in AI Agents in Action, Second Edition

Evaluation and feedback are mechanisms for assessing agent behavior and supplying signals that guide improvement or correction.

An agent can produce an answer without knowing whether it met the goal. Evaluation checks its behavior; feedback supplies information for correction. Together they make failures visible and improvement measurable. They are one of five functional agent layers, but they cannot compensate for a poorly designed agent. section 1.3 section 7.0

Use different checks for different questions:

  • Benchmarks ask whether the agent completes representative tasks. Include wrong examples, rerun tests to check consistency, and watch latency and token use as well as accuracy. section 7.6
  • Red team tests probe safety failures; grounding checks ask whether an answer is supported by its supplied context or citations. section 7.6
  • Human reviews, verified user feedback, and evaluator agents provide signals for cases that simple pass/fail tests cannot capture. A rubric gives an evaluator criteria and a scoring scale. section 7.0 section 7.6
  • Traces record prompts, tool calls, outcomes, token counts, and latency so a failure can be investigated rather than guessed at. section 11.1.5

A practical starting point is basic logging, a curated test set, and simple guardrails. Before changing a prompt or model, define what should pass; run the tests, make the smallest useful change, and retest. As the system grows, add checks for each change and collect human feedback. Keep evaluation connected to the agent’s learn-and-correct loop rather than treating a passing test as a one-time certificate. section 11.1.5 section 7.6

Block an unsupported answer

Suppose a retrieval-augmented generation (RAG) agent answers from retrieved knowledge. An output guardrail sends its question and answer to a grounding agent, which returns a grounded/not-grounded result and feedback. If the answer fails, a tripwire can block it and return “No grounded answer available.” The feedback could instead be used for another attempt. This is evaluation at the point of delivery, not just during testing. section 7.3.3

Listing 7.9 06_RAG_grounding_guardrail_agent.py (guardrail)
@output_guardrail    #1
async def ground_answer(
    context: RunContextWrapper, agent: Agent, output: AnswerResult
) -> GuardrailFunctionOutput:
    grounding_input = dict(
        question=output.question,
        answer=output.answer,
    )
    result = await Runner.run(    #2
             grounding_agent, input=str(grounding_input))
    result = result.final_output

    return GuardrailFunctionOutput(    #3
        output_info={
            "answer_is_grounded": result.is_answer_grounded,
            "feedback": result.feedback,
        },
        tripwire_triggered=result.is_answer_grounded is False,    #4
    )

agent = Agent(
    name="RAG Agent",
    instructions="""
You are a retrieval-augmented knowledge agent.
Break down the user's query into smaller parts if needed
to fetch relevant context for the user's query.
""",
    output_type=AnswerResult,
    tools=[search_knowledge_by_keyword],
    model="gpt-4o",  # Specify the model to use
    output_guardrails=[ground_answer],    #5
)

Inspect the guardrail function to see where the grounding result and feedback become a tripwire decision. section 7.3.3

For broader diagnosis, OpenAI Agents SDK tracing exposes agent activity, while Phoenix can capture traces and support experiments and evaluators. Choose checks that answer a specific question, and decide what happens on failure: retry, block, or surface feedback for review. section 7.4 section 7.6

How AI Agents in Action, Second Edition covers it

How deep it goes
Develops test-driven iteration, feedback sources, runtime guardrails, tracing, and failure responses; warns that evaluation cannot repair poor architecture.
Examples
Uses a RAG grounding guardrail that trips on unsupported answers and returns a static response or feedback for retry.
What you can do after
Apply it via curated tests, tracing, human feedback, and output guardrails to diagnose failures and guide iterative changes.
How it connects
Connects benchmarks, red team testing, grounding, guardrails, human-in-the-loop review, and observability to the agentic learn step.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.