From 19628009014dc9c3bae75d777b82f376d2ef805f Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Mon, 4 Mar 2024 19:47:54 -0800 Subject: [PATCH] update readme --- README.md | 89 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index f9e2f70a3..99833d07f 100644 --- a/README.md +++ b/README.md @@ -417,6 +417,32 @@ If you need cycles. Langchain Expression Language allows you to easily define chains (DAGs) but does not have a good mechanism for adding in cycles. `langgraph` adds that syntax. + +## How-to Guides + +These guides show how to use LangGraph in particular ways. + +### Async + +If you are running LangGraph in async workflows, you may want to create the nodes to be async by default. +For a walkthrough on how to do that, see [this documentation](https://github.com/langchain-ai/langgraph/blob/main/examples/async.ipynb) + +### Streaming Tokens + +Sometimes language models take a while to respond and you may want to stream tokens to end users. +For a guide on how to do this, see [this documentation](https://github.com/langchain-ai/langgraph/blob/main/examples/streaming-tokens.ipynb) + +### Persistence + +LangGraph comes with built-in persistence, allowing you to save the state of the graph at point and resume from there. +For a walkthrough on how to do that, see [this documentation](https://github.com/langchain-ai/langgraph/blob/main/examples/persistence.ipynb) + +### Human-in-the-loop + +LangGraph comes with built-in support for human-in-the-loop workflows. This is useful when you want to have a human review the current state before proceeding to a particular node. +For a walkthrough on how to do that, see [this documentation](https://github.com/langchain-ai/langgraph/blob/main/examples/human-in-the-loop.ipynb) + + ## Examples ### ChatAgentExecutor: with function calling @@ -454,25 +480,6 @@ We also have a lot of examples highlighting how to slightly modify the base chat - [Force calling a tool first](https://github.com/langchain-ai/langgraph/blob/main/examples/agent_executor/force-calling-a-tool-first.ipynb): How to always call a specific tool first - [Managing agent steps](https://github.com/langchain-ai/langgraph/blob/main/examples/agent_executor/managing-agent-steps.ipynb): How to more explicitly manage intermediate steps that an agent takes -### Async - -If you are running LangGraph in async workflows, you may want to create the nodes to be async by default. -For a walkthrough on how to do that, see [this documentation](https://github.com/langchain-ai/langgraph/blob/main/examples/async.ipynb) - -### Streaming Tokens - -Sometimes language models take a while to respond and you may want to stream tokens to end users. -For a guide on how to do this, see [this documentation](https://github.com/langchain-ai/langgraph/blob/main/examples/streaming-tokens.ipynb) - -### Persistence - -LangGraph comes with built-in persistence, allowing you to save the state of the graph at point and resume from there. -For a walkthrough on how to do that, see [this documentation](https://github.com/langchain-ai/langgraph/blob/main/examples/persistence.ipynb) - -### Human-in-the-loop - -LangGraph comes with built-in support for human-in-the-loop workflows. This is useful when you want to have a human review the current state before proceeding to a particular node. -For a walkthrough on how to do that, see [this documentation](https://github.com/langchain-ai/langgraph/blob/main/examples/human-in-the-loop.ipynb) ### Planning Agent Examples @@ -649,6 +656,23 @@ It only takes one argument: - `key`: The name of the node that should be called first. +#### `.add_conditional_edges` + +```python + def set_conditional_entry_point( + self, + condition: Callable[..., str], + conditional_edge_mapping: Optional[Dict[str, str]] = None, + ) -> None: +``` + +This method adds a conditional entry point. +What this means is that when the graph is called, it will call the `condition` Callable to decide what node to enter into first. + +- `condition`: A function to call to decide what to do next. The input will be the input to the graph. It should return a string that is present in `conditional_edge_mapping` and represents the edge to take. +- `conditional_edge_mapping`: A mapping of string to string. The keys should be strings that may be returned by `condition`. The values should be the downstream node to call if that condition is returned. + + #### `.set_finish_point` ```python @@ -735,6 +759,33 @@ for s in app.stream(inputs): print("----") ``` +### create_tool_calling_executor + +```python +from langgraph.prebuilt import chat_agent_executor +``` + +This is a helper function for creating a graph that works with a chat model that utilizes tool calling. +Can be created by passing in a model and a list of tools. +The model must be one that supports OpenAI tool calling. + +```python +from langchain_openai import ChatOpenAI +from langchain_community.tools.tavily_search import TavilySearchResults +from langgraph.prebuilt import chat_agent_executor +from langchain_core.messages import HumanMessage + +tools = [TavilySearchResults(max_results=1)] +model = ChatOpenAI() + +app = chat_agent_executor.create_tool_calling_executor(model, tools) + +inputs = {"messages": [HumanMessage(content="what is the weather in sf")]} +for s in app.stream(inputs): + print(list(s.values())[0]) + print("----") +``` + ### create_agent_executor ```python