No history yet

Study Guide

đź“– Core Concepts

Advanced agentic workflows transform stateless models into stateful problem-solvers using iterative reasoning, acting, and self-correction loops to improve accuracy on complex tasks.

Agents decompose large goals into smaller, executable steps, dynamically planning and calling external tools like APIs or databases to act upon the real world.

Multi-agent systems orchestrate specialized agents using frameworks like CrewAI or LangGraph, enabling collaborative problem-solving through defined roles and communication protocols to handle complex projects.

Stateful agents maintain memory across sessions using checkpointing and state management, while optimizing for cost and latency by using strategies like small-model-first routing.

Production-grade agents require robust evaluation pipelines, automated error recovery loops, and observability to ensure reliability, safety, and scalability in real-world business applications.

📌 Must Remember

Core Agentic Architecture (ReAct & Reflection)

  1. Performance Shift: A GPT-3.5 model in an agentic loop can outperform a zero-shot GPT-4 by using multiple, focused inference passes instead of one single attempt.
  2. ReAct Loop: The core agent cycle is Reason (think about the next step), Act (execute a tool or generate text), and Observe (analyze the result to inform the next reason step).
  3. Stateful vs. Stateless: Agentic workflows are stateful, meaning they maintain context and memory across steps, unlike stateless zero-shot prompts which have no memory of past interactions.
  4. Self-Correction: Agents improve accuracy via reflection, where they critique their own output (internal) or use external feedback (like unit tests) to trigger a revision cycle.
  5. Discretized Traces: Using JSON or structured code for outputs creates clear, machine-readable traces of an agent's reasoning, which is essential for debugging and evaluation.

Tool Use & Planning

  1. Function Calling: LLMs don't run tools directly; they generate a JSON object specifying the tool name and parameters (e.g., {"tool": "search", "query": "AI agents"}), which the orchestrator executes.
  2. Tool Hallucination: This critical failure mode occurs when an agent tries to call a non-existent tool or provides incorrect parameters; it must be handled with validation and error loops.
  3. Planning Primitives: Chain-of-Thought (CoT) is a basic planning technique where the model thinks step-by-step. More advanced methods like Tree-of-Thought explore multiple reasoning paths.
  4. Dynamic Replanning: An agent doesn't follow a static plan. It must adjust its next steps based on the observations it receives from tool outputs or changes in the environment.
  5. Model as Router: In tool use, the LLM acts as a smart 'routing engine,' deciding which specialized external function is best suited to handle a specific sub-task.

Multi-Agent Systems & Frameworks

  1. Orchestration Patterns: Key patterns include hierarchical (a manager delegates tasks, like in CrewAI) and conversational (agents chat to solve problems, like in AutoGen).
  2. Specialized Personas: Assigning specific roles (e.g., 'Senior Researcher', 'Code Auditor') to different agents with unique prompts and tools dramatically improves the quality of complex work.
  3. Context Drift: A major challenge is ensuring context is not lost or misinterpreted when passed between agents. Minimizing this requires clear communication protocols and state management.
  4. LangGraph: This framework models workflows as a graph or state machine, providing explicit control over cycles, branching, and state, making it ideal for deterministic processes.
  5. CrewAI vs. AutoGen: CrewAI focuses on collaborative role-playing for projects (hierarchical), while AutoGen excels at flexible, conversation-driven problem-solving between agents (conversational).

State, Memory & Optimization

  1. State Persistence: Production agents must be 'stateful,' using databases (like Redis or Postgres) to save their progress (state), allowing them to be paused, resumed, or recover from crashes.
  2. Checkpointing: This is the act of saving the agent's state at critical nodes in the workflow, enabling rollbacks and human-in-the-loop interventions without starting over.
  3. State Reducers: In complex graphs, a 'reducer' function is used to merge the state updates from different branches into a single, consistent state for the next step.
  4. Small Model First Routing: To manage cost and latency, use smaller, faster models (e.g., Llama 3 8B) for simple tasks like classification or planning, and reserve frontier models (e.g., GPT-4o) for complex reasoning.
  5. Context Pruning: Iterative loops can quickly bloat the context window. Strategies like summarizing past steps are crucial for managing token usage and staying within budget.

