Initial commit
This commit is contained in:
463
README.md
Normal file
463
README.md
Normal file
@@ -0,0 +1,463 @@
|
||||
# LangGraph ReAct Agent Template
|
||||
|
||||
[](https://github.com/langchain-ai/react-agent/actions/workflows/unit-tests.yml)
|
||||
[](https://github.com/langchain-ai/react-agent/actions/workflows/integration-tests.yml)
|
||||
|
||||
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.
|
||||
|
||||

|
||||
|
||||
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.
|
||||
|
||||
## What it does
|
||||
|
||||
The ReAct agent:
|
||||
|
||||
1. Takes a user **query** as input
|
||||
2. Reasons about the query and decides on an action
|
||||
3. Executes the chosen action using available tools
|
||||
4. Observes the result of the action
|
||||
5. Repeats steps 2-4 until it can provide a final answer
|
||||
|
||||
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.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Assuming you have already [installed LangGraph Studio](https://github.com/langchain-ai/langgraph-studio?tab=readme-ov-file#download), to set up:
|
||||
|
||||
1. Create a `.env` file.
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
2. Define required API keys in your `.env` file.
|
||||
|
||||
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).
|
||||
|
||||
<!--
|
||||
Setup instruction auto-generated by `langgraph template lock`. DO NOT EDIT MANUALLY.
|
||||
-->
|
||||
|
||||
Set up your LLM API keys. This repo defaults to using [Claude](https://console.anthropic.com/login).
|
||||
|
||||
<!--
|
||||
End setup instructions
|
||||
-->
|
||||
|
||||
3. Customize whatever you'd like in the code.
|
||||
4. Open the folder LangGraph Studio!
|
||||
|
||||
## How to customize
|
||||
|
||||
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.
|
||||
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. **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.
|
||||
|
||||
You can also quickly extend this template by:
|
||||
|
||||
- Modifying the agent's reasoning process in [graph.py](./src/react_agent/graph.py).
|
||||
- Adjusting the ReAct loop or adding additional steps to the agent's decision-making process.
|
||||
|
||||
## Development
|
||||
|
||||
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!
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
LangGraph Studio also integrates with [LangSmith](https://smith.langchain.com/) for more in-depth tracing and collaboration with teammates.
|
||||
|
||||
<!--
|
||||
Configuration auto-generated by `langgraph template lock`. DO NOT EDIT MANUALLY.
|
||||
{
|
||||
"config_schemas": {
|
||||
"agent": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"system_prompt": {
|
||||
"type": "string",
|
||||
"default": "You are a helpful AI assistant.\n\nSystem time: {system_time}"
|
||||
},
|
||||
"model_name": {
|
||||
"type": "string",
|
||||
"default": "anthropic/claude-3-5-sonnet-20240620",
|
||||
"environment": [
|
||||
{
|
||||
"value": "anthropic/claude-1.2",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-2.0",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-2.1",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-3-5-sonnet-20240620",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-3-haiku-20240307",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-3-opus-20240229",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-3-sonnet-20240229",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-instant-1.2",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/gemma2-9b-it",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3-70b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3-70b-instruct-hf",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3-8b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3-8b-instruct-hf",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3p1-405b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3p1-405b-instruct-long",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3p1-70b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3p1-8b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/mixtral-8x22b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/mixtral-8x7b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/mixtral-8x7b-instruct-hf",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/mythomax-l2-13b",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/phi-3-vision-128k-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/phi-3p5-vision-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/starcoder-16b",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/yi-large",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo-0125",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo-0301",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo-0613",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo-1106",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo-16k",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo-16k-0613",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-0125-preview",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-0314",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-0613",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-1106-preview",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-32k",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-32k-0314",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-32k-0613",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-turbo",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-turbo-preview",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-vision-preview",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4o",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4o-mini",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
}
|
||||
]
|
||||
},
|
||||
"scraper_tool_model_name": {
|
||||
"type": "string",
|
||||
"default": "accounts/fireworks/models/firefunction-v2",
|
||||
"environment": [
|
||||
{
|
||||
"value": "anthropic/claude-1.2",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-2.0",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-2.1",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-3-5-sonnet-20240620",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-3-haiku-20240307",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-3-opus-20240229",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-3-sonnet-20240229",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "anthropic/claude-instant-1.2",
|
||||
"variables": "ANTHROPIC_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/gemma2-9b-it",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3-70b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3-70b-instruct-hf",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3-8b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3-8b-instruct-hf",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3p1-405b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3p1-405b-instruct-long",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3p1-70b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/llama-v3p1-8b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/mixtral-8x22b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/mixtral-8x7b-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/mixtral-8x7b-instruct-hf",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/mythomax-l2-13b",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/phi-3-vision-128k-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/phi-3p5-vision-instruct",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/starcoder-16b",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "fireworks/yi-large",
|
||||
"variables": "FIREWORKS_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo-0125",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo-0301",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo-0613",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo-1106",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo-16k",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-3.5-turbo-16k-0613",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-0125-preview",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-0314",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-0613",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-1106-preview",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-32k",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-32k-0314",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-32k-0613",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-turbo",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-turbo-preview",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4-vision-preview",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4o",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
},
|
||||
{
|
||||
"value": "openai/gpt-4o-mini",
|
||||
"variables": "OPENAI_API_KEY"
|
||||
}
|
||||
]
|
||||
},
|
||||
"max_search_results": {
|
||||
"type": "integer",
|
||||
"default": 10
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-->
|
||||
Reference in New Issue
Block a user