generated from langchain-ai/react-agent
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Remove react agent code)
- Loading branch information
Showing
20 changed files
with
170 additions
and
785 deletions.
There are no files selected for viewing
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
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
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
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,7 +1,7 @@ | ||
{ | ||
"dependencies": ["."], | ||
"graphs": { | ||
"agent": "./src/react_agent/graph.py:graph" | ||
"agent": "./src/agent/graph.py:graph" | ||
}, | ||
"env": ".env" | ||
} |
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,7 +1,7 @@ | ||
[project] | ||
name = "react-agent" | ||
name = "agent" | ||
version = "0.0.1" | ||
description = "Starter template for making a custom Reasoning and Action agent (using tool calling) in LangGraph." | ||
description = "Starter template for making a new agent LangGraph." | ||
authors = [ | ||
{ name = "William Fu-Hinthorn", email = "[email protected]" }, | ||
] | ||
|
@@ -10,13 +10,7 @@ license = { text = "MIT" } | |
requires-python = ">=3.9" | ||
dependencies = [ | ||
"langgraph>=0.2.6", | ||
"langchain-openai>=0.1.22", | ||
"langchain-anthropic>=0.1.23", | ||
"langchain>=0.2.14", | ||
"langchain-fireworks>=0.1.7", | ||
"python-dotenv>=1.0.1", | ||
"langchain-community>=0.2.17", | ||
"tavily-python>=0.4.0", | ||
] | ||
|
||
|
||
|
@@ -28,10 +22,10 @@ requires = ["setuptools>=73.0.0", "wheel"] | |
build-backend = "setuptools.build_meta" | ||
|
||
[tool.setuptools] | ||
packages = ["langgraph.templates.react_agent", "react_agent"] | ||
packages = ["langgraph.templates.agent", "agent"] | ||
[tool.setuptools.package-dir] | ||
"langgraph.templates.react_agent" = "src/react_agent" | ||
"react_agent" = "src/react_agent" | ||
"langgraph.templates.agent" = "src/agent" | ||
"agent" = "src/agent" | ||
|
||
|
||
[tool.setuptools.package-data] | ||
|
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,8 @@ | ||
"""New LangGraph Agent. | ||
This module defines a custom graph. | ||
""" | ||
|
||
from agent.graph import graph | ||
|
||
__all__ = ["graph"] |
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,24 @@ | ||
"""Define the configurable parameters for the agent.""" | ||
|
||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass, fields | ||
from typing import Optional | ||
|
||
from langchain_core.runnables import RunnableConfig | ||
|
||
|
||
@dataclass(kw_only=True) | ||
class Configuration: | ||
"""The configuration for the agent.""" | ||
|
||
model_name: str = "my-model" | ||
|
||
@classmethod | ||
def from_runnable_config( | ||
cls, config: Optional[RunnableConfig] = None | ||
) -> Configuration: | ||
"""Create a Configuration instance from a RunnableConfig object.""" | ||
configurable = (config.get("configurable") or {}) if config else {} | ||
_fields = {f.name for f in fields(cls) if f.init} | ||
return cls(**{k: v for k, v in configurable.items() if k in _fields}) |
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,66 @@ | ||
"""Define a simple chatbot agent. | ||
This agent returns a predefined response without using an actual LLM. | ||
""" | ||
|
||
from typing import Dict, List | ||
|
||
from langchain_core.messages import AIMessage | ||
from langchain_core.runnables import RunnableConfig | ||
from langgraph.graph import StateGraph | ||
|
||
from agent.configuration import Configuration | ||
from agent.state import State | ||
|
||
# Define the function that simulates calling a model | ||
|
||
|
||
async def call_model( | ||
state: State, config: RunnableConfig | ||
) -> Dict[str, List[AIMessage]]: | ||
"""Simulate calling an LLM by returning a predefined response. | ||
Args: | ||
_state (State): The current state of the conversation (unused). | ||
_config (RunnableConfig): Configuration for the run (unused). | ||
Returns: | ||
dict: A dictionary containing the predefined response message. | ||
""" | ||
configuration = Configuration.from_runnable_config(config) | ||
# Return a predefined response | ||
return { | ||
"messages": [AIMessage(content=f"Hi there! This is {configuration.model_name}")] | ||
} | ||
|
||
|
||
# Define the routing function | ||
def route(state: State) -> str: | ||
"""Determine whether to continue the conversation or end it. | ||
Args: | ||
state (State): The current state of the conversation. | ||
Returns: | ||
str: Either "call_model" to continue or "__end__" to finish. | ||
""" | ||
if len(state.messages) > 5: # End after 5 interactions | ||
return "__end__" | ||
return "call_model" | ||
|
||
|
||
# Define a new graph | ||
workflow = StateGraph(State, config_schema=Configuration) | ||
|
||
# Add the node to the graph | ||
workflow.add_node("call_model", call_model) | ||
|
||
# Set the entrypoint as `call_model` | ||
workflow.add_edge("__start__", "call_model") | ||
|
||
# Add conditional edge | ||
workflow.add_conditional_edges("call_model", route) | ||
|
||
# Compile the workflow into an executable graph | ||
graph = workflow.compile() | ||
graph.name = "Simple Chatbot" # This defines the custom name in LangSmith |
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,25 @@ | ||
"""Define the state structures for the agent.""" | ||
|
||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass, field | ||
from typing import List | ||
|
||
from langchain_core.messages import AnyMessage | ||
from langgraph.graph import add_messages | ||
from typing_extensions import Annotated | ||
|
||
|
||
@dataclass | ||
class State: | ||
"""Defines the input state for the agent, representing a narrower interface to the outside world. | ||
This class is used to define the initial state and structure of incoming data. | ||
""" | ||
|
||
messages: Annotated[List[AnyMessage], add_messages] = field(default_factory=list) | ||
""" | ||
Messages tracking the primary execution state of the agent. | ||
Typically accumulates a pattern of user, assistant, user, ... etc. messages. | ||
""" |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.