Evaluation & Production

  1. Evaluation-Driven Development (EDD): Instead of 'vibe-checking,' build a small, high-quality dataset of problems and solutions to objectively measure any changes made to the agent's architecture.
  2. LLM-as-a-Judge: Use a powerful LLM with a detailed rubric to automate the evaluation of complex outputs like reasoning quality or text generation, providing a scalable way to score performance.
  3. Self-Healing Loops: A robust agent handles errors by feeding the error message (e.g., a Python stack trace) back into its context, allowing it to retry the action with corrected parameters.
  4. Observability: In production, you need more than just logs. Traces and spans provide a detailed view of the entire agent workflow, helping to pinpoint latency bottlenecks and failure points.
  5. Enterprise Guardrails: To deploy agents safely, implement strict guardrails that limit which tools can be used, validate outputs before execution, and require human approval for high-stakes actions.

📚 Key Terms

ReAct (Reason + Act): A foundational agentic architecture where the model alternates between generating verbal reasoning traces (Reason) and executing actions in an environment (Act).

  • Used in context: The agent used a ReAct loop to first reason that it needed a user's location, then act by calling the weather API.
  • Don't confuse with: Simple Chain-of-Thought (CoT), which only involves reasoning and does not execute actions.
  • Topic: Core Agentic Architecture (ReAct & Reflection)

Stateful Orchestration: The process of managing an agent's memory and context across multiple steps and sessions, allowing it to build on previous work.

  • Used in context: Stateful orchestration ensured the research agent could be paused overnight and resume its work the next day without losing any findings.
  • Don't confuse with: Stateless inference, where each query is independent and has no memory of past interactions.
  • Topic: State, Memory & Optimization

Tool Hallucination: A critical failure where an LLM attempts to use a tool that does not exist or provides it with incorrectly formatted parameters.

  • Used in context: The agent experienced tool hallucination when it tried to call calculate_stock_price() with a company name instead of a stock ticker symbol.
  • Topic: Tool Use & Planning

Context Drift: The degradation or loss of important information as it is passed between multiple agents in a sequence, leading to errors or irrelevant actions.

  • Used in context: After three agent handoffs, context drift caused the final 'Writer' agent to misunderstand the original goal set by the 'Planner' agent.
  • Topic: Multi-Agent Systems & Frameworks

Self-Healing Loop: An error-handling pattern where a failed tool's error message is fed back to the agent, which then attempts to correct its mistake and retry the action.

  • Used in context: When the SQL query failed, the self-healing loop provided the database error to the agent, which then corrected the syntax and successfully re-ran the query.
  • Topic: Evaluation & Production

LLM-as-a-Judge: A technique for evaluating complex AI outputs by using a powerful LLM (like GPT-4o) with a detailed rubric to score the quality of another model's reasoning or results.

  • Used in context: We used an LLM-as-a-judge to grade the coherence of the research summaries, which was faster and more scalable than human evaluation.
  • Topic: Evaluation & Production

Small Model First Routing: An optimization strategy where simple or preliminary tasks are routed to smaller, faster, and cheaper LLMs, reserving expensive frontier models for only the most complex steps.

  • Used in context: The system used 'Small Model First Routing' to have a 7B model classify user intent before deciding whether to invoke the more powerful GPT-4 for the main task.
  • Topic: State, Memory & Optimization

Checkpointing: The practice of saving the complete state of an agentic workflow at specific points, allowing it to be resumed, rolled back, or inspected by a human.

  • Used in context: The long-running research agent used checkpointing after every major discovery, creating a resilient workflow that could survive system crashes.
  • Topic: State, Memory & Optimization

🔄 Key Processes

The ReAct (Reason + Act) Loop

Step 1: Reason

  • What happens: The agent analyzes the current goal and its observations to generate a thought or a plan for the next action. This is often done using a Chain-of-Thought style prompt.
  • Key indicator: The model's output contains a 'Thought:' block explaining its internal monologue and strategy.
  • Common error: The reasoning is too generic or fails to break the problem down into a small, actionable step.

Step 2: Act

  • What happens: Based on the reasoning, the agent generates a specific action, which is typically a tool call (e.g., search('latest AI research')) or a final answer to the user.
  • Key indicator: The model's output contains an 'Action:' block with a tool name and its parameters, usually in a structured format like JSON.
  • Common error: The agent hallucinates a tool or provides poorly formatted arguments.

Step 3: Observe

  • What happens: The orchestrator executes the action from Step 2 and passes the result (e.g., API response, error message) back to the agent as a new 'Observation'.
  • Key indicator: The context for the next loop contains an 'Observation:' block with the output from the previous action.
  • Common error: The observation is too verbose or lacks the key information needed for the agent to decide the next step.

