Mohammad Haghir commited on
Commit ·
474f370
1
Parent(s): 2e4c847
agent
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ from langchain_groq import ChatGroq
|
|
| 15 |
from langchain_core.messages import HumanMessage
|
| 16 |
|
| 17 |
from langgraph.graph import START, END, StateGraph
|
| 18 |
-
from langgraph.prebuilt import ToolNode
|
| 19 |
|
| 20 |
from agent_utils import wiki_ret
|
| 21 |
|
|
@@ -38,6 +38,10 @@ class BasicAgent:
|
|
| 38 |
print("BasicAgent initialized.")
|
| 39 |
self.graph = self.create_graph()
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
def agent(self, question: str) -> str:
|
| 42 |
|
| 43 |
# print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
@@ -78,13 +82,10 @@ class BasicAgent:
|
|
| 78 |
builder.add_node("tools", ToolNode(tools = [wiki_ret]))
|
| 79 |
|
| 80 |
builder.add_edge(START, "agent")
|
|
|
|
| 81 |
builder.add_edge("agent", END)
|
| 82 |
return builder.compile()
|
| 83 |
|
| 84 |
-
def __call___(self, question: str) -> str:
|
| 85 |
-
response = (self.graph).invoke({"messages": question})
|
| 86 |
-
return response
|
| 87 |
-
|
| 88 |
|
| 89 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 90 |
"""
|
|
|
|
| 15 |
from langchain_core.messages import HumanMessage
|
| 16 |
|
| 17 |
from langgraph.graph import START, END, StateGraph
|
| 18 |
+
from langgraph.prebuilt import ToolNode, tools_condition
|
| 19 |
|
| 20 |
from agent_utils import wiki_ret
|
| 21 |
|
|
|
|
| 38 |
print("BasicAgent initialized.")
|
| 39 |
self.graph = self.create_graph()
|
| 40 |
|
| 41 |
+
def __call___(self, question: str) -> str:
|
| 42 |
+
response = (self.graph).invoke({"messages": question})
|
| 43 |
+
return response
|
| 44 |
+
|
| 45 |
def agent(self, question: str) -> str:
|
| 46 |
|
| 47 |
# print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
|
|
| 82 |
builder.add_node("tools", ToolNode(tools = [wiki_ret]))
|
| 83 |
|
| 84 |
builder.add_edge(START, "agent")
|
| 85 |
+
builder.add_conditional_edges("agent", tools_condition)
|
| 86 |
builder.add_edge("agent", END)
|
| 87 |
return builder.compile()
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 91 |
"""
|