Spaces:
Running
Running
Update agent.py
Browse files
agent.py
CHANGED
@@ -4,7 +4,7 @@ from langchain_core.tools import tool
|
|
4 |
from langchain_openai import ChatOpenAI
|
5 |
from langgraph.graph import END, StateGraph
|
6 |
from langgraph.prebuilt import ToolNode
|
7 |
-
from
|
8 |
from langchain_community.utilities import WikipediaAPIWrapper
|
9 |
from langchain.agents import create_tool_calling_agent
|
10 |
from langchain.agents import AgentExecutor
|
@@ -12,7 +12,6 @@ from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
12 |
import operator
|
13 |
import json
|
14 |
|
15 |
-
|
16 |
# Define the agent state
|
17 |
class AgentState(TypedDict):
|
18 |
messages: Annotated[Sequence[BaseMessage], operator.add]
|
@@ -32,9 +31,9 @@ def web_search(query: str, num_results: int = 3) -> list:
|
|
32 |
@tool
|
33 |
def calculate(expression: str) -> str:
|
34 |
"""Evaluate mathematical expressions."""
|
35 |
-
from
|
36 |
-
|
37 |
-
return
|
38 |
|
39 |
class AdvancedAIAgent:
|
40 |
def __init__(self, model_name="gpt-4-turbo"):
|
@@ -65,7 +64,7 @@ class AdvancedAIAgent:
|
|
65 |
|
66 |
# Define nodes
|
67 |
workflow.add_node("agent", self._call_agent)
|
68 |
-
workflow.add_node("tools", ToolNode(self.tools))
|
69 |
|
70 |
# Define edges
|
71 |
workflow.set_entry_point("agent")
|
|
|
4 |
from langchain_openai import ChatOpenAI
|
5 |
from langgraph.graph import END, StateGraph
|
6 |
from langgraph.prebuilt import ToolNode
|
7 |
+
from langchain_community.tools import DuckDuckGoSearchResults
|
8 |
from langchain_community.utilities import WikipediaAPIWrapper
|
9 |
from langchain.agents import create_tool_calling_agent
|
10 |
from langchain.agents import AgentExecutor
|
|
|
12 |
import operator
|
13 |
import json
|
14 |
|
|
|
15 |
# Define the agent state
|
16 |
class AgentState(TypedDict):
|
17 |
messages: Annotated[Sequence[BaseMessage], operator.add]
|
|
|
31 |
@tool
|
32 |
def calculate(expression: str) -> str:
|
33 |
"""Evaluate mathematical expressions."""
|
34 |
+
from langchain_experimental.tools import PythonREPLTool
|
35 |
+
python_repl = PythonREPLTool()
|
36 |
+
return python_repl.run(f"print({expression})")
|
37 |
|
38 |
class AdvancedAIAgent:
|
39 |
def __init__(self, model_name="gpt-4-turbo"):
|
|
|
64 |
|
65 |
# Define nodes
|
66 |
workflow.add_node("agent", self._call_agent)
|
67 |
+
workflow.add_node("tools", ToolNode(self.tools))
|
68 |
|
69 |
# Define edges
|
70 |
workflow.set_entry_point("agent")
|