avatarLaxfed Paulacy

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1881

Abstract

h, and it can be compiled into a runnable for execution.</p><h2 id="a351">Examples</h2><h2 id="2962">StateGraph</h2><div id="01bd"><pre><span class="hljs-title">from</span> langgraph.graph <span class="hljs-keyword">import</span> StateGraph <span class="hljs-title">from</span> typing <span class="hljs-keyword">import</span> TypedDict, List, Annotated <span class="hljs-keyword">import</span> Operator <span class="hljs-class"> <span class="hljs-keyword">class</span> <span class="hljs-type">State</span>(<span class="hljs-type">TypedDict</span>): input: str all_actions: <span class="hljs-type">Annotated</span>[<span class="hljs-type">List</span>[str], operator.add]

graph = <span class="hljs-type">StateGraph</span>(<span class="hljs-type">State</span>)</span></pre></div><h2 id="bc8d">Adding Nodes</h2><div id="5d3c"><pre><span class="hljs-keyword">graph</span>.add_node(<span class="hljs-string">"model"</span>, model) <span class="hljs-keyword">graph</span>.add_node(<span class="hljs-string">"tools"</span>, tool_executor)</pre></div><h2 id="f36a">Adding Edges</h2><div id="9059"><pre><span class="hljs-keyword">graph</span>.set_entry_point(<span class="hljs-string">"model"</span>)

<span class="hljs-keyword">graph</span>.add_edge(<span class="hljs-string">"tools"</span>, <span class="hljs-string">"model"</span>)

<span class="hljs-keyword">graph</span>.add_conditional_edge( <span class="hljs-string">"model"</span>, should_continue, { <span class="hljs-string">"end"</span>: END, <span class="hljs-string">"continue"</span>: <span class="hljs-string">"tools"</span> } )</pre></div><h2 id="77e6">Compile</h2><div id="d12e"><pre><span class="hljs-attribute">app</span> <span class="hljs-operator">=</span> graph.compile()</pre></div><h2 id="f577">Agent Executor</h2><p id="f460">LangGraph provides a way to recreate the LangChai

Options

n AgentExecutor. It allows modification of the internals of the AgentExecutor and contains familiar state concepts.</p><h2 id="504d">Chat Agent Executor</h2><p id="df28">For models operating on a list of messages, LangGraph provides an agent runtime that works with this state.</p><h2 id="b5e9">Modifications</h2><p id="fbed">LangGraph exposes the logic of AgentExecutor in a more natural and modifiable way. Examples include forcing the agent to call a tool first, adding a human-in-the-loop step, and managing agent steps.</p><h2 id="bd5f">Future Work</h2><p id="e1d5">Future implementations include more advanced agent runtimes from academia, stateful tools, more controlled human-in-the-loop workflows, and multi-agent workflows.</p><div id="c04b" class="link-block"> <a href="https://readmedium.com/langchain-langchain-partners-with-commandbar-on-their-copilot-user-assistant-15ca5ce93590"> <div> <div> <h2>LANGCHAIN — LangChain Partners with CommandBar on Their CoPilot User Assistant</h2> <div><h3>The most dangerous phrase in the language is, ‘We’ve always done it this way.’ — Grace Hopper.</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*nu7ZXSdSXeo6aCLEJYoZpg.jpeg)"></div> </div> </div> </a> </div><p id="b95b">LangGraph offers a powerful way to create custom and powerful agent runtimes, and users are encouraged to explore and contribute examples to the LangGraph repository or reach out at [email protected] for collaboration.</p><p id="8c07">In conclusion, LangGraph opens new possibilities for creating agent runtimes and offers a platform for collaboration and further development.</p></article></body>

LANGCHAIN — What Is LangGraph?

The advance of technology is based on making it fit in so that you don’t really even notice it, so it’s part of everyday life. — Bill Gates

LangGraph is a module built on top of LangChain to better enable the creation of cyclical graphs, often needed for agent runtimes. It adds new value primarily through the introduction of an easy way to create cyclical graphs, which is often useful when creating agent runtimes.

Motivation

LangGraph addresses the need for introducing cycles into the LangChain directed acyclic graphs (DAGs). It aims to facilitate the creation of agent runtimes that use the LangChain Language Model (LLM) to reason about the next steps in the cycle.

Functionality

At its core, LangGraph exposes a narrow interface on top of LangChain. The primary class is StateGraph, which represents the graph and can be initialized with a state definition. Nodes and edges can be added to create the graph, and it can be compiled into a runnable for execution.

Examples

StateGraph

from langgraph.graph import StateGraph
from typing import TypedDict, List, Annotated
import Operator

class State(TypedDict):
    input: str
    all_actions: Annotated[List[str], operator.add]

graph = StateGraph(State)

Adding Nodes

graph.add_node("model", model)
graph.add_node("tools", tool_executor)

Adding Edges

graph.set_entry_point("model")

graph.add_edge("tools", "model")

graph.add_conditional_edge(
    "model",
    should_continue,
    {
        "end": END,
        "continue": "tools"
    }
)

Compile

app = graph.compile()

Agent Executor

LangGraph provides a way to recreate the LangChain AgentExecutor. It allows modification of the internals of the AgentExecutor and contains familiar state concepts.

Chat Agent Executor

For models operating on a list of messages, LangGraph provides an agent runtime that works with this state.

Modifications

LangGraph exposes the logic of AgentExecutor in a more natural and modifiable way. Examples include forcing the agent to call a tool first, adding a human-in-the-loop step, and managing agent steps.

Future Work

Future implementations include more advanced agent runtimes from academia, stateful tools, more controlled human-in-the-loop workflows, and multi-agent workflows.

LangGraph offers a powerful way to create custom and powerful agent runtimes, and users are encouraged to explore and contribute examples to the LangGraph repository or reach out at [email protected] for collaboration.

In conclusion, LangGraph opens new possibilities for creating agent runtimes and offers a platform for collaboration and further development.

ChatGPT
Langchain
Recommended from ReadMedium