05. Plan-and-Execute

Plan-and-Execute

This tutorial introduces how to make an "plan-and-execute" style agent, which LangGraph Describe the process of utilizing and implementing step by step. The "plan-and-execute" strategy is an approach that first establishes a long-term plan when performing complex tasks, then executes that plan step by step and re-modifies the plan as needed.

What is Plan-and-Execute?

"plan-and-execute" is an approach with the following characteristics:

  • Long-term planning : Develop a long-term plan to draw big pictures before performing complex tasks.

  • Step-by-step execution and re-planning : You can run the plan you have made step by step, review each step to see if the plan is still valid, and then modify it.

This way Plan-and-Solve papers and Baby-AGI Project Inspired by traditional ReAct style The agent thinks one step at a time, while "plan-and-execute" emphasizes explicit and long-term planning.

Advantages : One. Explicit long-term planning : Even a strong LLM can have a hard time dealing with long-term plans at once. By explicitly establishing a long-term plan, more stable progress is possible. 2. Efficient model use : You can optimize resource consumption by using a larger/stronger model in the planning phase, and a relatively small/weak model in the execution phase.


Main contents

  • Tool definition : Define tools to use

  • Define executing agents : Create an agent that runs real jobs

  • Status definition : Define the agent's state

  • Planning phase : Create steps to make long-term plans

  • Replanning phase : Create steps to re-correct the plan according to the progress of the work

  • Graph creation and execution : Create and run graphs linking these steps


Reference

From now on, we will follow each step and take a closer look at how to implement the "plan-and-execute" agent with LangGraph.

Preferences

Define model names to use for practice

Tool definition

Define the tools to use first. In this simple example Tavily We will use the built-in search tool provided through. However, it is also very easy to make your own tools.

More details Tools See documentation.

Define job execution agent

Now run the job execution agent Generate.

In this example, it is the same for each task execution agent I'm going to use it, but I don't necessarily have to do this.

Status definition

  • input : User input

  • plan : Current plan

  • past_steps : Previously executed plans and execution results

  • response : Final response

Plan phase

now Planning phase Let's consider how to generate. At this stage function calling Use to plan.

planner Run to confirm the results of the plan.

Re-Plan phase

Now create a step to re-establish the plan based on the results of the previous step.

Graph generation

Now you can create a graph.

Graph generation

Now connect the nodes you have defined so far to generate graphs.

Visualize the graph.

Graph execution

Last updated