Spaces:
Runtime error
Runtime error
ernani
commited on
Commit
·
2c04564
1
Parent(s):
fa91962
updating tools - memory persistency
Browse files
app.py
CHANGED
|
@@ -10,9 +10,8 @@ from langgraph.prebuilt import tools_condition
|
|
| 10 |
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 11 |
from langgraph.prebuilt import create_react_agent
|
| 12 |
from langgraph.store.memory import InMemoryStore
|
| 13 |
-
from langmem import create_manage_memory_tool, create_search_memory_tool
|
| 14 |
|
| 15 |
-
from tools import weather_info_tool, hub_stats_tool,
|
| 16 |
from retriever import load_guest_dataset
|
| 17 |
|
| 18 |
# Initialize the Hugging Face model
|
|
@@ -34,23 +33,19 @@ store = InMemoryStore(
|
|
| 34 |
)
|
| 35 |
|
| 36 |
|
| 37 |
-
agent = create_react_agent(
|
| 38 |
-
llm,
|
| 39 |
-
tools=[
|
| 40 |
-
# Memory tools use LangGraph's BaseStore for persistence (4)
|
| 41 |
-
create_manage_memory_tool(namespace=("memories",)),
|
| 42 |
-
create_search_memory_tool(namespace=("memories",)),
|
| 43 |
-
],
|
| 44 |
-
store=store,
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
# adding tools
|
| 48 |
|
| 49 |
guest_info_tool = load_guest_dataset()
|
| 50 |
|
| 51 |
-
tools = [guest_info_tool, weather_info_tool, hub_stats_tool, duckduckgo_search_tool,
|
| 52 |
chat_with_tools = chat.bind_tools(tools)
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
# Generate the AgentState and Agent graph
|
| 55 |
class AgentState(TypedDict):
|
| 56 |
messages: Annotated[list[AnyMessage], add_messages]
|
|
|
|
| 10 |
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 11 |
from langgraph.prebuilt import create_react_agent
|
| 12 |
from langgraph.store.memory import InMemoryStore
|
|
|
|
| 13 |
|
| 14 |
+
from tools import weather_info_tool, hub_stats_tool, duckduckgo_search_tool, manage_memory_tool, search_memory_tool
|
| 15 |
from retriever import load_guest_dataset
|
| 16 |
|
| 17 |
# Initialize the Hugging Face model
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
# adding tools
|
| 37 |
|
| 38 |
guest_info_tool = load_guest_dataset()
|
| 39 |
|
| 40 |
+
tools = [guest_info_tool, weather_info_tool, hub_stats_tool, duckduckgo_search_tool, manage_memory_tool, search_memory_tool]
|
| 41 |
chat_with_tools = chat.bind_tools(tools)
|
| 42 |
|
| 43 |
+
agent = create_react_agent(
|
| 44 |
+
"openai:gpt-4o",
|
| 45 |
+
tools=tools,
|
| 46 |
+
store=store,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
# Generate the AgentState and Agent graph
|
| 50 |
class AgentState(TypedDict):
|
| 51 |
messages: Annotated[list[AnyMessage], add_messages]
|
tools.py
CHANGED
|
@@ -3,6 +3,7 @@ from langchain_community.tools import DuckDuckGoSearchRun
|
|
| 3 |
from langgraph.store.memory import InMemoryStore
|
| 4 |
import random
|
| 5 |
from huggingface_hub import list_models
|
|
|
|
| 6 |
|
| 7 |
# Initialize the DuckDuckGo search tool
|
| 8 |
search_tool = DuckDuckGoSearchRun()
|
|
@@ -72,5 +73,6 @@ duckduckgo_search_tool = Tool(
|
|
| 72 |
description="Searches the web for information."
|
| 73 |
)
|
| 74 |
|
| 75 |
-
|
|
|
|
| 76 |
|
|
|
|
| 3 |
from langgraph.store.memory import InMemoryStore
|
| 4 |
import random
|
| 5 |
from huggingface_hub import list_models
|
| 6 |
+
from langmem import create_manage_memory_tool, create_search_memory_tool
|
| 7 |
|
| 8 |
# Initialize the DuckDuckGo search tool
|
| 9 |
search_tool = DuckDuckGoSearchRun()
|
|
|
|
| 73 |
description="Searches the web for information."
|
| 74 |
)
|
| 75 |
|
| 76 |
+
manage_memory_tool = create_manage_memory_tool(namespace=("memories",))
|
| 77 |
+
search_memory_tool = create_search_memory_tool(namespace=("memories",))
|
| 78 |
|