Skip to content

Commit 301bf7a

Browse files
authored
Merge pull request #22 from nextcloud/feat/tool-info
Feat: tool info as optional output shape
2 parents 86bca31 + c2190c5 commit 301bf7a

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

ex_app/lib/agent.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def call_model(
6969
Use the same language for your answers as the user used in their message.
7070
Today is {CURRENT_DATE}.
7171
Detect the language the user is using. Reply in the detected language. Do not output the detected language.
72-
Only use the duckduckgo_results_json tool if the user explicitly asks for a web search.
72+
Only use the duckduckgo_results_json tool if the user explicitly asks for a web search.
7373
You can check which conversations exist using the list_talk_conversations tool, if a conversation cannot be found.
7474
You can check which calendars exist using the list_calendars tool, if a calendar can not be found.
7575
you can find out a user's email address and location by using the find_person_in_contacts tool.
@@ -108,6 +108,12 @@ def call_model(
108108

109109
for event in graph.stream(new_input, thread, stream_mode="values"):
110110
last_message = event['messages'][-1]
111+
for message in event['messages']:
112+
if isinstance(message, HumanMessage):
113+
source_list = []
114+
if isinstance(message, AIMessage) and message.tool_calls:
115+
for tool_call in message.tool_calls:
116+
source_list.append(tool_call['name'])
111117

112118
state_snapshot = graph.get_state(thread)
113119
actions = ''
@@ -117,5 +123,6 @@ def call_model(
117123
return {
118124
'output': last_message.content,
119125
'actions': actions,
120-
'conversation_token': export_conversation(checkpointer)
126+
'conversation_token': export_conversation(checkpointer),
127+
'sources': source_list,
121128
}

ex_app/lib/all_tools/external.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def get_coordinates_for_address(address: str) -> (str, str):
3636
def get_current_weather_for_coordinates(lat: str, lon: str) -> dict[str, typing.Any]:
3737
"""
3838
Retrieve the current weather for a given latitude and longitude
39-
When using this tool, you must let the user know that the internet service met.no was used.
4039
:param lat: Latitude
4140
:param lon: Longitude
4241
:return:

ex_app/lib/provider.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22
# SPDX-License-Identifier: AGPL-3.0-or-later
33
from nc_py_api.ex_app.providers.task_processing import TaskProcessingProvider, TaskType, ShapeDescriptor, ShapeType
44

5+
56
provider = TaskProcessingProvider(
67
id='context_agent:agent',
78
name='ContextAgent Provider',
89
task_type='core:contextagent:interaction',
910
expected_runtime=60,
11+
optional_output_shape= [
12+
ShapeDescriptor(
13+
name="sources",
14+
description="Used tools",
15+
shape_type=ShapeType.LIST_OF_TEXTS
16+
)
17+
]
1018
)

0 commit comments

Comments
 (0)