Scott Cogan commited on
Commit
db208ca
·
1 Parent(s): 7ec0166

langchain versions

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -9,7 +9,6 @@ from typing import IO, Dict
9
  from io import BytesIO
10
  from langchain_core.messages import HumanMessage, SystemMessage
11
  from langgraph.graph import StateGraph
12
- from langgraph.prebuilt import ToolNode
13
  import base64
14
  from google.ai.generativelanguage_v1beta.types import Tool as GenAITool
15
  from google import genai
@@ -201,7 +200,7 @@ class BasicAgent:
201
 
202
  # Define nodes: these do the work
203
  self.builder.add_node("assistant", self.assistant)
204
- self.builder.add_node("tools", ToolNode(self.tools))
205
 
206
  # Define edges: these determine how the control flow moves
207
  self.builder.add_edge("start", "assistant")
@@ -214,6 +213,14 @@ class BasicAgent:
214
  def assistant(self, state):
215
  return {"messages": [self.agent.invoke([self.sys_msg] + state["messages"])]}
216
 
 
 
 
 
 
 
 
 
217
  async def __call__(self, question: str, task_id: str) -> str:
218
  print(f"Agent received question (first 50 chars): {question[:50]}...")
219
  fixed_answer = "This is a default answer."
 
9
  from io import BytesIO
10
  from langchain_core.messages import HumanMessage, SystemMessage
11
  from langgraph.graph import StateGraph
 
12
  import base64
13
  from google.ai.generativelanguage_v1beta.types import Tool as GenAITool
14
  from google import genai
 
200
 
201
  # Define nodes: these do the work
202
  self.builder.add_node("assistant", self.assistant)
203
+ self.builder.add_node("tools", self.tools_node)
204
 
205
  # Define edges: these determine how the control flow moves
206
  self.builder.add_edge("start", "assistant")
 
213
  def assistant(self, state):
214
  return {"messages": [self.agent.invoke([self.sys_msg] + state["messages"])]}
215
 
216
+ def tools_node(self, state):
217
+ # Execute the tool and return the result
218
+ tool_name = state["messages"][-1].content
219
+ for tool in self.tools:
220
+ if tool.__name__ == tool_name:
221
+ return {"messages": [tool(*state["args"])]}
222
+ return {"messages": [f"Tool {tool_name} not found"]}
223
+
224
  async def __call__(self, question: str, task_id: str) -> str:
225
  print(f"Agent received question (first 50 chars): {question[:50]}...")
226
  fixed_answer = "This is a default answer."