(The process then returns to Step 1, creating a loop that continues until the task is complete)

Topic: Core Agentic Architecture (ReAct & Reflection)


The Critique-Refinement Cycle

Step 1: Generate Initial Output

  • What happens: The primary agent performs a task and produces a first draft of the output (e.g., a block of code, a SQL query, a paragraph of text).
  • Key indicator: A complete, standalone piece of work is generated.
  • Common error: The initial output contains logical flaws, syntax errors, or factual inaccuracies.

Step 2: Critique

  • What happens: The output is evaluated against a set of rules or criteria. This can be done by the same agent (self-critique) or by an external source like a unit test or a separate 'critic' agent.
  • Key indicator: A list of specific, actionable feedback points is generated (e.g., 'The Python code is missing an import statement,' or 'The SQL query fails on edge cases.').
  • Common error: The critique is too vague ('This is bad') and doesn't provide concrete guidance for improvement.

Step 3: Refine

  • What happens: The primary agent receives the original output and the critique as context. It is then prompted to generate a revised version that addresses the feedback.
  • Key indicator: A new version of the output is produced that incorporates the suggested changes.
  • Common error: The agent 'over-corrects' and introduces new problems while fixing the old ones, or it ignores some of the feedback.

(This cycle can be repeated multiple times until the output passes all evaluation criteria)

Topic: Core Agentic Architecture (ReAct & Reflection)

🔍 Key Comparisons

Orchestration Frameworks: LangGraph vs. CrewAI vs. AutoGen

FeatureLangGraphCrewAIAutoGen
Core PhilosophyState MachineHuman OrganizationConversation
StructureExplicit Graph (Nodes & Edges)Hierarchical (Manager & Roles)Flexible (Agent Chat)
ControlHigh (Deterministic, explicit)Medium (Role-based, structured)Low (Emergent, autonomous)
Best ForReliable, repeatable processes with complex logic and branching (e.g., self-healing loops).Project-based work with specialized roles that mimic a human team (e.g., research and report writing).Open-ended problem solving and rapid prototyping where the solution path is unknown.
Key ComponentStatefulGraphCrew and Agent with RoleConversableAgent

Memory trick: LangGraph is for Logical Graphs. CrewAI is for a Company Crew. AutoGen is for Autonomous Generative conversations.

Topic: Multi-Agent Systems & Frameworks

⚠️ Common Mistakes

❌ MISTAKE: Letting agents run in long, uninterrupted loops without clear exit conditions.

  • Why it happens: Developers assume the agent will eventually determine the task is 'done,' but ambiguity can lead to infinite loops, racking up high costs and never producing a final answer.
  • âś… Instead: Always implement explicit exit conditions. This can be a maximum number of iterations, a check to see if the last action was 'finish', or a token budget limit.
  • Topic: State, Memory & Optimization

❌ MISTAKE: Prompting a 'critic' agent with a generic instruction like 'Is this good?'.

  • Why it happens: Vague prompts lead to vague, unhelpful critiques. The model doesn't know what criteria to evaluate against.
  • âś… Instead: Provide the critic agent with a detailed, specific rubric or checklist. For example: 'Critique this code based on these three criteria: 1. Python PEP 8 compliance. 2. Correct handling of edge cases. 3. Presence of docstrings.'
  • Topic: Core Agentic Architecture (ReAct & Reflection)

❌ MISTAKE: Passing the entire history of an agent's work into every new step.

  • Why it happens: While seeming thorough, this quickly exceeds the context window and fills it with irrelevant early steps, increasing costs and confusing the model.
  • âś… Instead: Implement a context compression strategy. For example, after a few steps, use a separate LLM call to summarize the work so far, and pass that summary forward instead of the full raw history.
  • Topic: State, Memory & Optimization

❌ MISTAKE: Assuming a tool call will always succeed and designing a linear workflow.

  • Why it happens: Real-world tools (APIs, databases) can fail due to network issues, invalid inputs, or authentication problems. A linear plan without error handling is brittle and will break.
  • âś… Instead: Design workflows with branching logic. Use graph-based frameworks like LangGraph to create specific edges for success and failure, allowing the agent to enter a self-healing loop or try an alternative tool if the first one fails.
  • Topic: Evaluation & Production