From 318de5bb81dcf7945fa4f863d229ec8756370861 Mon Sep 17 00:00:00 2001 From: Chester Curme Date: Fri, 17 Jan 2025 13:31:41 -0500 Subject: [PATCH 1/6] update readme --- README.md | 35 +++++++++++++++++++++++++---------- libs/langgraph/README.md | 35 +++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 648f45f4b..9dbafabc1 100644 --- a/README.md +++ b/README.md @@ -12,25 +12,40 @@ ## Overview -[LangGraph](https://langchain-ai.github.io/langgraph/) is a library for building stateful, multi-actor applications with LLMs, used to create agent and multi-agent workflows. Compared to other LLM frameworks, it offers these core benefits: cycles, controllability, and persistence. LangGraph allows you to define flows that involve cycles, essential for most agentic architectures, differentiating it from DAG-based solutions. As a very low-level framework, it provides fine-grained control over both the flow and state of your application, crucial for creating reliable agents. Additionally, LangGraph includes built-in persistence, enabling advanced human-in-the-loop and memory features. +[LangGraph](https://langchain-ai.github.io/langgraph/) is a library for building stateful, multi-actor applications with LLMs, used to create agent and multi-agent workflows. + LangGraph is inspired by [Pregel](https://research.google/pubs/pub37252/) and [Apache Beam](https://beam.apache.org/). The public interface draws inspiration from [NetworkX](https://networkx.org/documentation/latest/). LangGraph is built by LangChain Inc, the creators of LangChain, but can be used without LangChain. -[LangGraph Platform](https://langchain-ai.github.io/langgraph/concepts/langgraph_platform) is infrastructure for deploying LangGraph agents. It is a commercial solution for deploying agentic applications to production, built on the open-source LangGraph framework. The LangGraph Platform consists of several components that work together to support the development, deployment, debugging, and monitoring of LangGraph applications: [LangGraph Server](https://langchain-ai.github.io/langgraph/concepts/langgraph_server) (APIs), [LangGraph SDKs](https://langchain-ai.github.io/langgraph/concepts/sdk) (clients for the APIs), [LangGraph CLI](https://langchain-ai.github.io/langgraph/concepts/langgraph_cli) (command line tool for building the server), [LangGraph Studio](https://langchain-ai.github.io/langgraph/concepts/langgraph_studio) (UI/debugger), +### Why use LangGraph? -To learn more about LangGraph, check out our first LangChain Academy course, *Introduction to LangGraph*, available for free [here](https://academy.langchain.com/courses/intro-to-langgraph). +LangGraph provides fine-grained control over both the flow and state of your +agent applications. It implements a central persistence layer, enabling features that +are common to most agent architectures: -### Key Features +- **Memory**: LangGraph supports conversational memory within and across user +interactions; +- **Human-in-the-loop**: Execution can be interrupted and resumed, allowing for +decisions, validation, and corrections at key stages via human input. -- **Cycles and Branching**: Implement loops and conditionals in your apps. -- **Persistence**: Automatically save state after each step in the graph. Pause and resume the graph execution at any point to support error recovery, human-in-the-loop workflows, time travel and more. -- **Human-in-the-Loop**: Interrupt graph execution to approve or edit next action planned by the agent. -- **Streaming Support**: Stream outputs as they are produced by each node (including token streaming). -- **Integration with LangChain**: LangGraph integrates seamlessly with [LangChain](https://github.com/langchain-ai/langchain/) and [LangSmith](https://docs.smith.langchain.com/) (but does not require them). +Standardizing these components allows individuals and teams to focus on the behavior +of their agent, instead of its supporting infrastructure. + +Through [LangGraph Platform](#langgraph-platform), LangGraph also provides tooling for +debugging, tracing and observability, evaluation, and deployment. + +LangGraph integrates seamlessly with +[LangChain](https://python.langchain.com/docs/introduction/) and +[LangSmith](https://docs.smith.langchain.com/) (but does not require them). + +To learn more about LangGraph, check out our first LangChain Academy +course, *Introduction to LangGraph*, available for free +[here](https://academy.langchain.com/courses/intro-to-langgraph). ### LangGraph Platform -LangGraph Platform is a commercial solution for deploying agentic applications to production, built on the open-source LangGraph framework. +[LangGraph Platform](https://langchain-ai.github.io/langgraph/concepts/langgraph_platform) is infrastructure for deploying LangGraph agents. It is a commercial solution for deploying agentic applications to production, built on the open-source LangGraph framework. The LangGraph Platform consists of several components that work together to support the development, deployment, debugging, and monitoring of LangGraph applications: [LangGraph Server](https://langchain-ai.github.io/langgraph/concepts/langgraph_server) (APIs), [LangGraph SDKs](https://langchain-ai.github.io/langgraph/concepts/sdk) (clients for the APIs), [LangGraph CLI](https://langchain-ai.github.io/langgraph/concepts/langgraph_cli) (command line tool for building the server), and [LangGraph Studio](https://langchain-ai.github.io/langgraph/concepts/langgraph_studio) (UI/debugger). + Here are some common issues that arise in complex deployments, which LangGraph Platform addresses: - **Streaming support**: LangGraph Server provides [multiple streaming modes](https://langchain-ai.github.io/langgraph/concepts/streaming) optimized for various application needs diff --git a/libs/langgraph/README.md b/libs/langgraph/README.md index 648f45f4b..9397bd668 100644 --- a/libs/langgraph/README.md +++ b/libs/langgraph/README.md @@ -12,25 +12,40 @@ ## Overview -[LangGraph](https://langchain-ai.github.io/langgraph/) is a library for building stateful, multi-actor applications with LLMs, used to create agent and multi-agent workflows. Compared to other LLM frameworks, it offers these core benefits: cycles, controllability, and persistence. LangGraph allows you to define flows that involve cycles, essential for most agentic architectures, differentiating it from DAG-based solutions. As a very low-level framework, it provides fine-grained control over both the flow and state of your application, crucial for creating reliable agents. Additionally, LangGraph includes built-in persistence, enabling advanced human-in-the-loop and memory features. +[LangGraph](https://langchain-ai.github.io/langgraph/) is a library for building stateful, multi-actor applications with LLMs, used to create agent and multi-agent workflows. + LangGraph is inspired by [Pregel](https://research.google/pubs/pub37252/) and [Apache Beam](https://beam.apache.org/). The public interface draws inspiration from [NetworkX](https://networkx.org/documentation/latest/). LangGraph is built by LangChain Inc, the creators of LangChain, but can be used without LangChain. -[LangGraph Platform](https://langchain-ai.github.io/langgraph/concepts/langgraph_platform) is infrastructure for deploying LangGraph agents. It is a commercial solution for deploying agentic applications to production, built on the open-source LangGraph framework. The LangGraph Platform consists of several components that work together to support the development, deployment, debugging, and monitoring of LangGraph applications: [LangGraph Server](https://langchain-ai.github.io/langgraph/concepts/langgraph_server) (APIs), [LangGraph SDKs](https://langchain-ai.github.io/langgraph/concepts/sdk) (clients for the APIs), [LangGraph CLI](https://langchain-ai.github.io/langgraph/concepts/langgraph_cli) (command line tool for building the server), [LangGraph Studio](https://langchain-ai.github.io/langgraph/concepts/langgraph_studio) (UI/debugger), +### Why use LangGraph? -To learn more about LangGraph, check out our first LangChain Academy course, *Introduction to LangGraph*, available for free [here](https://academy.langchain.com/courses/intro-to-langgraph). +LangGraph provides fine-grained control over both the flow and state of your +agent applications. It implements a central persistence layer, enabling features that +are common to most agent architectures: -### Key Features +- **Memory**: LangGraph supports conversational memory within and across user +interactions; +- **Human-in-the-loop**: Execution can be interrupted and resumed, allowing for +decisions, validation, and corrections at key stages via human input. -- **Cycles and Branching**: Implement loops and conditionals in your apps. -- **Persistence**: Automatically save state after each step in the graph. Pause and resume the graph execution at any point to support error recovery, human-in-the-loop workflows, time travel and more. -- **Human-in-the-Loop**: Interrupt graph execution to approve or edit next action planned by the agent. -- **Streaming Support**: Stream outputs as they are produced by each node (including token streaming). -- **Integration with LangChain**: LangGraph integrates seamlessly with [LangChain](https://github.com/langchain-ai/langchain/) and [LangSmith](https://docs.smith.langchain.com/) (but does not require them). +Standardizing these components allows individuals and teams to focus on the behavior +of their agent, instead of its supporting infrastructure. + +Through [LangGraph Platform](#langgraph-platform), LangGraph also provides tooling for +debugging, tracing and observability, evaluation, and deployment. + +LangGraph integrates seamlessly with +[LangChain](https://github.com/langchain-ai/langchain/) and +[LangSmith](https://docs.smith.langchain.com/) (but does not require them). + +To learn more about LangGraph, check out our first LangChain Academy +course, *Introduction to LangGraph*, available for free +[here](https://academy.langchain.com/courses/intro-to-langgraph). ### LangGraph Platform -LangGraph Platform is a commercial solution for deploying agentic applications to production, built on the open-source LangGraph framework. +[LangGraph Platform](https://langchain-ai.github.io/langgraph/concepts/langgraph_platform) is infrastructure for deploying LangGraph agents. It is a commercial solution for deploying agentic applications to production, built on the open-source LangGraph framework. The LangGraph Platform consists of several components that work together to support the development, deployment, debugging, and monitoring of LangGraph applications: [LangGraph Server](https://langchain-ai.github.io/langgraph/concepts/langgraph_server) (APIs), [LangGraph SDKs](https://langchain-ai.github.io/langgraph/concepts/sdk) (clients for the APIs), [LangGraph CLI](https://langchain-ai.github.io/langgraph/concepts/langgraph_cli) (command line tool for building the server), and [LangGraph Studio](https://langchain-ai.github.io/langgraph/concepts/langgraph_studio) (UI/debugger). + Here are some common issues that arise in complex deployments, which LangGraph Platform addresses: - **Streaming support**: LangGraph Server provides [multiple streaming modes](https://langchain-ai.github.io/langgraph/concepts/streaming) optimized for various application needs From 832f9ad64e1a426003cb76999fbbea0c4d68e878 Mon Sep 17 00:00:00 2001 From: Chester Curme Date: Fri, 17 Jan 2025 13:34:32 -0500 Subject: [PATCH 2/6] copy changes to libs/langgraph/README.md --- libs/langgraph/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/langgraph/README.md b/libs/langgraph/README.md index 9397bd668..9dbafabc1 100644 --- a/libs/langgraph/README.md +++ b/libs/langgraph/README.md @@ -35,7 +35,7 @@ Through [LangGraph Platform](#langgraph-platform), LangGraph also provides tooli debugging, tracing and observability, evaluation, and deployment. LangGraph integrates seamlessly with -[LangChain](https://github.com/langchain-ai/langchain/) and +[LangChain](https://python.langchain.com/docs/introduction/) and [LangSmith](https://docs.smith.langchain.com/) (but does not require them). To learn more about LangGraph, check out our first LangChain Academy From 0f4e42474f4741cb9d01b27e31ce92b7c012de99 Mon Sep 17 00:00:00 2001 From: Chester Curme Date: Fri, 17 Jan 2025 16:19:32 -0500 Subject: [PATCH 3/6] cr --- README.md | 133 ++++++++++++++++++++++++--------------- libs/langgraph/README.md | 133 ++++++++++++++++++++++++--------------- 2 files changed, 166 insertions(+), 100 deletions(-) diff --git a/README.md b/README.md index 9dbafabc1..662a71130 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ ## Overview -[LangGraph](https://langchain-ai.github.io/langgraph/) is a library for building stateful, multi-actor applications with LLMs, used to create agent and multi-agent workflows. +[LangGraph](https://langchain-ai.github.io/langgraph/) is a library for building +stateful, multi-actor applications with LLMs, used to create agent and multi-agent +workflows. Check out an introductory tutorial [here](https://langchain-ai.github.io/langgraph/tutorials/introduction/). LangGraph is inspired by [Pregel](https://research.google/pubs/pub37252/) and [Apache Beam](https://beam.apache.org/). The public interface draws inspiration from [NetworkX](https://networkx.org/documentation/latest/). LangGraph is built by LangChain Inc, the creators of LangChain, but can be used without LangChain. @@ -23,7 +25,8 @@ LangGraph provides fine-grained control over both the flow and state of your agent applications. It implements a central persistence layer, enabling features that are common to most agent architectures: -- **Memory**: LangGraph supports conversational memory within and across user +- **Memory**: LangGraph persists arbitrary aspects of your application's state, +supporting memory of conversations and other updates within and across user interactions; - **Human-in-the-loop**: Execution can be interrupted and resumed, allowing for decisions, validation, and corrections at key stages via human input. @@ -32,7 +35,7 @@ Standardizing these components allows individuals and teams to focus on the beha of their agent, instead of its supporting infrastructure. Through [LangGraph Platform](#langgraph-platform), LangGraph also provides tooling for -debugging, tracing and observability, evaluation, and deployment. +the development, deployment, debugging, and monitoring of your applications. LangGraph integrates seamlessly with [LangChain](https://python.langchain.com/docs/introduction/) and @@ -46,6 +49,9 @@ course, *Introduction to LangGraph*, available for free [LangGraph Platform](https://langchain-ai.github.io/langgraph/concepts/langgraph_platform) is infrastructure for deploying LangGraph agents. It is a commercial solution for deploying agentic applications to production, built on the open-source LangGraph framework. The LangGraph Platform consists of several components that work together to support the development, deployment, debugging, and monitoring of LangGraph applications: [LangGraph Server](https://langchain-ai.github.io/langgraph/concepts/langgraph_server) (APIs), [LangGraph SDKs](https://langchain-ai.github.io/langgraph/concepts/sdk) (clients for the APIs), [LangGraph CLI](https://langchain-ai.github.io/langgraph/concepts/langgraph_cli) (command line tool for building the server), and [LangGraph Studio](https://langchain-ai.github.io/langgraph/concepts/langgraph_studio) (UI/debugger). +See deployment options [here](https://langchain-ai.github.io/langgraph/concepts/deployment_options/) +(includes a free tier). + Here are some common issues that arise in complex deployments, which LangGraph Platform addresses: - **Streaming support**: LangGraph Server provides [multiple streaming modes](https://langchain-ai.github.io/langgraph/concepts/streaming) optimized for various application needs @@ -213,9 +219,8 @@ final_state = app.invoke( ) final_state["messages"][-1].content ``` - -Now when we pass the same `"thread_id"`, the conversation context is retained via the saved state (i.e. stored list of messages) +Now when we pass the same "thread_id", the conversation context is retained via the saved state (i.e. stored list of messages) ```python final_state = app.invoke( @@ -229,66 +234,94 @@ final_state["messages"][-1].content "Based on the search results, I can tell you that the current weather in New York City is:\n\nTemperature: 90 degrees Fahrenheit (approximately 32.2 degrees Celsius)\nConditions: Sunny\n\nThis weather is quite different from what we just saw in San Francisco. New York is experiencing much warmer temperatures right now. Here are a few points to note:\n\n1. The temperature of 90°F is quite hot, typical of summer weather in New York City.\n2. The sunny conditions suggest clear skies, which is great for outdoor activities but also means it might feel even hotter due to direct sunlight.\n3. This kind of weather in New York often comes with high humidity, which can make it feel even warmer than the actual temperature suggests.\n\nIt's interesting to see the stark contrast between San Francisco's mild, foggy weather and New York's hot, sunny conditions. This difference illustrates how varied weather can be across different parts of the United States, even on the same day.\n\nIs there anything else you'd like to know about the weather in New York or any other location?" ``` -### Step-by-step Breakdown +Step-by-step Breakdown: -1.
- Initialize the model and tools. +
+Initialize the model and tools. +
    +
  • + We use ChatAnthropic as our LLM. NOTE: we need to make sure the model knows that it has these tools available to call. We can do this by converting the LangChain tools into the format for OpenAI tool calling using the .bind_tools() method. +
  • +
  • + We define the tools we want to use - a search tool in our case. It is really easy to create your own tools - see documentation here on how to do that here. +
  • +
