Skip to content

Commit b250de6

Browse files
authored
Merge pull request #61 from nextcloud/prompt_tuning
Only add specific tool info to system prompt when tool is enabled
2 parents 1ced045 + 887d905 commit b250de6

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

ex_app/lib/agent.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,45 @@ async def react(task, nc: Nextcloud):
4949

5050
model.bind_nextcloud(nc)
5151

52+
tools = dangerous_tools + safe_tools
53+
5254
bound_model = model.bind_tools(
53-
dangerous_tools
54-
+ safe_tools
55+
tools,
5556
)
5657

58+
def tool_enabled(tool_name):
59+
for tool in tools:
60+
if tool.name == tool_name:
61+
return True
62+
return False
63+
5764
async def call_model(
5865
state: AgentState,
5966
config: RunnableConfig,
6067
):
6168
current_date = date.today().strftime("%Y-%m-%d")
62-
# this is similar to customizing the create_react_agent with state_modifier, but is a lot more flexible
63-
system_prompt = SystemMessage(
64-
"""
69+
70+
system_prompt_text = """
6571
You are a helpful AI assistant with access to tools, please respond to the user's query to the best of your ability, using the provided tools if necessary. If no tool is needed to provide a correct answer, do not use one. If you used a tool, you still need to convey its output to the user.
6672
Use the same language for your answers as the user used in their message.
6773
Today is {CURRENT_DATE}.
6874
Intuit the language the user is using (there is no tool for this, you will need to guess). Reply in the language intuited. Do not output the language you intuited.
6975
Only use tools if you cannot answer the user without them.
70-
Only use the duckduckgo_results_json tool if the user explicitly asks for a web search.
71-
You can check which conversations exist using the list_talk_conversations tool, if a conversation cannot be found.
72-
You can check which calendars exist using the list_calendars tool, if a calendar can not be found.
73-
you can find out a user's email address and location by using the find_person_in_contacts tool.
74-
you can find out the current user's location by using the find_details_of_current_user tool.
75-
If an item should be added to a list, check list_calendars for a fitting calendar and add the item as a task there.
7676
If you get a link as a tool output, always add the link to your response.
77-
""".replace("{CURRENT_DATE}", current_date)
77+
"""
78+
if tool_enabled("duckduckgo_results_json"):
79+
system_prompt_text += "Only use the duckduckgo_results_json tool if the user explicitly asks for a web search.\n"
80+
if tool_enabled("list_talk_conversations"):
81+
system_prompt_text += "Use the list_talk_conversations tool to check which conversations exist.\n"
82+
if tool_enabled("list_calendars"):
83+
system_prompt_text += "Use the list_calendars tool to check which calendars exist.\nIf an item should be added to a list, check list_calendars for a fitting calendar and add the item as a task there.\n"
84+
if tool_enabled("find_person_in_contacts"):
85+
system_prompt_text += "Use the find_person_in_contacts tool to find a person's email address and location.\n"
86+
if tool_enabled("find_details_of_current_user"):
87+
system_prompt_text += "Use the find_details_of_current_user tool to find the current user's location.\n"
88+
# this is similar to customizing the create_react_agent with state_modifier, but is a lot more flexible
89+
system_prompt = SystemMessage(
90+
system_prompt_text.replace("{CURRENT_DATE}", current_date)
7891
)
7992

8093
response = await bound_model.ainvoke([system_prompt] + state["messages"], config)

0 commit comments

Comments
 (0)