Spaces:
Sleeping
Sleeping
EtienneB
commited on
Commit
·
85ecabb
1
Parent(s):
8ca5d55
updated tools and added systemprompt
Browse files- __pycache__/tools.cpython-313.pyc +0 -0
- agent.py +19 -8
- app.py +9 -1
__pycache__/tools.cpython-313.pyc
CHANGED
Binary files a/__pycache__/tools.cpython-313.pyc and b/__pycache__/tools.cpython-313.pyc differ
|
|
agent.py
CHANGED
@@ -12,7 +12,7 @@ from tools import (absolute, add, analyze_excel_file, arvix_search,
|
|
12 |
divide, exponential, factorial, floor_divide,
|
13 |
get_current_time_in_timezone, greatest_common_divisor,
|
14 |
is_prime, least_common_multiple, logarithm, modulus,
|
15 |
-
multiply, percentage_calculator, power,
|
16 |
roman_calculator_converter, square_root, subtract,
|
17 |
web_search, wiki_search)
|
18 |
|
@@ -28,9 +28,20 @@ tools = [
|
|
28 |
get_current_time_in_timezone, compound_interest,
|
29 |
convert_temperature, factorial, greatest_common_divisor,
|
30 |
is_prime, least_common_multiple, percentage_calculator,
|
31 |
-
wiki_search, analyze_excel_file, arvix_search, audio_transcription
|
32 |
]
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
def build_graph():
|
35 |
"""Build the graph"""
|
36 |
|
@@ -52,17 +63,17 @@ def build_graph():
|
|
52 |
# Node
|
53 |
def assistant(state: MessagesState):
|
54 |
"""Assistant node"""
|
55 |
-
return {"messages": [llm_with_tools.invoke(state["messages"])]}
|
56 |
|
57 |
-
|
58 |
builder = StateGraph(MessagesState)
|
|
|
|
|
59 |
builder.add_node("assistant", assistant)
|
60 |
builder.add_node("tools", ToolNode(tools))
|
61 |
-
|
62 |
-
|
63 |
-
tools_condition,
|
64 |
-
)
|
65 |
builder.add_edge(START, "assistant")
|
|
|
66 |
builder.add_edge("tools", "assistant")
|
67 |
|
68 |
# Compile graph
|
|
|
12 |
divide, exponential, factorial, floor_divide,
|
13 |
get_current_time_in_timezone, greatest_common_divisor,
|
14 |
is_prime, least_common_multiple, logarithm, modulus,
|
15 |
+
multiply, percentage_calculator, power, python_code_parser,
|
16 |
roman_calculator_converter, square_root, subtract,
|
17 |
web_search, wiki_search)
|
18 |
|
|
|
28 |
get_current_time_in_timezone, compound_interest,
|
29 |
convert_temperature, factorial, greatest_common_divisor,
|
30 |
is_prime, least_common_multiple, percentage_calculator,
|
31 |
+
wiki_search, analyze_excel_file, arvix_search, audio_transcription, python_code_parser
|
32 |
]
|
33 |
|
34 |
+
|
35 |
+
# Load system prompt
|
36 |
+
system_prompt = """
|
37 |
+
You are a helpful assistant tasked with answering questions using a set of tools.
|
38 |
+
Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
39 |
+
FINAL ANSWER: [YOUR FINAL ANSWER].
|
40 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. 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. 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. 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.
|
41 |
+
Your answer should only start with "FINAL ANSWER: ", then follows with the answer.
|
42 |
+
"""
|
43 |
+
|
44 |
+
|
45 |
def build_graph():
|
46 |
"""Build the graph"""
|
47 |
|
|
|
63 |
# Node
|
64 |
def assistant(state: MessagesState):
|
65 |
"""Assistant node"""
|
66 |
+
return {"messages": [llm_with_tools.invoke([system_prompt] + state["messages"])]}
|
67 |
|
|
|
68 |
builder = StateGraph(MessagesState)
|
69 |
+
|
70 |
+
# Nodes
|
71 |
builder.add_node("assistant", assistant)
|
72 |
builder.add_node("tools", ToolNode(tools))
|
73 |
+
|
74 |
+
# Edges
|
|
|
|
|
75 |
builder.add_edge(START, "assistant")
|
76 |
+
builder.add_conditional_edges("assistant", tools_condition)
|
77 |
builder.add_edge("tools", "assistant")
|
78 |
|
79 |
# Compile graph
|
app.py
CHANGED
@@ -26,7 +26,15 @@ class BasicAgent:
|
|
26 |
messages = [HumanMessage(content=question)]
|
27 |
messages = self.graph.invoke({"messages": messages})
|
28 |
answer = messages['messages'][-1].content
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
|
32 |
|
|
|
26 |
messages = [HumanMessage(content=question)]
|
27 |
messages = self.graph.invoke({"messages": messages})
|
28 |
answer = messages['messages'][-1].content
|
29 |
+
print(f"Agent full response: {answer}")
|
30 |
+
|
31 |
+
# Optionally trim the "Final Answer: " prefix only if it exists
|
32 |
+
if answer.startswith("Final Answer:"):
|
33 |
+
return answer[len("Final Answer:"):].strip()
|
34 |
+
else:
|
35 |
+
return answer.strip()
|
36 |
+
|
37 |
+
|
38 |
|
39 |
|
40 |
|