Isaacgv commited on
Commit
cb3750e
·
verified ·
1 Parent(s): 3810434

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +25 -4
agent.py CHANGED
@@ -112,6 +112,22 @@ def arvix_search(query: str) -> str:
112
 
113
 
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  tools = [
117
  multiply,
@@ -155,20 +171,25 @@ def build_graph(provider: str = "huggingface"):
155
  def assistant(state: MessagesState):
156
  """Assistant node"""
157
  return {"messages": [llm_with_tools.invoke(state["messages"])]}
 
 
 
 
 
158
 
159
 
160
 
161
  builder = StateGraph(MessagesState)
162
-
163
  builder.add_node("assistant", assistant)
164
  builder.add_node("tools", ToolNode(tools))
165
-
166
- builder.add_edge(START, "assistant")
167
  builder.add_conditional_edges(
168
  "assistant",
169
  tools_condition,
170
  )
171
- builder.add_edge("tools", "assistant")
172
 
173
  # Compile graph
174
  return builder.compile()
 
112
 
113
 
114
 
115
+ system_prompt= '''
116
+ You are a helpful assistant with access to tools for answering questions. For each question, think step by step and clearly explain your reasoning. Conclude your response using the following format:
117
+
118
+ FINAL ANSWER: [YOUR FINAL ANSWER]
119
+
120
+ Formatting rules for YOUR FINAL ANSWER:
121
+
122
+ If the answer is a number, write it as digits only. Do not include commas or units (e.g. $, %, etc.) unless explicitly required.
123
+
124
+ If the answer is a string, avoid articles ("a", "an", "the"), do not use abbreviations (e.g., for cities), and spell out all digits (e.g., "two thousand").
125
+
126
+ If the answer is a comma-separated list, apply the above rules to each item in the list, depending on whether they are numbers or strings.
127
+
128
+ Your answer should only begin with "FINAL ANSWER: " followed directly by the formatted result. Nothing else should follow.
129
+ '''
130
+ sys_msg = SystemMessage(content=system_prompt)
131
 
132
  tools = [
133
  multiply,
 
171
  def assistant(state: MessagesState):
172
  """Assistant node"""
173
  return {"messages": [llm_with_tools.invoke(state["messages"])]}
174
+
175
+ def retriever(state: MessagesState):
176
+ """Retriever node"""
177
+
178
+ return {"messages": [sys_msg] }
179
 
180
 
181
 
182
  builder = StateGraph(MessagesState)
183
+ builder.add_node("retriever", retriever)
184
  builder.add_node("assistant", assistant)
185
  builder.add_node("tools", ToolNode(tools))
186
+ builder.add_edge(START, "retriever")
187
+ builder.add_edge("retriever", "assistant")
188
  builder.add_conditional_edges(
189
  "assistant",
190
  tools_condition,
191
  )
192
+ builder.add_edge("tools", "assistant"))
193
 
194
  # Compile graph
195
  return builder.compile()