WeByT3 commited on
Commit
9a4d131
·
verified ·
1 Parent(s): d1343b6

Update agent.py

Browse files
Files changed (1) hide show
  1. agent.py +18 -1
agent.py CHANGED
@@ -19,15 +19,32 @@ def build_agent():
19
  "messages": [chat_with_tools.invoke(state["messages"])],
20
  }
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  ## The graph
23
  builder = StateGraph(MessagesState)
24
 
25
  # Define nodes: these do the work
 
26
  builder.add_node("assistant", assistant)
27
  builder.add_node("tools", ToolNode(tools))
28
 
29
  # Define edges: these determine how the control flow moves
30
- builder.add_edge(START, "assistant")
 
31
  builder.add_conditional_edges(
32
  "assistant",
33
  # If the latest message requires a tool, route to tools
 
19
  "messages": [chat_with_tools.invoke(state["messages"])],
20
  }
21
 
22
+ def enhancer(state: MessagesState):
23
+ system_propmt = """
24
+ You are a helpful assistant tasked with answering questions using a set of tools.
25
+ Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
26
+ FINAL ANSWER: [YOUR FINAL ANSWER].
27
+ YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings.
28
+ If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise.
29
+ If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise.
30
+ If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
31
+ Your answer should only start with "FINAL ANSWER: ", then follows with the answer.
32
+ """
33
+ return {
34
+ "messages": [sys_msg] + state["messages"]
35
+ }
36
+
37
  ## The graph
38
  builder = StateGraph(MessagesState)
39
 
40
  # Define nodes: these do the work
41
+ builder.add_node("enhancer", enhancer)
42
  builder.add_node("assistant", assistant)
43
  builder.add_node("tools", ToolNode(tools))
44
 
45
  # Define edges: these determine how the control flow moves
46
+ builder.add_edge(START, "enhancer")
47
+ builder.add_edge("enhancer", "assistant")
48
  builder.add_conditional_edges(
49
  "assistant",
50
  # If the latest message requires a tool, route to tools