elysium / backend /tools /dispatcher.py
pmrinal2005's picture
Upload folder using huggingface_hub
a521353 verified
Raw
History Blame
1.64 kB
"""Tool dispatcher. Maps tool_name → implementation. Offline-safe."""
from ..schema import ToolCall
from . import (duckduckgo_tool, email_tool, reminder_tool, calendar_tool,
file_tool, weather_tool, calculator_tool, fetch_url_tool,
transit_lookup_tool)
REGISTRY = {
"duckduckgo_search": duckduckgo_tool.run,
"web_search": duckduckgo_tool.run,
"send_email": email_tool.run,
"set_reminder": reminder_tool.run,
"calendar_lookup": calendar_tool.run,
"read_file": file_tool.read,
"write_file": file_tool.write,
"weather_lookup": weather_tool.run,
"run_calculator": calculator_tool.run,
"fetch_url": fetch_url_tool.run,
"transit_lookup": transit_lookup_tool.run,
"read_discord": lambda p: {"status": "offline", "note": "no_token"},
"read_telegram": lambda p: {"status": "offline", "note": "no_token"},
"create_notion_page": lambda p: file_tool.write(
{"path": f"notion_{p.get('title','page')}.md", "content": p.get("content","")}),
}
def execute_all(tool_calls):
results = []
for tc in tool_calls:
fn = REGISTRY.get(tc.tool_name)
try:
out = fn(tc.parameters) if fn else {"error": f"Unknown tool: {tc.tool_name}"}
except Exception as e:
out = {"error": str(e), "fallback": tc.offline_fallback}
results.append({"call_id": tc.call_id, "tool_name": tc.tool_name,
"calling_agent": tc.calling_agent, "result": out})
return results