-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add example repo for agent inbox and LangGraph
- Loading branch information
1 parent
049ec89
commit 54b433b
Showing
17 changed files
with
1,296 additions
and
140 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"python.languageServer": "None" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,75 @@ | ||
# New LangGraph Project | ||
# Agent Inbox LangGraph Example | ||
|
||
[![CI](https://github.com/langchain-ai/new-langgraph-project/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/langchain-ai/new-langgraph-project/actions/workflows/unit-tests.yml) | ||
[![Integration Tests](https://github.com/langchain-ai/new-langgraph-project/actions/workflows/integration-tests.yml/badge.svg)](https://github.com/langchain-ai/new-langgraph-project/actions/workflows/integration-tests.yml) | ||
[![Open in - LangGraph Studio](https://img.shields.io/badge/Open_in-LangGraph_Studio-00324d.svg?logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4NS4zMzMiIGhlaWdodD0iODUuMzMzIiB2ZXJzaW9uPSIxLjAiIHZpZXdCb3g9IjAgMCA2NCA2NCI+PHBhdGggZD0iTTEzIDcuOGMtNi4zIDMuMS03LjEgNi4zLTYuOCAyNS43LjQgMjQuNi4zIDI0LjUgMjUuOSAyNC41QzU3LjUgNTggNTggNTcuNSA1OCAzMi4zIDU4IDcuMyA1Ni43IDYgMzIgNmMtMTIuOCAwLTE2LjEuMy0xOSAxLjhtMzcuNiAxNi42YzIuOCAyLjggMy40IDQuMiAzLjQgNy42cy0uNiA0LjgtMy40IDcuNkw0Ny4yIDQzSDE2LjhsLTMuNC0zLjRjLTQuOC00LjgtNC44LTEwLjQgMC0xNS4ybDMuNC0zLjRoMzAuNHoiLz48cGF0aCBkPSJNMTguOSAyNS42Yy0xLjEgMS4zLTEgMS43LjQgMi41LjkuNiAxLjcgMS44IDEuNyAyLjcgMCAxIC43IDIuOCAxLjYgNC4xIDEuNCAxLjkgMS40IDIuNS4zIDMuMi0xIC42LS42LjkgMS40LjkgMS41IDAgMi43LS41IDIuNy0xIDAtLjYgMS4xLS44IDIuNi0uNGwyLjYuNy0xLjgtMi45Yy01LjktOS4zLTkuNC0xMi4zLTExLjUtOS44TTM5IDI2YzAgMS4xLS45IDIuNS0yIDMuMi0yLjQgMS41LTIuNiAzLjQtLjUgNC4yLjguMyAyIDEuNyAyLjUgMy4xLjYgMS41IDEuNCAyLjMgMiAyIDEuNS0uOSAxLjItMy41LS40LTMuNS0yLjEgMC0yLjgtMi44LS44LTMuMyAxLjYtLjQgMS42LS41IDAtLjYtMS4xLS4xLTEuNS0uNi0xLjItMS42LjctMS43IDMuMy0yLjEgMy41LS41LjEuNS4yIDEuNi4zIDIuMiAwIC43LjkgMS40IDEuOSAxLjYgMi4xLjQgMi4zLTIuMy4yLTMuMi0uOC0uMy0yLTEuNy0yLjUtMy4xLTEuMS0zLTMtMy4zLTMtLjUiLz48L3N2Zz4=)](https://langgraph-studio.vercel.app/templates/open?githubUrl=https://github.com/langchain-ai/new-langgraph-project) | ||
The repository contains a bare minimum code example to get started with the Agent Inbox with LangGraph. | ||
|
||
This template demonstrates a simple chatbot implemented using [LangGraph](https://github.com/langchain-ai/langgraph), designed for [LangGraph Studio](https://github.com/langchain-ai/langgraph-studio). The chatbot maintains persistent chat memory, allowing for coherent conversations across multiple interactions. | ||
|
||
![Graph view in LangGraph studio UI](./static/studio_ui.png) | ||
## Getting Started | ||
|
||
The core logic, defined in `src/agent/graph.py`, showcases a straightforward chatbot that responds to user queries while maintaining context from previous messages. | ||
To get started, clone the repository: | ||
|
||
## What it does | ||
```bash | ||
git clone https://github.com/langchain-ai/agent-inbox-example | ||
``` | ||
|
||
The simple chatbot: | ||
```bash | ||
cd agent-inbox-example | ||
``` | ||
|
||
1. Takes a user **message** as input | ||
2. Maintains a history of the conversation | ||
3. Generates a response based on the current message and conversation history | ||
4. Updates the conversation history with the new interaction | ||
Then, install the dependencies: | ||
|
||
This template provides a foundation that can be easily customized and extended to create more complex conversational agents. | ||
```bash | ||
poetry install | ||
``` | ||
|
||
## Getting Started | ||
Next, install the [LangGraph CLI](https://langchain-ai.github.io/langgraph/cloud/reference/cli/) if not already installed. We're installing the in-memory version so we can run the LangGraph server without Docker. | ||
|
||
Assuming you have already [installed LangGraph Studio](https://github.com/langchain-ai/langgraph-studio?tab=readme-ov-file#download), to set up: | ||
```bash | ||
pip install -U "langgraph-cli[inmem]" | ||
``` | ||
|
||
1. Create a `.env` file. | ||
After this, we can start the LangGraph server: | ||
|
||
```bash | ||
cp .env.example .env | ||
langgraph dev | ||
``` | ||
|
||
2. Define required API keys in your `.env` file. | ||
This may take a second to start. Once the server is running, it should open a new browser tab to the LangGraph Studio through LangSmith. If this does not happen automatically, visit this URL: | ||
[https://smith.langchain.com/studio/thread?baseUrl=http%3A%2F%2F127.0.0.1%3A2024](https://smith.langchain.com/studio/thread?baseUrl=http%3A%2F%2F127.0.0.1%3A2024) | ||
|
||
<!-- | ||
Setup instruction auto-generated by `langgraph template lock`. DO NOT EDIT MANUALLY. | ||
--> | ||
Now that our LangGraph server is running, we can start a new run in the Studio. To do this, simply enter any string into the `Interrupt Response` field, then click the `Submit` button. This will execute the graph, and interrupt on the `human_node`. Once the graph has interrupted, we can visit the Agent Inbox site to add your graph, and manage the interrupted thread. | ||
|
||
## Agent Inbox Setup | ||
|
||
Visit [`dev.agentinbox.ai`](https://dev.agentinbox.ai). If it's your first time visiting the site, you'll be prompted to add a new graph. | ||
|
||
<!-- | ||
End setup instructions | ||
--> | ||
Enter the following fields into the form: | ||
|
||
3. Customize the code as needed. | ||
4. Open the folder in LangGraph Studio! | ||
- Graph/Assistant ID: `agent` - this corresponds to the ID of the graph defined in the [`langgraph.json`](./langgraph.json) file, or the ID of an assistant tied to your graph. | ||
- Deployment URL: `http://127.0.0.1:2024` - this is the URL of the LangGraph server running locally. | ||
- Name: `My Agent` - this is the optional name of the graph. You can set this to any value you want, or leave it empty and it'll be auto-assigned. | ||
|
||
## How to customize | ||
Click `Submit` and watch your graph appear in the sidebar. This should automatically fetch the interrupted threads, but if it does not, click on the sidebar item & refresh the page. Once you've done this, you should see a single interrupted item in the table: | ||
|
||
1. **Modify the system prompt**: The default system prompt is defined in [configuration.py](./src/agent/configuration.py). You can easily update this via configuration in the studio to change the chatbot's personality or behavior. | ||
2. **Select a different model**: We default to Anthropic's Claude 3 Sonnet. You can select a compatible chat model using `provider/model-name` via configuration. Example: `openai/gpt-4-turbo-preview`. | ||
3. **Extend the graph**: The core logic of the chatbot is defined in [graph.py](./src/agent/graph.py). You can modify this file to add new nodes, edges, or change the flow of the conversation. | ||
![Screenshot of the Agent Inbox](./static/agent_inbox_view.png) | ||
|
||
You can also quickly extend this template by: | ||
Click on this row, and you'll be taken to the interrupted item page. From here, you can respond in any way you'd like: | ||
|
||
- Adding custom tools or functions to enhance the chatbot's capabilities. | ||
- Implementing additional logic for handling specific types of user queries or tasks. | ||
- Integrating external APIs or databases to provide more dynamic responses. | ||
- Accept | ||
- Edit | ||
- Respond | ||
- Ignore | ||
|
||
## Development | ||
![Screenshot of an interrupted item in the Agent Inbox](./static/interrupted_item.png) | ||
|
||
While iterating on your graph, you can edit past state and rerun your app from previous states to debug specific nodes. Local changes will be automatically applied via hot reload. Try experimenting with: | ||
Once you take an action, the graph will resume the execution and end. The final state returned from the graph will be a string containing the type of action which was taken, and the value of the action args (unless `ignore` was chosen). | ||
|
||
- Modifying the system prompt to give your chatbot a unique personality. | ||
- Adding new nodes to the graph for more complex conversation flows. | ||
- Implementing conditional logic to handle different types of user inputs. | ||
To view the result of the graph, go back to the LangGraph Studio and inspect the most recent thread results. | ||
|
||
Follow-up requests will be appended to the same thread. You can create an entirely new thread, clearing previous history, using the `+` button in the top right. | ||
![Screenshot of the most recent thread results LangGraph Studio](./static/studio_thread_result.png) | ||
|
||
For more advanced features and examples, refer to the [LangGraph documentation](https://github.com/langchain-ai/langgraph). These resources can help you adapt this template for your specific use case and build more sophisticated conversational agents. | ||
## Go Deeper | ||
|
||
LangGraph Studio also integrates with [LangSmith](https://smith.langchain.com/) for more in-depth tracing and collaboration with teammates, allowing you to analyze and optimize your chatbot's performance. | ||
If you'd like to go deeper, you can: | ||
|
||
<!-- | ||
Configuration auto-generated by `langgraph template lock`. DO NOT EDIT MANUALLY. | ||
{ | ||
"config_schemas": { | ||
"agent": { | ||
"type": "object", | ||
"properties": {} | ||
} | ||
} | ||
} | ||
--> | ||
- Checkout the Agent Inbox docs, and codebase here: [github.com/langchain-ai/agent-inbox](https://github.com/langchain-ai/agent-inbox) | ||
- See an open source Executive AI Assistant here: [github.com/langchain-ai/executive-ai-assistant](https://github.com/langchain-ai/executive-ai-assistant) | ||
- See an open source Social Media Agent here: [github.com/langchain-ai/social-media-agent](https://github.com/langchain-ai/social-media-agent) |
Oops, something went wrong.