Overview

10 Agent reasoning and evaluation

This chapter moves from agent memory and retrieval to the capstone capability of planning, which blends reasoning, understanding, evaluation, and feedback. It shows how prompt engineering can extend large language models beyond simple completion into structured thinking and action selection, using practical orchestration with tools like Prompt Flow and Semantic Kernel. The material frames a progression of strategies—ranging from direct prompts to multi-step reasoning and evaluative workflows—aimed at producing more reliable, goal-directed behavior in agents.

The chapter first grounds planning in direct solution prompting styles: question–answer prompts that use provided context and simple similarity-based evaluation; few-shot prompts that imprint patterns and personas to induce behaviors not in pretraining; and zero-shot prompts that leverage generalization for tasks like classification with minimal instruction. It then escalates to reasoning techniques: Chain-of-Thought with worked examples to model stepwise logic; zero-shot CoT triggered by “think step by step” cues; and prompt chaining that decomposes problems, computes intermediate results, and synthesizes final answers. Challenging time-travel scenarios serve as a consistent testbed, illustrating how these formats expose reasoning processes yet may still falter or become verbose without safeguards.

To improve reliability, the chapter introduces evaluation-centric methods. Self-consistency generates multiple solutions at higher diversity, embeds and compares them, and selects the most coherent outcome, simulated via batch runs in a DAG-style workflow. Tree of Thought integrates branching generation with evaluation at each stage, pruning weaker paths and advancing stronger ones in a breadth-first fashion through reusable semantic functions and thresholded scoring—more capable on hard problems but costlier in compute. The overarching lesson is to pair reasoning-oriented prompts with systematic evaluation and adaptive feedback so agents converge on accurate, consistent plans across varied problem classes.

How the two planning prompt engineering strategies align with the various techniques and how we will explore them in this chapter (and later ones)
The flow.dag.yaml, open in the visual editor, and highlighting the various components of the flow
The complexity of the time travel problems we intend to solve using LLMs with reasoning and planning
The flow of the Chain of Thought
The prompt chaining flow
Comparing the various prompt engineering strategies to enable reasoning and planning from LLMs
The self-consistency prompt generation beside the evaluation flow
The step by step process of launching a batch process
The VS Code is open to the batch run output folder. Highlighted are the metrics.json file and the output showing the most similar answer.
Breadth versus depth-first execution on Tree of Thought pattern
Tree-of-Thought pattern expressed and Prompt Flow flow.

Summary

  • Direct solution prompting is a foundational method of using prompts to direct LLMs toward solving specific problems or tasks, emphasizing the importance of clear question-and-answer structures.
  • Few-shot prompting provides LLMs with a few examples to guide them in handling new or unseen content, highlighting its power in enabling the model to adapt to unfamiliar patterns.
  • Zero-shot learning and prompting demonstrate how LLMs can generalize from their training to solve problems without needing explicit examples, showcasing their inherent ability to understand and apply knowledge in new contexts.
  • Chain of thought prompting guides the LLMs through a reasoning process step-by-step to solve complex problems, illustrating how to elicit detailed reasoning from the model.
  • Prompt chaining breaks down a problem into a series of prompts that build upon each other, showing how to structure complex problem-solving processes into manageable steps for LLMs.
  • Self-consistency is a prompt technique that generates multiple solutions to a problem and selects the most consistent answer through evaluation, emphasizing the importance of consistency in achieving reliable outcomes.
  • Tree of thought prompting combines self-evaluation and prompt chaining to create a comprehensive strategy for tackling complex problems, allowing for a systematic exploration of multiple solution paths.
  • Advanced prompt engineering strategies provide insights into sophisticated techniques like self-consistency with CoT and Tree of Thought, offering methods to increase the accuracy and reliability of LLM-generated solutions.

FAQ

What are the main prompting strategies covered in this chapter (direct, few-shot, and zero-shot), and how do they differ?Direct solution prompting answers a question directly with provided context. Few-shot prompting supplies a few examples to teach a pattern or behavior the model can generalize to new inputs. Zero-shot prompting gives rules or labels (no examples) and relies on the model’s prior knowledge to generalize, e.g., sentiment classification into neutral/negative/positive.
How does Prompt Flow structure a basic Q&A evaluation pipeline?Prompt Flow uses a DAG of blocks: an LLM prompt generates an answer, embeddings are computed for both the predicted and expected answers, and a Python tool computes similarity (e.g., cosine) to produce an evaluation_score. This provides a quick, automated measure of answer quality.
What is Chain-of-Thought (CoT) prompting and why is it useful?CoT includes one or more examples that explicitly show reasoning steps before the final answer. By modeling step-by-step thinking, the LLM can generalize the reasoning process to similar problems, improving performance on logic-like tasks (e.g., time-travel word problems). It can be more accurate but costs more tokens.
What is Zero-shot Chain-of-Thought and how does the phrase “Let’s think step by step” help?Zero-shot CoT elicits reasoning without examples by prompting the model to think in steps (e.g., “Let’s think step by step”). This often improves logical coherence while keeping prompts compact. Adding “Provide the final answer in a single statement” can make evaluation easier.
What is prompt chaining and when should I use it?Prompt chaining decomposes a problem into multiple prompts: 1) decompose steps, 2) calculate each step, 3) produce a final solution. It enforces staged reasoning and improves transparency. It can still be verbose and not always correct, but it’s useful when you want to audit intermediate reasoning.
How is self-consistency prompting implemented and evaluated in Prompt Flow?Self-consistency generates multiple answers (e.g., via batch runs at higher temperature) and then selects the most consistent one by embedding each answer and picking the response most similar to others (e.g., using mean embedding and cosine similarity). It tends to help on simpler problems and offers a lightweight ensemble.
What is Tree-of-Thought (ToT) prompting and how is it executed here?ToT explores multiple candidate thoughts at each step (forming a tree) and evaluates them, pruning weak branches. In Prompt Flow, a breadth-first approximation is implemented with semantic functions that gate generation using an evaluation function; failing nodes stop propagating. It’s powerful but can be expensive (many LLM calls).
How are embeddings and similarity scores used for evaluation, and what are their limitations?Embeddings convert text into vectors; cosine similarity measures closeness between predicted and expected outputs. It’s fast and model-agnostic, but can over-score verbose or paraphrased answers and may miss exactness, numeric correctness, or step validity. Complement with stricter evaluators or require final concise answers.
How do reasoning and planning differ, and how do they relate to agent behavior?Reasoning is thinking through actions and consequences to solve a task; planning orders actions and parameters to reach a goal (from strategic to operational). Prompting techniques (CoT, zero-shot CoT, chaining, self-consistency, ToT) help LLMs approximate reasoning and planning within agent pipelines.
What practical tips improve accuracy on complex problems like the time-travel tasks?- Provide or elicit step-by-step reasoning (CoT/zero-shot CoT) and require a single final answer line - Use prompt chaining to force decomposition and calculation stages - Run self-consistency or ToT for exploration and pruning - Tune temperature (higher for diversity in self-consistency; lower for determinism) - Add targeted examples (few-shot) for the specific problem pattern - Validate with multiple evaluators, not just similarity