Skip to content

Commit 1ced045

Browse files
authored
Merge pull request #55 from nextcloud/add-mcp-client
feat: allow for specifying mcp clients and convert functions to async
2 parents b789065 + 8c09b4f commit 1ced045

24 files changed

+446
-78
lines changed

ex_app/lib/agent.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def export_conversation(checkpointer):
4444
return add_signature(checkpointer.serde.dumps(checkpointer.storage).decode('utf-8'), key)
4545

4646

47-
def react(task, nc: Nextcloud):
48-
safe_tools, dangerous_tools = get_tools(nc)
47+
async def react(task, nc: Nextcloud):
48+
safe_tools, dangerous_tools = await get_tools(nc)
4949

5050
model.bind_nextcloud(nc)
5151

@@ -54,7 +54,7 @@ def react(task, nc: Nextcloud):
5454
+ safe_tools
5555
)
5656

57-
def call_model(
57+
async def call_model(
5858
state: AgentState,
5959
config: RunnableConfig,
6060
):
@@ -77,12 +77,12 @@ def call_model(
7777
""".replace("{CURRENT_DATE}", current_date)
7878
)
7979

80-
response = bound_model.invoke([system_prompt] + state["messages"], config)
80+
response = await bound_model.ainvoke([system_prompt] + state["messages"], config)
8181
# We return a list, because this will get added to the existing list
8282
return {"messages": [response]}
8383

8484
checkpointer = MemorySaver()
85-
graph = get_graph(call_model, safe_tools, dangerous_tools, checkpointer)
85+
graph = await get_graph(call_model, safe_tools, dangerous_tools, checkpointer)
8686

8787
load_conversation(checkpointer, task['input']['conversation_token'])
8888

@@ -105,7 +105,7 @@ def call_model(
105105
else:
106106
new_input = {"messages": [("user", task['input']['input'])]}
107107

108-
for event in graph.stream(new_input, thread, stream_mode="values"):
108+
async for event in graph.astream(new_input, thread, stream_mode="values"):
109109
last_message = event['messages'][-1]
110110
for message in event['messages']:
111111
if isinstance(message, HumanMessage):

ex_app/lib/all_tools/audio2text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ex_app.lib.all_tools.lib.decorator import safe_tool
99

1010

11-
def get_tools(nc: Nextcloud):
11+
async def get_tools(nc: Nextcloud):
1212

1313
@tool
1414
@safe_tool

ex_app/lib/all_tools/calendar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from ex_app.lib.logger import log
1919

2020

21-
def get_tools(nc: Nextcloud):
21+
async def get_tools(nc: Nextcloud):
2222

2323
@tool
2424
@safe_tool

ex_app/lib/all_tools/contacts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ex_app.lib.all_tools.lib.decorator import safe_tool
1111

1212

13-
def get_tools(nc: Nextcloud):
13+
async def get_tools(nc: Nextcloud):
1414
@tool
1515
@safe_tool
1616
def find_person_in_contacts(name: str) -> list[dict[str, typing.Any]]:

ex_app/lib/all_tools/context_chat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ex_app.lib.all_tools.lib.decorator import safe_tool
88

99

10-
def get_tools(nc: Nextcloud):
10+
async def get_tools(nc: Nextcloud):
1111

1212
@tool
1313
@safe_tool

ex_app/lib/all_tools/deck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from ex_app.lib.logger import log
1717

1818

19-
def get_tools(nc: Nextcloud):
19+
async def get_tools(nc: Nextcloud):
2020

2121
@tool
2222
@safe_tool

ex_app/lib/all_tools/doc-gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ex_app.lib.all_tools.lib.decorator import safe_tool
88

99

10-
def get_tools(nc: Nextcloud):
10+
async def get_tools(nc: Nextcloud):
1111

1212
@tool
1313
@safe_tool

ex_app/lib/all_tools/duckduckgo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ex_app.lib.all_tools.lib.decorator import safe_tool
88

99

10-
def get_tools(nc: Nextcloud):
10+
async def get_tools(nc: Nextcloud):
1111

1212
web_search = DuckDuckGoSearchResults(output_format="list")
1313
return [

ex_app/lib/all_tools/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ex_app.lib.all_tools.lib.decorator import safe_tool, dangerous_tool
99

1010

11-
def get_tools(nc: Nextcloud):
11+
async def get_tools(nc: Nextcloud):
1212

1313
@tool
1414
@safe_tool

ex_app/lib/all_tools/here.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ex_app.lib.all_tools.lib.decorator import safe_tool
1212

1313

14-
def get_tools(nc: Nextcloud):
14+
async def get_tools(nc: Nextcloud):
1515

1616
@tool
1717
@safe_tool

0 commit comments

Comments
 (0)