Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
from typing import TypedDict, List, Dict, Any, Optional
|
| 4 |
from langgraph.graph import StateGraph, START, END, MessagesState
|
| 5 |
-
from langchain.agents import create_tool_calling_agent, AgentExecutor, initialize_agent
|
| 6 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 7 |
from langchain_groq import ChatGroq
|
| 8 |
from langchain_core.tools import tool
|
|
@@ -292,14 +292,20 @@ class BasicAgent:
|
|
| 292 |
("system", self.sys_prompt),
|
| 293 |
("human", "{input}")
|
| 294 |
])
|
| 295 |
-
self.agent = initialize_agent(
|
| 296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
llm=self.model,
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
system_prompt=self.prompt,
|
| 301 |
-
handle_parsing_errors="Check your output and make sure it conforms, use the Action/Action Input syntax"
|
| 302 |
)
|
|
|
|
| 303 |
# self.graph = self.__graph_compile__()
|
| 304 |
print("BasicAgent initialized.")
|
| 305 |
|
|
@@ -313,7 +319,8 @@ class BasicAgent:
|
|
| 313 |
question = f"{question} with TASK-ID: {task_id}"
|
| 314 |
# fixed_answer = self.agent.run(f'{question} with TASK-ID: {task_id}')
|
| 315 |
# fixed_answer = "This is a default answer."
|
| 316 |
-
fixed_answer = self.agent.run(question)
|
|
|
|
| 317 |
# human_message = [HumanMessage(content=question)]
|
| 318 |
# messages = self.graph.invoke({"messages": human_message})
|
| 319 |
# fixed_answer = messages['messages'][-1].content
|
|
|
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
from typing import TypedDict, List, Dict, Any, Optional
|
| 4 |
from langgraph.graph import StateGraph, START, END, MessagesState
|
| 5 |
+
from langchain.agents import create_tool_calling_agent, AgentExecutor, initialize_agent, create_react_agent
|
| 6 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 7 |
from langchain_groq import ChatGroq
|
| 8 |
from langchain_core.tools import tool
|
|
|
|
| 292 |
("system", self.sys_prompt),
|
| 293 |
("human", "{input}")
|
| 294 |
])
|
| 295 |
+
# self.agent = initialize_agent(
|
| 296 |
+
# tools=self.tools,
|
| 297 |
+
# llm=self.model,
|
| 298 |
+
# agent="zero-shot-react-description", # ReAct agent type
|
| 299 |
+
# verbose=True,
|
| 300 |
+
# system_prompt=self.prompt,
|
| 301 |
+
# handle_parsing_errors="Check your output and make sure it conforms, use the Action/Action Input syntax"
|
| 302 |
+
# )
|
| 303 |
+
self.agent = create_react_agent(
|
| 304 |
llm=self.model,
|
| 305 |
+
tools=self.tools,
|
| 306 |
+
prompt=self.prompt
|
|
|
|
|
|
|
| 307 |
)
|
| 308 |
+
self.agent_exe = AgentExecutor(agent=self.agent, tools=self.tools, verbose=True)
|
| 309 |
# self.graph = self.__graph_compile__()
|
| 310 |
print("BasicAgent initialized.")
|
| 311 |
|
|
|
|
| 319 |
question = f"{question} with TASK-ID: {task_id}"
|
| 320 |
# fixed_answer = self.agent.run(f'{question} with TASK-ID: {task_id}')
|
| 321 |
# fixed_answer = "This is a default answer."
|
| 322 |
+
# fixed_answer = self.agent.run(question)
|
| 323 |
+
fixed_answer = self.agent_exe.invoke({"input": question})
|
| 324 |
# human_message = [HumanMessage(content=question)]
|
| 325 |
# messages = self.graph.invoke({"messages": human_message})
|
| 326 |
# fixed_answer = messages['messages'][-1].content
|