Wednesday, May 8, 2024

Why LangGraph?

LangGraph is framework agnostic (each node is a regular python function). It extends the core Runnable API (shared interface for streaming, async, and batch calls) to make it easy to:

Seamless state management across multiple turns of conversation or tool usage

The ability to flexibly route between nodes based on dynamic criteria

Smooth switching between LLMs and human intervention

Persistence for long-running, multi-session applications

If you're building a straightforward DAG, Runnables are a great fit. But for more complex, stateful applications with nonlinear flows, LangGraph is the perfect tool for the job.


Runnables:

Independent Units: Runnables are self-contained functions or code blocks that perform specific tasks. They typically don't rely on external state or interact with other Runnables directly.

Simple Actions: Use Runnables for well-defined, atomic actions like:

Data processing steps within a larger workflow.

Calling external APIs or services.

Performing calculations or transformations on data.

Reusable Components: Runnables can be reused across different Langraphs, promoting modularity and code maintainability.


Langraph:

Workflow Orchestration: Langgraph acts as an orchestration engine that defines the overall flow of execution. It connects different Runnables, manages data flow between them, and handles decision-making logic.

Complex Workflows: Use Langgraph to build multi-step workflows involving multiple Runnables, conditional branching, and state management. It provides a structured way to chain actions and manage dependencies.

State Management: Langgraph allows you to manage and pass data (state) between different stages of your workflow. This facilitates communication and data sharing between Runnables.

Choosing the Right Tool:

Here's a simple guideline to help you decide:

If you have a single, well-defined task, use a Runnable.

If you need to chain multiple tasks, manage data flow, or handle decision logic within a complex workflow, use Langraph.


references:

Gemini


No comments:

Post a Comment