Paperbag commited on
Commit
3b80656
·
1 Parent(s): 6a9721c

update tool calling

Browse files
Files changed (1) hide show
  1. agent.py +26 -1
agent.py CHANGED
@@ -59,6 +59,26 @@ def read_message(state: AgentState) -> AgentState:
59
  # Just pass the messages through to the next node
60
  return {"messages": messages}
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  def answer_message(state: AgentState) -> AgentState:
64
  messages = state["messages"]
@@ -69,6 +89,10 @@ def answer_message(state: AgentState) -> AgentState:
69
  Do not include any thought process before answering the question, and only response exactly what was being asked of you.
70
  If you are not able to provide an answer, please state the limitation that you're facing instead.
71
 
 
 
 
 
72
  Example question: How many hours are there in a day?
73
  Response: 24
74
 
@@ -76,11 +100,12 @@ def answer_message(state: AgentState) -> AgentState:
76
  {messages}
77
 
78
  """
79
- response = model.invoke(prompt)
80
  # Append the model's answer to the messages list
81
  return {"messages": messages + [response]}
82
 
83
 
 
84
  def build_graph():
85
  agent_graph = StateGraph(AgentState)
86
 
 
59
  # Just pass the messages through to the next node
60
  return {"messages": messages}
61
 
62
+ # def tool_message(state: AgentState) -> AgentState:
63
+ # messages = state["messages"]
64
+ # prompt = f"""
65
+ # You are a GAIA question answering expert.
66
+ # Your task is to decide whether to use a tool or not.
67
+ # If you need to use a tool, answer ONLY:
68
+ # CALL_TOOL: <your tool name>
69
+ # If you do not need to use a tool, answer ONLY:
70
+ # NO_TOOL
71
+ # Here is the question:
72
+ # {messages}
73
+ # """
74
+ # return {"messages": messages}
75
+ # response = model_with_tools.invoke(prompt)
76
+ # return {"messages": messages + [response]}
77
+
78
+ # Augment the LLM with tools
79
+ tools = [web_search]
80
+ tools_by_name = {tool.name: tool for tool in tools}
81
+ model_with_tools = model.bind_tools(tools)
82
 
83
  def answer_message(state: AgentState) -> AgentState:
84
  messages = state["messages"]
 
89
  Do not include any thought process before answering the question, and only response exactly what was being asked of you.
90
  If you are not able to provide an answer, please state the limitation that you're facing instead.
91
 
92
+ You can optionally use a web search tool.
93
+ if you need web information, answer ONLY:
94
+ CALL_WEB_SEARCH: <your search query>
95
+
96
  Example question: How many hours are there in a day?
97
  Response: 24
98
 
 
100
  {messages}
101
 
102
  """
103
+ response = model_with_tools.invoke(prompt)
104
  # Append the model's answer to the messages list
105
  return {"messages": messages + [response]}
106
 
107
 
108
+
109
  def build_graph():
110
  agent_graph = StateGraph(AgentState)
111