LangGraph - Planning Agents
AI Summary
Summary: Creating Plan and Execute Style Agents in L Graph
- Introduction
- Will from Lang chain introduces how to create plan and execute style agents using L graph.
- L graph is a framework on top of Lang chain core, offering a graph-based syntax for building agents and state machines.
- Plan and Execute Style Agents
- These agents are closer to being production-ready.
- Benefits include faster execution, lower token costs, and better reliability.
- Background on LLM Agents
- Example: REACT paper by Sh Ya from Princeton, which prompts language models to reason and output actions for real-world applications.
- Limitations of Previous Generations
- Require an LLM for each tool invocation, leading to slow serial execution.
- Only execute one step at a time, potentially resulting in shortsighted decisions.
- Plan and Execute Design Pattern
- Breaks down agents into planner, executors, and optional replanner modules.
- The planner generates a plan based on user input and environmental cues.
- Executors perform tasks, and replanner decides whether to generate a new plan.
- Example Implementation
- Setup includes populating API keys and setting up tracing with Lang Smith for debugging.
- Main components: planner, tool executors, and agent executor.
- The agent executor divides tasks and uses tools to answer questions.
- L Graph State
- Each node represents a module (planner, executor, solver).
- Nodes receive state, process it, and update the state to proceed with computation.
- Structured Output and Replanning
- Structured output runnables use function calling to generate structured output from prompts.
- Replanner updates the plan or responds based on the results of executed tasks.
- Creating the Graph
- Nodes for planning, executing, and replanning are defined.
- Conditional edges determine whether to end the process or continue.
- Executing the Agent
- Configuration sets a recursion limit to avoid continuous LLM calls.
- Input is provided, and outputs are streamed for monitoring.
- Debugging with Lang Smith
- Allows observation of the agent’s progress and decision-making process.
- Helps identify areas for improvement in agent efficiency.
- Further Improvements
- Variable substitution in planning allows for more efficient execution.
- Streaming tasks in the form of a DAG and executing tasks as soon as dependencies are met can speed up the process.
- Conclusion
- These agents represent progress towards more robust and effective LLM-based decision-making systems.
- Implementing in L graph is recommended, potentially combining different approaches for optimization.
- Additional Resources
- Lang Smith is available for debugging LLM workflows without a waitlist.