
LANGCHAIN — Plan and Execute Agents
Technology makes it possible for people to gain control over everything, except over technology. — John Tudor.
In this article, we’ll explore the implementation of “Plan-and-Execute” agents in LangChain. These agents are designed to handle more complex long-term planning, at the cost of making more calls to the language model. The Plan-and-Execute framework separates higher-level planning from shorter-term execution, aiming to increase reliability and handle increasingly complex user objectives. Let’s dive into the implementation of Plan-and-Execute agents in Python and TypeScript.
Plan-and-Execute Agent Implementation
The Plan-and-Execute agent framework relies on two key components: a planner and an executor.
Planner
The planner, often based on a language model, is responsible for high-level planning and dealing with ambiguity/edge cases. The output parser is used to parse the raw LLM output into a list of strings, with each string representing a step.
# Python planner implementation
def plan_with_language_model(objective):
# Utilize the language model's reasoning ability to plan out the steps
# Parse the raw LLM output into a list of strings (each string being a step)
# Return the list of planned steps
passExecutor
The initial implementation of the executor is an Action Agent, which determines the tools to use to accomplish the high-level objective.
// TypeScript executor implementation
function executeWithActionAgent(step: string) {
// Determine the tools or the best course of action to accomplish the step
// Execute the step using the selected tools
}This separation of planning from execution allows for more reliability on both fronts and makes it easier to swap out components for smaller, fine-tuned models. However, this approach requires more calls due to the separation of concerns.
Future Directions
The future directions for the Plan-and-Execute agent framework include:
Better support for long sequences of steps
As planning steps get longer, we may want to store intermediate steps in a vectorstore and retrieve them as needed.
Revisiting plans
Having a mechanism for revisiting and adjusting the plan, either every step or as needed, can improve the adaptability of the agents.
Evaluation
We aim to have more rigorous ways of evaluating agent frameworks, possibly through benchmarking outputs.
Selection of execution chain
Allowing the planner to specify which execution chain to use can enhance the flexibility of the framework.
Conclusion
The introduction of the Plan-and-Execute agent paradigm in LangChain brings promising opportunities for handling complex user objectives and increasing reliability. The separation of planning and execution lays the groundwork for future enhancements and fine-tuning. To explore the Plan-and-Execute approach further, refer to the Python Documentation and JS/TS Documentation.






