mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-07-11 12:27:13 +00:00
refactor(tools): extract document tools to handle registry (#3666)
* feat(tools): add document management tool handlers to the agent_tools module * feat(tools): extraced document tools for create, update, edit, suggest, and manage from tool_implementations.py * feat(tests): refactor document tool tests to use TOOL_HANDLERS and document_tools * refactor(tools): add document tool dispatcher and updated tool calling path * refactor(tools): remove duplicated document management functions * refactor(tools): removing unused functions and adding new import paths * refactor(tools): update document tool execute methods to use context dictionary * refactor(tests): update import paths for document tools in test files * refactor(tests): update owner parameter format in document management tests * refactor(tests): update import path for _owned_document_query * feat(tools): add document management tool handlers to the agent_tools module * feat(tools): extraced document tools for create, update, edit, suggest, and manage from tool_implementations.py * feat(tests): refactor document tool tests to use TOOL_HANDLERS and document_tools * refactor(tools): add document tool dispatcher and updated tool calling path * refactor(tools): remove duplicated document management functions * refactor(tools): removing unused functions and adding new import paths * refactor(tools): update document tool execute methods to use context dictionary * refactor(tests): update import paths for document tools in test files * refactor(tests): update owner parameter format in document management tests * refactor(tests): update import path for _owned_document_query * refactor: update import paths for document tools * fix(tests): correct source path for document ID test
This commit is contained in:
+23
-19
@@ -419,6 +419,20 @@ async def _direct_fallback(
|
||||
return None
|
||||
|
||||
|
||||
async def _document_tool_dispatch(
|
||||
tool: str,
|
||||
content: str,
|
||||
session_id: Optional[str] = None,
|
||||
owner: Optional[str] = None,
|
||||
) -> Optional[Dict]:
|
||||
"""Route a document tool through TOOL_HANDLERS with the right ctx shape."""
|
||||
from src.agent_tools import TOOL_HANDLERS
|
||||
ctx = {"session_id": session_id, "owner": owner}
|
||||
if tool in TOOL_HANDLERS:
|
||||
return await TOOL_HANDLERS[tool](content, ctx)
|
||||
return None
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Dispatcher
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -439,11 +453,10 @@ async def execute_tool_block(
|
||||
events while the command is in flight. Ignored by other tools.
|
||||
"""
|
||||
from src.tool_implementations import (
|
||||
do_create_document, do_update_document, do_edit_document,
|
||||
do_suggest_document, do_search_chats, do_manage_tasks,
|
||||
do_search_chats, do_manage_tasks,
|
||||
do_manage_skills, do_api_call, do_manage_endpoints,
|
||||
do_manage_mcp, do_manage_webhooks, do_manage_tokens,
|
||||
do_manage_documents, do_manage_settings, do_manage_notes,
|
||||
do_manage_settings, do_manage_notes,
|
||||
do_manage_calendar,
|
||||
do_download_model, do_serve_model, do_list_served_models, do_stop_served_model,
|
||||
do_tail_serve_output,
|
||||
@@ -637,19 +650,13 @@ async def execute_tool_block(
|
||||
desc = f"{tool}: {first_line}"
|
||||
result = await _direct_fallback(tool, content, progress_cb=progress_cb) \
|
||||
or {"error": f"{tool}: execution failed", "exit_code": 1}
|
||||
elif tool == "create_document":
|
||||
title = content.split("\n")[0].strip()[:60]
|
||||
desc = f"create_document: {title}"
|
||||
result = await do_create_document(content, session_id=session_id, owner=owner)
|
||||
elif tool == "update_document":
|
||||
desc = f"update_document: {content.split(chr(10))[0][:60]}"
|
||||
result = await do_update_document(content, owner=owner)
|
||||
elif tool == "edit_document":
|
||||
result = await do_edit_document(content, owner=owner)
|
||||
desc = f"edit_document: {result.get('title', '')}"
|
||||
elif tool == "suggest_document":
|
||||
result = await do_suggest_document(content, owner=owner)
|
||||
desc = f"suggest_document: {result.get('count', 0)} suggestions"
|
||||
elif tool in ("create_document", "update_document", "edit_document",
|
||||
"suggest_document", "manage_documents"):
|
||||
desc = f"{tool}: {content.split(chr(10))[0][:80]}"
|
||||
result = await _document_tool_dispatch(tool, content, session_id, owner) \
|
||||
or {"error": f"{tool}: execution failed", "exit_code": 1}
|
||||
if tool in ("edit_document", "suggest_document") and "title" in (result or {}):
|
||||
desc = f"{tool}: {result.get('title', '')}"
|
||||
elif tool == "search_chats":
|
||||
query = content.split("\n")[0].strip()
|
||||
desc = f"search_chats: {query[:80]}"
|
||||
@@ -682,9 +689,6 @@ async def execute_tool_block(
|
||||
elif tool == "manage_tokens":
|
||||
desc = "manage_tokens"
|
||||
result = await do_manage_tokens(content, owner=owner)
|
||||
elif tool == "manage_documents":
|
||||
desc = "manage_documents"
|
||||
result = await do_manage_documents(content, owner=owner)
|
||||
elif tool == "manage_settings":
|
||||
desc = "manage_settings"
|
||||
result = await do_manage_settings(content, owner=owner)
|
||||
|
||||
Reference in New Issue
Block a user