You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This template showcases a [ReAct agent](https://arxiv.org/abs/2210.03629) implemented using [LangGraph](https://github.com/langchain-ai/langgraph), designed for [LangGraph Studio](https://github.com/langchain-ai/langgraph-studio). ReAct agents are uncomplicated, prototypical agents that can be flexibly extended to many tools.
4
7
5
8

6
9
7
-
## Repo Structure
8
-
9
-
```txt
10
-
├── LICENSE
11
-
├── README.md
12
-
├── langgraph.json
13
-
├── poetry.lock
14
-
├── pyproject.toml
15
-
├── react_agent
16
-
│ ├── __init__.py
17
-
│ ├── graph.py
18
-
│ └── utils
19
-
│ ├── __init__.py
20
-
│ ├── configuration.py # Define the configurable variables
21
-
│ ├── state.py # Define state variables and how they're updated
22
-
│ ├── tools.py # Define the tools your agent can access
23
-
│ └── utils.py # Other sundry utilities
24
-
└── tests # Add whatever tests you'd like here
25
-
├── integration_tests
26
-
│ └── __init__.py
27
-
└── unit_tests
28
-
└── __init__.py
10
+
The core logic, defined in `src/react_agent/graph.py`, demonstrates a flexible ReAct agent that iteratively reasons about user queries and executes actions, showcasing the power of this approach for complex problem-solving tasks.
11
+
12
+
## What it does
13
+
14
+
The ReAct agent:
15
+
16
+
1. Takes a user **query** as input
17
+
2. Reasons about the query and decides on an action
18
+
3. Executes the chosen action using available tools
19
+
4. Observes the result of the action
20
+
5. Repeats steps 2-4 until it can provide a final answer
21
+
22
+
By default, it's set up with a basic set of tools, but can be easily extended with custom tools to suit various use cases.
23
+
24
+
## Getting Started
25
+
26
+
Assuming you have already [installed LangGraph Studio](https://github.com/langchain-ai/langgraph-studio?tab=readme-ov-file#download), to set up:
27
+
28
+
1. Create a `.env` file.
29
+
30
+
```bash
31
+
cp .env.example .env
32
+
```
33
+
34
+
2. Define required API keys in your `.env` file.
35
+
36
+
The primary [search tool](./src/react_agent/tools.py)[^1] used is [Tavily](https://tavily.com/). Create an API key [here](https://app.tavily.com/sign-in).
37
+
38
+
<!--
39
+
Setup instruction auto-generated by `langgraph template lock`. DO NOT EDIT MANUALLY.
40
+
-->
41
+
42
+
<details>
43
+
<summary>Setup for `model_name` and `scraper_tool_model_name`</summary>
Follow the instructions below to get set up, or pick one of the additional options.
52
+
53
+
### Anthropic Chat Models
54
+
55
+
To use Anthropic's chat models:
56
+
57
+
1. Sign up for an [Anthropic API key](https://console.anthropic.com/) if you haven't already.
58
+
2. Once you have your API key, add it to your `.env` file:
59
+
60
+
```
61
+
ANTHROPIC_API_KEY=your-api-key
62
+
```
63
+
### Fireworks Chat Models
64
+
65
+
To use Fireworks AI's chat models:
66
+
67
+
1. Sign up for a [Fireworks AI account](https://app.fireworks.ai/signup) and obtain an API key.
68
+
2. Add your Fireworks AI API key to your `.env` file:
69
+
70
+
```
71
+
FIREWORKS_API_KEY=your-api-key
72
+
```
73
+
#### OpenAI Chat Models
74
+
75
+
To use OpenAI's chat models:
76
+
77
+
1. Sign up for an [OpenAI API key](https://platform.openai.com/signup).
78
+
2. Once you have your API key, add it to your `.env` file:
79
+
```
80
+
OPENAI_API_KEY=your-api-key
29
81
```
30
82
83
+
</details>
84
+
85
+
86
+
87
+
<!--
88
+
End setup instructions
89
+
-->
90
+
91
+
92
+
3. Customize whatever you'd like in the code.
93
+
4. Open the folder LangGraph Studio!
94
+
95
+
## How to customize
96
+
97
+
1. **Add new tools**: Extend the agent's capabilities by adding new tools in [tools.py](./src/react_agent/tools.py). These can be any Python functions that perform specific tasks.
98
+
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`.
99
+
3. **Customize the prompt**: We provide a default system prompt in [configuration.py](./src/react_agent/configuration.py). You can easily update this via configuration in the studio.
100
+
101
+
You can also quickly extend this template by:
102
+
103
+
- Modifying the agent's reasoning process in [graph.py](./src/react_agent/graph.py).
104
+
- Adjusting the ReAct loop or adding additional steps to the agent's decision-making process.
105
+
106
+
## Development
107
+
108
+
While iterating on your graph, you can edit past state and rerun your app from past states to debug specific nodes. Local changes will be automatically applied via hot reload. Try adding an interrupt before the agent calls tools, updating the default system message in `src/react_agent/configuration.py` to take on a persona, or adding additional nodes and edges!
109
+
110
+
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.
111
+
112
+
You can find the latest (under construction) docs on [LangGraph](https://github.com/langchain-ai/langgraph) here, including examples and other references. Using those guides can help you pick the right patterns to adapt here for your use case.
113
+
114
+
LangGraph Studio also integrates with [LangSmith](https://smith.langchain.com/) for more in-depth tracing and collaboration with teammates.
115
+
31
116
<!--
32
117
Configuration auto-generated by `langgraph template lock`. DO NOT EDIT MANUALLY.
33
118
{
@@ -37,7 +122,7 @@ Configuration auto-generated by `langgraph template lock`. DO NOT EDIT MANUALLY.
37
122
"properties": {
38
123
"system_prompt": {
39
124
"type": "string",
40
-
"default": "You are a helpful AI assistant.\nSystem time: {system_time}"
125
+
"default": "You are a helpful AI assistant.\n\nSystem time: {system_time}"
41
126
},
42
127
"model_name": {
43
128
"type": "string",
@@ -410,9 +495,13 @@ Configuration auto-generated by `langgraph template lock`. DO NOT EDIT MANUALLY.
0 commit comments