+
- - we use `ChatAnthropic` as our LLM. **NOTE:** we need make sure the model knows that it has these tools available to call. We can do this by converting the LangChain tools into the format for OpenAI tool calling using the `.bind_tools()` method. - - we define the tools we want to use - a search tool in our case. It is really easy to create your own tools - see documentation here on how to do that [here](https://python.langchain.com/docs/modules/agents/tools/custom_tools). -
+
+Initialize graph with state. -2.
- Initialize graph with state. +
    +
  • We initialize graph (StateGraph) by passing state schema (in our case MessagesState)
  • +
  • MessagesState is a prebuilt state schema that has one attribute -- a list of LangChain Message objects, as well as logic for merging the updates from each node into the state.
  • +
+
- - we initialize graph (`StateGraph`) by passing state schema (in our case `MessagesState`) - - `MessagesState` is a prebuilt state schema that has one attribute -- a list of LangChain `Message` objects, as well as logic for merging the updates from each node into the state -
+
+Define graph nodes. -3.
- Define graph nodes. +There are two main nodes we need: - There are two main nodes we need: +
    +
  • The agent node: responsible for deciding what (if any) actions to take.
  • +
  • The tools node that invokes tools: if the agent decides to take an action, this node will then execute that action.
  • +
+
- - The `agent` node: responsible for deciding what (if any) actions to take. - - The `tools` node that invokes tools: if the agent decides to take an action, this node will then execute that action. -
+
+Define entry point and graph edges. -4.
- Define entry point and graph edges. +First, we need to set the entry point for graph execution - agent node. - First, we need to set the entry point for graph execution - `agent` node. +Then we define one normal and one conditional edge. Conditional edge means that the destination depends on the contents of the graph's state (MessagesState). In our case, the destination is not known until the agent (LLM) decides. - Then we define one normal and one conditional edge. Conditional edge means that the destination depends on the contents of the graph's state (`MessageState`). In our case, the destination is not known until the agent (LLM) decides. +
    +
  • Conditional edge: after the agent is called, we should either: +
      +
    • a. Run tools if the agent said to take an action, OR
    • +
    • b. Finish (respond to the user) if the agent did not ask to run tools
    • +
    +
  • +
  • Normal edge: after the tools are invoked, the graph should always return to the agent to decide what to do next
  • +
+
- - Conditional edge: after the agent is called, we should either: - - a. Run tools if the agent said to take an action, OR - - b. Finish (respond to the user) if the agent did not ask to run tools - - Normal edge: after the tools are invoked, the graph should always return to the agent to decide what to do next -
+
+Compile the graph. -5.
- Compile the graph. +
    +
  • + When we compile the graph, we turn it into a LangChain + Runnable, + which automatically enables calling .invoke(), .stream() and .batch() + with your inputs +
  • +
  • + We can also optionally pass checkpointer object for persisting state between graph runs, and enabling memory, + human-in-the-loop workflows, time travel and more. In our case we use MemorySaver - + a simple in-memory checkpointer +
  • +
+
- - When we compile the graph, we turn it into a LangChain [Runnable](https://python.langchain.com/v0.2/docs/concepts/#runnable-interface), which automatically enables calling `.invoke()`, `.stream()` and `.batch()` with your inputs - - We can also optionally pass checkpointer object for persisting state between graph runs, and enabling memory, human-in-the-loop workflows, time travel and more. In our case we use `MemorySaver` - a simple in-memory checkpointer -
+
+Execute the graph. -6.
- Execute the graph. - - 1. LangGraph adds the input message to the internal state, then passes the state to the entrypoint node, `"agent"`. - 2. The `"agent"` node executes, invoking the chat model. - 3. The chat model returns an `AIMessage`. LangGraph adds this to the state. - 4. Graph cycles the following steps until there are no more `tool_calls` on `AIMessage`: - - - If `AIMessage` has `tool_calls`, `"tools"` node executes - - The `"agent"` node executes again and returns `AIMessage` - - 5. Execution progresses to the special `END` value and outputs the final state. - And as a result, we get a list of all our chat messages as output. -
+
    +
  1. LangGraph adds the input message to the internal state, then passes the state to the entrypoint node, "agent".
  2. +
  3. The "agent" node executes, invoking the chat model.
  4. +
  5. The chat model returns an AIMessage. LangGraph adds this to the state.
  6. +
  7. Graph cycles the following steps until there are no more tool_calls on AIMessage: +
      +
    • If AIMessage has tool_calls, "tools" node executes
    • +
    • The "agent" node executes again and returns AIMessage
    • +
    +
  8. +
  9. Execution progresses to the special END value and outputs the final state. And as a result, we get a list of all our chat messages as output.
  10. +
+
+ ## Documentation diff --git a/libs/langgraph/README.md b/libs/langgraph/README.md index 9dbafabc1..662a71130 100644 --- a/libs/langgraph/README.md +++ b/libs/langgraph/README.md @@ -12,7 +12,9 @@ ## Overview -[LangGraph](https://langchain-ai.github.io/langgraph/) is a library for building stateful, multi-actor applications with LLMs, used to create agent and multi-agent workflows. +[LangGraph](https://langchain-ai.github.io/langgraph/) is a library for building +stateful, multi-actor applications with LLMs, used to create agent and multi-agent +workflows. Check out an introductory tutorial [here](https://langchain-ai.github.io/langgraph/tutorials/introduction/). LangGraph is inspired by [Pregel](https://research.google/pubs/pub37252/) and [Apache Beam](https://beam.apache.org/). The public interface draws inspiration from [NetworkX](https://networkx.org/documentation/latest/). LangGraph is built by LangChain Inc, the creators of LangChain, but can be used without LangChain. @@ -23,7 +25,8 @@ LangGraph provides fine-grained control over both the flow and state of your agent applications. It implements a central persistence layer, enabling features that are common to most agent architectures: -- **Memory**: LangGraph supports conversational memory within and across user +- **Memory**: LangGraph persists arbitrary aspects of your application's state, +supporting memory of conversations and other updates within and across user interactions; - **Human-in-the-loop**: Execution can be interrupted and resumed, allowing for decisions, validation, and corrections at key stages via human input. @@ -32,7 +35,7 @@ Standardizing these components allows individuals and teams to focus on the beha of their agent, instead of its supporting infrastructure. Through [LangGraph Platform](#langgraph-platform), LangGraph also provides tooling for -debugging, tracing and observability, evaluation, and deployment. +the development, deployment, debugging, and monitoring of your applications. LangGraph integrates seamlessly with [LangChain](https://python.langchain.com/docs/introduction/) and @@ -46,6 +49,9 @@ course, *Introduction to LangGraph*, available for free [LangGraph Platform](https://langchain-ai.github.io/langgraph/concepts/langgraph_platform) is infrastructure for deploying LangGraph agents. It is a commercial solution for deploying agentic applications to production, built on the open-source LangGraph framework. The LangGraph Platform consists of several components that work together to support the development, deployment, debugging, and monitoring of LangGraph applications: [LangGraph Server](https://langchain-ai.github.io/langgraph/concepts/langgraph_server) (APIs), [LangGraph SDKs](https://langchain-ai.github.io/langgraph/concepts/sdk) (clients for the APIs), [LangGraph CLI](https://langchain-ai.github.io/langgraph/concepts/langgraph_cli) (command line tool for building the server), and [LangGraph Studio](https://langchain-ai.github.io/langgraph/concepts/langgraph_studio) (UI/debugger). +See deployment options [here](https://langchain-ai.github.io/langgraph/concepts/deployment_options/) +(includes a free tier). + Here are some common issues that arise in complex deployments, which LangGraph Platform addresses: - **Streaming support**: LangGraph Server provides [multiple streaming modes](https://langchain-ai.github.io/langgraph/concepts/streaming) optimized for various application needs @@ -213,9 +219,8 @@ final_state = app.invoke( ) final_state["messages"][-1].content ``` - -Now when we pass the same `"thread_id"`, the conversation context is retained via the saved state (i.e. stored list of messages) +Now when we pass the same "thread_id", the conversation context is retained via the saved state (i.e. stored list of messages) ```python final_state = app.invoke( @@ -229,66 +234,94 @@ final_state["messages"][-1].content "Based on the search results, I can tell you that the current weather in New York City is:\n\nTemperature: 90 degrees Fahrenheit (approximately 32.2 degrees Celsius)\nConditions: Sunny\n\nThis weather is quite different from what we just saw in San Francisco. New York is experiencing much warmer temperatures right now. Here are a few points to note:\n\n1. The temperature of 90°F is quite hot, typical of summer weather in New York City.\n2. The sunny conditions suggest clear skies, which is great for outdoor activities but also means it might feel even hotter due to direct sunlight.\n3. This kind of weather in New York often comes with high humidity, which can make it feel even warmer than the actual temperature suggests.\n\nIt's interesting to see the stark contrast between San Francisco's mild, foggy weather and New York's hot, sunny conditions. This difference illustrates how varied weather can be across different parts of the United States, even on the same day.\n\nIs there anything else you'd like to know about the weather in New York or any other location?" ``` -### Step-by-step Breakdown +Step-by-step Breakdown: -1.
- Initialize the model and tools. +
+Initialize the model and tools. +
    +
  • + We use ChatAnthropic as our LLM. NOTE: we need to make sure the model knows that it has these tools available to call. We can do this by converting the LangChain tools into the format for OpenAI tool calling using the .bind_tools() method. +
  • +
  • + We define the tools we want to use - a search tool in our case. It is really easy to create your own tools - see documentation here on how to do that here. +
  • +
+
- - we use `ChatAnthropic` as our LLM. **NOTE:** we need make sure the model knows that it has these tools available to call. We can do this by converting the LangChain tools into the format for OpenAI tool calling using the `.bind_tools()` method. - - we define the tools we want to use - a search tool in our case. It is really easy to create your own tools - see documentation here on how to do that [here](https://python.langchain.com/docs/modules/agents/tools/custom_tools). -
+
+Initialize graph with state. -2.
- Initialize graph with state. +
    +
  • We initialize graph (StateGraph) by passing state schema (in our case MessagesState)
  • +
  • MessagesState is a prebuilt state schema that has one attribute -- a list of LangChain Message objects, as well as logic for merging the updates from each node into the state.
  • +
+
- - we initialize graph (`StateGraph`) by passing state schema (in our case `MessagesState`) - - `MessagesState` is a prebuilt state schema that has one attribute -- a list of LangChain `Message` objects, as well as logic for merging the updates from each node into the state -
+
+Define graph nodes. -3.
- Define graph nodes. +There are two main nodes we need: - There are two main nodes we need: +
    +
  • The agent node: responsible for deciding what (if any) actions to take.
  • +
  • The tools node that invokes tools: if the agent decides to take an action, this node will then execute that action.
  • +
+
- - The `agent` node: responsible for deciding what (if any) actions to take. - - The `tools` node that invokes tools: if the agent decides to take an action, this node will then execute that action. -
+
+Define entry point and graph edges. -4.
- Define entry point and graph edges. +First, we need to set the entry point for graph execution - agent node. - First, we need to set the entry point for graph execution - `agent` node. +Then we define one normal and one conditional edge. Conditional edge means that the destination depends on the contents of the graph's state (MessagesState). In our case, the destination is not known until the agent (LLM) decides. - Then we define one normal and one conditional edge. Conditional edge means that the destination depends on the contents of the graph's state (`MessageState`). In our case, the destination is not known until the agent (LLM) decides. +
    +
  • Conditional edge: after the agent is called, we should either: +
      +
    • a. Run tools if the agent said to take an action, OR
    • +
    • b. Finish (respond to the user) if the agent did not ask to run tools
    • +
    +
  • +
  • Normal edge: after the tools are invoked, the graph should always return to the agent to decide what to do next
  • +
+
- - Conditional edge: after the agent is called, we should either: - - a. Run tools if the agent said to take an action, OR - - b. Finish (respond to the user) if the agent did not ask to run tools - - Normal edge: after the tools are invoked, the graph should always return to the agent to decide what to do next -
+
+Compile the graph. -5.
- Compile the graph. +
    +
  • + When we compile the graph, we turn it into a LangChain + Runnable, + which automatically enables calling .invoke(), .stream() and .batch() + with your inputs +
  • +
  • + We can also optionally pass checkpointer object for persisting state between graph runs, and enabling memory, + human-in-the-loop workflows, time travel and more. In our case we use MemorySaver - + a simple in-memory checkpointer +
  • +
+
- - When we compile the graph, we turn it into a LangChain [Runnable](https://python.langchain.com/v0.2/docs/concepts/#runnable-interface), which automatically enables calling `.invoke()`, `.stream()` and `.batch()` with your inputs - - We can also optionally pass checkpointer object for persisting state between graph runs, and enabling memory, human-in-the-loop workflows, time travel and more. In our case we use `MemorySaver` - a simple in-memory checkpointer -
+
+Execute the graph. -6.
- Execute the graph. - - 1. LangGraph adds the input message to the internal state, then passes the state to the entrypoint node, `"agent"`. - 2. The `"agent"` node executes, invoking the chat model. - 3. The chat model returns an `AIMessage`. LangGraph adds this to the state. - 4. Graph cycles the following steps until there are no more `tool_calls` on `AIMessage`: - - - If `AIMessage` has `tool_calls`, `"tools"` node executes - - The `"agent"` node executes again and returns `AIMessage` - - 5. Execution progresses to the special `END` value and outputs the final state. - And as a result, we get a list of all our chat messages as output. -
+
    +
  1. LangGraph adds the input message to the internal state, then passes the state to the entrypoint node, "agent".
  2. +
  3. The "agent" node executes, invoking the chat model.
  4. +
  5. The chat model returns an AIMessage. LangGraph adds this to the state.
  6. +
  7. Graph cycles the following steps until there are no more tool_calls on AIMessage: +
      +
    • If AIMessage has tool_calls, "tools" node executes
    • +
    • The "agent" node executes again and returns AIMessage
    • +
    +
  8. +
  9. Execution progresses to the special END value and outputs the final state. And as a result, we get a list of all our chat messages as output.
  10. +
+
+ ## Documentation From 44970640d55020cee59c6dabbf3ccbd9d5e21349 Mon Sep 17 00:00:00 2001 From: Chester Curme Date: Fri, 17 Jan 2025 16:28:36 -0500 Subject: [PATCH 4/6] cr --- README.md | 5 +++-- libs/langgraph/README.md | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 662a71130..2582752a5 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,9 @@ are common to most agent architectures: - **Memory**: LangGraph persists arbitrary aspects of your application's state, supporting memory of conversations and other updates within and across user interactions; -- **Human-in-the-loop**: Execution can be interrupted and resumed, allowing for -decisions, validation, and corrections at key stages via human input. +- **Human-in-the-loop**: Because state is checkpointed, execution can be interrupted +and resumed, allowing for decisions, validation, and corrections at key stages via +human input. Standardizing these components allows individuals and teams to focus on the behavior of their agent, instead of its supporting infrastructure. diff --git a/libs/langgraph/README.md b/libs/langgraph/README.md index 662a71130..2582752a5 100644 --- a/libs/langgraph/README.md +++ b/libs/langgraph/README.md @@ -28,8 +28,9 @@ are common to most agent architectures: - **Memory**: LangGraph persists arbitrary aspects of your application's state, supporting memory of conversations and other updates within and across user interactions; -- **Human-in-the-loop**: Execution can be interrupted and resumed, allowing for -decisions, validation, and corrections at key stages via human input. +- **Human-in-the-loop**: Because state is checkpointed, execution can be interrupted +and resumed, allowing for decisions, validation, and corrections at key stages via +human input. Standardizing these components allows individuals and teams to focus on the behavior of their agent, instead of its supporting infrastructure. From 31578cbe0ea910b35ece5008ee2a439fc0b2c3aa Mon Sep 17 00:00:00 2001 From: Chester Curme Date: Fri, 17 Jan 2025 18:01:57 -0500 Subject: [PATCH 5/6] move code block --- README.md | 28 ++++++++++++++-------------- libs/langgraph/README.md | 28 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 2582752a5..828abae90 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,20 @@ final_state["messages"][-1].content ``` "Based on the search results, I can tell you that the current weather in San Francisco is:\n\nTemperature: 60 degrees Fahrenheit\nConditions: Foggy\n\nSan Francisco is known for its microclimates and frequent fog, especially during the summer months. The temperature of 60°F (about 15.5°C) is quite typical for the city, which tends to have mild temperatures year-round. The fog, often referred to as "Karl the Fog" by locals, is a characteristic feature of San Francisco\'s weather, particularly in the mornings and evenings.\n\nIs there anything else you\'d like to know about the weather in San Francisco or any other location?" ``` + +Now when we pass the same "thread_id", the conversation context is retained via the saved state (i.e. stored list of messages) + +```python +final_state = app.invoke( + {"messages": [{"role": "user", "content": "what about ny"}]}, + config={"configurable": {"thread_id": 42}} +) +final_state["messages"][-1].content +``` + +``` +"Based on the search results, I can tell you that the current weather in New York City is:\n\nTemperature: 90 degrees Fahrenheit (approximately 32.2 degrees Celsius)\nConditions: Sunny\n\nThis weather is quite different from what we just saw in San Francisco. New York is experiencing much warmer temperatures right now. Here are a few points to note:\n\n1. The temperature of 90°F is quite hot, typical of summer weather in New York City.\n2. The sunny conditions suggest clear skies, which is great for outdoor activities but also means it might feel even hotter due to direct sunlight.\n3. This kind of weather in New York often comes with high humidity, which can make it feel even warmer than the actual temperature suggests.\n\nIt's interesting to see the stark contrast between San Francisco's mild, foggy weather and New York's hot, sunny conditions. This difference illustrates how varied weather can be across different parts of the United States, even on the same day.\n\nIs there anything else you'd like to know about the weather in New York or any other location?" +``` > [!TIP] @@ -221,20 +235,6 @@ final_state = app.invoke( final_state["messages"][-1].content ``` -Now when we pass the same "thread_id", the conversation context is retained via the saved state (i.e. stored list of messages) - -```python -final_state = app.invoke( - {"messages": [{"role": "user", "content": "what about ny"}]}, - config={"configurable": {"thread_id": 42}} -) -final_state["messages"][-1].content -``` - -``` -"Based on the search results, I can tell you that the current weather in New York City is:\n\nTemperature: 90 degrees Fahrenheit (approximately 32.2 degrees Celsius)\nConditions: Sunny\n\nThis weather is quite different from what we just saw in San Francisco. New York is experiencing much warmer temperatures right now. Here are a few points to note:\n\n1. The temperature of 90°F is quite hot, typical of summer weather in New York City.\n2. The sunny conditions suggest clear skies, which is great for outdoor activities but also means it might feel even hotter due to direct sunlight.\n3. This kind of weather in New York often comes with high humidity, which can make it feel even warmer than the actual temperature suggests.\n\nIt's interesting to see the stark contrast between San Francisco's mild, foggy weather and New York's hot, sunny conditions. This difference illustrates how varied weather can be across different parts of the United States, even on the same day.\n\nIs there anything else you'd like to know about the weather in New York or any other location?" -``` - Step-by-step Breakdown:
diff --git a/libs/langgraph/README.md b/libs/langgraph/README.md index 2582752a5..828abae90 100644 --- a/libs/langgraph/README.md +++ b/libs/langgraph/README.md @@ -125,6 +125,20 @@ final_state["messages"][-1].content ``` "Based on the search results, I can tell you that the current weather in San Francisco is:\n\nTemperature: 60 degrees Fahrenheit\nConditions: Foggy\n\nSan Francisco is known for its microclimates and frequent fog, especially during the summer months. The temperature of 60°F (about 15.5°C) is quite typical for the city, which tends to have mild temperatures year-round. The fog, often referred to as "Karl the Fog" by locals, is a characteristic feature of San Francisco\'s weather, particularly in the mornings and evenings.\n\nIs there anything else you\'d like to know about the weather in San Francisco or any other location?" ``` + +Now when we pass the same "thread_id", the conversation context is retained via the saved state (i.e. stored list of messages) + +```python +final_state = app.invoke( + {"messages": [{"role": "user", "content": "what about ny"}]}, + config={"configurable": {"thread_id": 42}} +) +final_state["messages"][-1].content +``` + +``` +"Based on the search results, I can tell you that the current weather in New York City is:\n\nTemperature: 90 degrees Fahrenheit (approximately 32.2 degrees Celsius)\nConditions: Sunny\n\nThis weather is quite different from what we just saw in San Francisco. New York is experiencing much warmer temperatures right now. Here are a few points to note:\n\n1. The temperature of 90°F is quite hot, typical of summer weather in New York City.\n2. The sunny conditions suggest clear skies, which is great for outdoor activities but also means it might feel even hotter due to direct sunlight.\n3. This kind of weather in New York often comes with high humidity, which can make it feel even warmer than the actual temperature suggests.\n\nIt's interesting to see the stark contrast between San Francisco's mild, foggy weather and New York's hot, sunny conditions. This difference illustrates how varied weather can be across different parts of the United States, even on the same day.\n\nIs there anything else you'd like to know about the weather in New York or any other location?" +```
> [!TIP] @@ -221,20 +235,6 @@ final_state = app.invoke( final_state["messages"][-1].content ``` -Now when we pass the same "thread_id", the conversation context is retained via the saved state (i.e. stored list of messages) - -```python -final_state = app.invoke( - {"messages": [{"role": "user", "content": "what about ny"}]}, - config={"configurable": {"thread_id": 42}} -) -final_state["messages"][-1].content -``` - -``` -"Based on the search results, I can tell you that the current weather in New York City is:\n\nTemperature: 90 degrees Fahrenheit (approximately 32.2 degrees Celsius)\nConditions: Sunny\n\nThis weather is quite different from what we just saw in San Francisco. New York is experiencing much warmer temperatures right now. Here are a few points to note:\n\n1. The temperature of 90°F is quite hot, typical of summer weather in New York City.\n2. The sunny conditions suggest clear skies, which is great for outdoor activities but also means it might feel even hotter due to direct sunlight.\n3. This kind of weather in New York often comes with high humidity, which can make it feel even warmer than the actual temperature suggests.\n\nIt's interesting to see the stark contrast between San Francisco's mild, foggy weather and New York's hot, sunny conditions. This difference illustrates how varied weather can be across different parts of the United States, even on the same day.\n\nIs there anything else you'd like to know about the weather in New York or any other location?" -``` - Step-by-step Breakdown:
From ee61d06f8dc8404ea6de960c2e19e9908924c62f Mon Sep 17 00:00:00 2001 From: Chester Curme Date: Tue, 21 Jan 2025 10:31:27 -0500 Subject: [PATCH 6/6] add hyperlink --- README.md | 5 +++-- libs/langgraph/README.md | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 828abae90..bd6cf5586 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,9 @@ LangGraph is inspired by [Pregel](https://research.google/pubs/pub37252/) and [A ### Why use LangGraph? LangGraph provides fine-grained control over both the flow and state of your -agent applications. It implements a central persistence layer, enabling features that -are common to most agent architectures: +agent applications. It implements a central +[persistence layer](https://langchain-ai.github.io/langgraph/concepts/persistence/), +enabling features that are common to most agent architectures: - **Memory**: LangGraph persists arbitrary aspects of your application's state, supporting memory of conversations and other updates within and across user diff --git a/libs/langgraph/README.md b/libs/langgraph/README.md index 828abae90..bd6cf5586 100644 --- a/libs/langgraph/README.md +++ b/libs/langgraph/README.md @@ -22,8 +22,9 @@ LangGraph is inspired by [Pregel](https://research.google/pubs/pub37252/) and [A ### Why use LangGraph? LangGraph provides fine-grained control over both the flow and state of your -agent applications. It implements a central persistence layer, enabling features that -are common to most agent architectures: +agent applications. It implements a central +[persistence layer](https://langchain-ai.github.io/langgraph/concepts/persistence/), +enabling features that are common to most agent architectures: - **Memory**: LangGraph persists arbitrary aspects of your application's state, supporting memory of conversations and other updates within and across user