mirror of
https://github.com/R0m1k3/Loki.git
synced 2026-10-21 05:58:13 +02:00
feat(mcp): outils MCP dans la boucle agent (dispatch async + notices)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
e09af9c9bb
commit
91e0a9f0b2
2 files changed
+34
-2
No files matched your search
+25
-1
@@ -81,15 +81,20 @@ async def run_agent(
|
||||
confirm_shell: bool = True,
|
||||
think: bool = True,
|
||||
keep_alive: str | None = None,
|
||||
mcp_tools: list[dict] | None = None,
|
||||
) -> AsyncIterator[dict]:
|
||||
# enabled_tools=None -> tous les outils ; liste vide -> aucun outil.
|
||||
if enabled_tools is None:
|
||||
tools = TOOL_DEFINITIONS
|
||||
tools = list(TOOL_DEFINITIONS)
|
||||
elif enabled_tools:
|
||||
tools = [
|
||||
t for t in TOOL_DEFINITIONS if t["function"]["name"] in enabled_tools
|
||||
]
|
||||
else:
|
||||
tools = []
|
||||
# Outils MCP des serveurs activés (déjà résolus par l'appelant).
|
||||
tools.extend(mcp_tools or [])
|
||||
if not tools:
|
||||
tools = None
|
||||
collected: list[dict] = []
|
||||
text_parts: list[str] = []
|
||||
@@ -289,6 +294,25 @@ async def run_agent(
|
||||
})
|
||||
continue
|
||||
|
||||
# Outils MCP : dispatch asynchrone vers le serveur concerné.
|
||||
if name.startswith("mcp_"):
|
||||
from .mcp_client import manager as mcp_manager
|
||||
mcp_res = await mcp_manager.call_tool(name, args)
|
||||
status = "ok" if mcp_res["ok"] else "error"
|
||||
record = {"name": name, "args": args,
|
||||
"summary": mcp_res["summary"], "status": status}
|
||||
collected.append(record)
|
||||
yield {"type": "tool_result", **record}
|
||||
convo.append({
|
||||
"role": "tool",
|
||||
"tool_name": name,
|
||||
"content": json.dumps(
|
||||
{"ok": mcp_res["ok"], "content": mcp_res["content"]},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
})
|
||||
continue
|
||||
|
||||
try:
|
||||
result = run_tool(name, args)
|
||||
summary = result.get("summary", "terminé")
|
||||
|
||||
Reference in new issue
Block a user