0Pricing
AI Agents with LangChain & Autonomous Workflows · Lektion

ReAct- und Plan-and-Execute-Agenten

Verstehen und implementieren Sie fortgeschrittene Agentenarchitekturen, die Reasoning und Aktionen zur Bearbeitung komplexer Aufgaben kombinieren.

ReAct- und Plan-and-Execute-Agenten ist eine kostenlose AI Agents with LangChain & Autonomous Workflows-Lektion auf CoddyKit. Dies ist Lektion 1 von 6. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des AI Agents with LangChain & Autonomous Workflows-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der AI Agents with LangChain & Autonomous Workflows-Kurs umfasst insgesamt 6 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Beyond Simple AI Agents

Welcome to Advanced Agent Architectures! So far, you've learned about basic agents and chains in LangChain. These are great for straightforward tasks.

However, real-world problems can be complex. They often require agents to reason, make decisions, and perform multiple steps to achieve a goal. This is where advanced architectures come in.

Introducing ReAct Agents

One powerful advanced architecture is ReAct, which stands for Reasoning and Acting. It's inspired by how humans solve problems.

  • Reasoning: The agent thinks about the problem, current state, and what to do next.
  • Acting: The agent then performs an action, often by using a tool.

This cycle allows agents to dynamically adapt and solve complex tasks.

The ReAct Loop: Thought, Action, Observation

ReAct agents operate in an iterative loop:

  • Thought: The agent generates a thought, explaining its reasoning and what it plans to do.
  • Action: Based on the thought, the agent chooses a tool and its input (e.g., 'search', 'calculator').
  • Observation: The agent receives the result from the tool's execution.

This loop continues until the agent believes it has enough information to provide a final answer.

ReAct in Action: A Simple Flow

Let's see a simplified Python example of how a ReAct agent's logic might flow. Notice how it thinks, acts, and observes to reach a conclusion.

def run_react_agent(query):
    print(f"User Query: {query}")
    print("Thought: I need to find the population of London. I will use a search tool.")
    print("Action: Use 'search_tool' with query 'population of London'")
    # Simulate tool output
    observation = "Observation: The population of London is ~9 million (2023 est.)."
    print(observation)
    print("Thought: I have the information. I can now answer the user.")
    print("Action: Respond with the observed information.")
    return observation.replace("Observation: ", "")

if __name__ == "__main__":
    result = run_react_agent("What is the population of London?")
    print(f"\nFinal Answer: {result}")

Understanding Plan-and-Execute

Another powerful architecture is Plan-and-Execute. Unlike ReAct, which is more reactive, Plan-and-Execute agents first create a comprehensive plan.

They are particularly effective for tasks that are complex, multi-step, and where a clear sequence of actions can be determined upfront.

The Planner and Executor Components

Plan-and-Execute agents typically consist of two main parts:

  • The Planner: This component takes the initial goal and breaks it down into a sequence of smaller, manageable steps. It focuses on strategy.
  • The Executor: This component then takes each step from the plan and carries it out, often by using specific tools. It focuses on execution.

This separation helps manage complexity and ensures a structured approach.

Plan-and-Execute: A Structured Flow

Here's a simplified Python example illustrating the Plan-and-Execute flow. Notice how the goal is first planned, then each step is executed in order.

def planner(goal):
    print(f"Goal: {goal}")
    print("Planner: Breaking down the goal into steps...")
    plan = [
        "Step 1: Find today's date.",
        "Step 2: Get the weather forecast for New York City for today.",
        "Step 3: Summarize the date and weather information."
    ]
    print(f"Plan created: {plan}")
    return plan

def executor(step):
    print(f"Executing: {step}")
    if "date" in step:
        return "Observation: Today's date is October 26, 2023."
    elif "weather" in step:
        return "Observation: New York weather: Sunny, 60°F."
    elif "summarize" in step:
        return "Observation: Summary: Oct 26, 2023, NYC is Sunny, 60°F."
    return "Observation: Step completed."

if __name__ == "__main__":
    my_goal = "Tell me today's date and weather in New York City."
    plan_steps = planner(my_goal)
    
    print("\n--- Execution Phase ---")
    for step in plan_steps:
        res = executor(step)
        print(res)

ReAct vs. Plan-and-Execute

Both are powerful, but suited for different scenarios:

  • ReAct: More dynamic and reactive. Best for tasks where the path isn't clear upfront, requiring exploration and iterative decision-making (e.g., complex research questions).
  • Plan-and-Execute: More structured and systematic. Best for tasks where a clear sequence of steps can be defined (e.g., booking a flight with known steps: search, select, confirm).

Choosing the Right Architecture

When deciding between ReAct and Plan-and-Execute, consider:

  • Task Complexity: Is it a clear, sequential task (Plan-and-Execute) or an exploratory, problem-solving one (ReAct)?
  • Predictability: Can you easily predict the steps needed (Plan-and-Execute) or will the agent need to adapt dynamically (ReAct)?
  • Error Handling: Plan-and-Execute can sometimes be easier to debug due to defined steps, while ReAct's dynamic nature can be harder to trace.

Quick Check: Agent Architectures

An AI agent needs to solve a complex, multi-step problem where the exact sequence of actions is not known beforehand, and it might need to explore different options and react to intermediate results.

Recap: Advanced Agent Architectures

Great job! In this lesson, you explored two advanced agent architectures:

  • ReAct (Reasoning and Acting): Agents that iteratively think, act, and observe, suitable for dynamic, exploratory tasks.
  • Plan-and-Execute: Agents that first create a detailed plan and then execute each step, ideal for structured, multi-step workflows.

Understanding these patterns helps you build more robust and intelligent AI agents for complex challenges. Next, we'll look at agents that can self-correct!

Häufig gestellte Fragen

Ist die Lektion „ReAct- und Plan-and-Execute-Agenten“ kostenlos?

Ja — der vollständige Text von „ReAct- und Plan-and-Execute-Agenten“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des AI Agents with LangChain & Autonomous Workflows-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der AI Agents with LangChain & Autonomous Workflows-Kurs umfasst insgesamt 6 Lektionen.

Was lerne ich in „ReAct- und Plan-and-Execute-Agenten“?

Verstehen und implementieren Sie fortgeschrittene Agentenarchitekturen, die Reasoning und Aktionen zur Bearbeitung komplexer Aufgaben kombinieren. Du übst AI Agents with LangChain & Autonomous Workflows mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um AI Agents with LangChain & Autonomous Workflows zu starten?

Keine Vorkenntnisse erforderlich. AI Agents with LangChain & Autonomous Workflows auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 6.

Wie lange dauert die Lektion „ReAct- und Plan-and-Execute-Agenten“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser AI Agents with LangChain & Autonomous Workflows-Lektion Code schreiben und ausführen?

Ja. Jede AI Agents with LangChain & Autonomous Workflows-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. ReAct- und Plan-and-Execute-Agenten
  2. Hierarchische Agentenentwürfe
  3. Agenten für Selbstkorrektur und Reflexion
  4. Kognitive Architekturen für Agenten
  5. Muster für die Zusammenarbeit mehrerer Agenten
  6. Hybride Agentensysteme
← Zurück zu AI Agents with LangChain & Autonomous Workflows