← Master Index
Vol. 15 Module 15.1 Lecture

Reasoning

Agent Fundamentals

How This Lesson Fits the Module & Volume

Volume 13 taught chain-of-thought, tree-of-thoughts, and prompt-level reflection. In Volume 15, reasoning is that same intermediate inference—but now it sits inside an agent loop that can call tools instead of only emitting text. Planning sets the map; reasoning chooses the next legal move given observations.

ReAct (Reason + Act) is the practical glue: a thought, then a tool call, then a new thought. Later, reflection critiques finished attempts. Module 15.2 memory types store the traces that reasoning needs.

Learning Objectives

By the end of this lesson, students should be able to:

  • Distinguish prompt-only CoT from tool-augmented agent reasoning.
  • Describe the ReAct pattern: Thought → Action → Observation.
  • Decide when to reason vs when to call a tool for facts.
  • Implement a small ReAct-style loop with OpenAI tool calling.
  • Recognize fluent-but-wrong reasoning and ground it with tools.
  • Link reasoning traces to memory, reflection, and eval.
Definition

Reasoning (in agents) is the model’s intermediate inference used to interpret observations, choose among tools or plan steps, and justify a halt or a final answer. Unlike pure CoT, agent reasoning is expected to ground claims in tool results when facts live outside the weights.

CoT vs Agent Reasoning

DimensionPrompt CoT (Vol. 13)Agent reasoning (Vol. 15)
OutputScratchpad + answerThoughts + tool calls + answer
GroundingMostly parametric / prompt contextObservations from tools / RAG
ControlOne completionMulti-step loop
Failure modeWrong chain, still fluentSame, plus wasted tool calls
FixBetter prompts / self-consistencyTools, schemas, halt, reflection

ReAct: Thought → Action → Observation

Do not ask the model to invent order statuses. Ask it to think about which tool to use, call it, then reason over the returned string. Keep user-facing answers short; keep traces in logs (and later in episodic memory).

import json from openai import OpenAI client = OpenAI() TOOLS = [{ "type": "function", "function": { "name": "lookup_sla", "description": "Return SLA hours for a support tier.", "parameters": { "type": "object", "properties": {"tier": {"type": "string", "enum": ["basic", "pro", "enterprise"]}}, "required": ["tier"], }, }, }] def lookup_sla(tier: str) -> str: return {"basic": "48h", "pro": "8h", "enterprise": "1h"}[tier] SYSTEM = """You are a support agent. Reason briefly about what fact you still need. If a fact is not in the conversation, call a tool. After observations, give a concise final answer. Never invent SLAs.""" messages = [ {"role": "system", "content": SYSTEM}, {"role": "user", "content": "How fast must we reply to a Pro customer?"}, ] for step in range(4): msg = client.chat.completions.create( model="gpt-4o-mini", messages=messages, tools=TOOLS ).choices[0].message messages.append(msg) if not msg.tool_calls: print("FINAL:", msg.content) break for call in msg.tool_calls: args = json.loads(call.function.arguments) obs = lookup_sla(**args) messages.append({"role": "tool", "tool_call_id": call.id, "content": obs}) print(f"step {step} thought/tool={call.function.name} args={args} obs={obs}")

When to Think vs When to Act

Reason in-weights

  • Formatting, tone, summaries
  • Logic over already-fetched facts
  • Choosing among known options

Call a tool

  • Live data (orders, SLAs, prices)
  • Math you do not want hallucinated
  • Search / RAG / code execution

Stop

  • Answer is grounded
  • Policy forbids the action
  • Need a human (ambiguity/risk)

Strengths

  • Improves multi-hop tool use
  • Debuggable traces
  • Composes with CoT / ToT skills
  • Feeds reflection and eval

Tradeoffs

  • Tokens and latency
  • Leaking scratchpads to users
  • Confident wrong chains
  • Reasoning instead of retrieving
Common Misconception

“Longer reasoning always yields better agent decisions.” Extra tokens can rationalize a bad tool choice. Prefer short, goal-oriented thoughts plus mandatory tool use for external facts. Measure task success, not thought length.

Knowledge Check

  1. Short Answer: How does agent reasoning differ from Vol. 13 CoT? Answer: It runs in a loop and should ground facts via tools/observations, not only text.
  2. True/False: ReAct interleaves thoughts with actions and observations. Answer: True.
  3. Multiple Choice: Live order status should come from: (a) parametric memory only, (b) a tool/API, (c) CSS. Answer: (b).
  4. Short Answer: What should you do with reasoning traces in production UX? Answer: Log them; show users a concise grounded answer (unless transparency requires more).
  5. True/False: Planning and reasoning are the same module concept. Answer: False—planning structures the task; reasoning infers the next move.
  6. Multiple Choice: Fluent wrong chains are fixed mainly by: (a) bigger fonts, (b) tools + halt + eval, (c) dropping JSON. Answer: (b).
  7. Short Answer: Name the three ReAct beats. Answer: Thought, Action, Observation.
  8. Short Answer: Which later lecture critiques a finished attempt? Answer: Reflection.
  9. Multiple Choice: Module 15.2 helps reasoning by storing: (a) CUDA kernels, (b) memory traces/types, (c) CSS themes. Answer: (b).
  10. True/False: You should invent SLAs if the tool is slow. Answer: False.

Key Takeaways

  • Agent reasoning is CoT-plus-tools: infer, act, observe, infer again.
  • Use tools for external facts; use thoughts for control and synthesis.
  • Keep traces for debug/eval; do not equate verbosity with quality.
  • ReAct feeds planning, the agent loop, reflection, and memory.
  • Next: memory—what the reasoner is allowed to remember.
Trainer’s Guide

Whiteboard: Take a hallucinated SLA answer and rewrite it as a ReAct trace that must call lookup_sla.

Lab: Add a second tool get_tier_for_account. Require the agent to chain both tools before answering.

Recap: Reasoning chooses the next grounded move inside the loop. Continue with Memory.