File size: 11,414 Bytes
81ff144 9cc23a0 81ff144 9cc23a0 81ff144 9cc23a0 81ff144 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | from .file_generator import FileGeneratorTool
from .decomposer import DecompositionTool
from .sre import SRETool
from .browser import BrowserTool
from .sandbox import CodeSandboxTool
from .visuals import VisualsTool
from typing import Any, Dict, List
class ToolRegistry:
def __init__(self):
self.browser = BrowserTool()
self.sandbox = CodeSandboxTool()
self.file_gen = FileGeneratorTool()
self.decomposer = DecompositionTool()
self.sre = SRETool()
self.visuals = VisualsTool()
self.tools = {
"web_search": {
"func": self.browser.web_search,
"description": "Searches the public web using Tavily and returns summarized results with source URLs."
},
"extract_url": {
"func": self.browser.search_and_extract,
"description": "Extracts text content from a specific URL."
},
"execute_python": {
"func": self.sandbox.execute_python,
"description": "Executes Python code and returns the output."
},
"generate_pdf": {
"func": self.file_gen.generate_pdf,
"description": "Generates a PDF document."
},
"generate_excel": {
"func": self.file_gen.generate_excel,
"description": "Generates an Excel spreadsheet from structured data."
},
"create_subtasks": {
"func": self.decomposer.create_subtasks,
"description": "Breaks down a goal into a list of actionable tasks."
},
"generate_chart": {
"func": self.visuals.generate_chart,
"description": "Generates a chart image (bar, line, pie) from a JSON config."
},
"generate_illustration": {
"func": self.visuals.generate_illustration,
"description": "Generates an AI illustration or drawing based on a text prompt."
},
"get_system_health": {
"func": self.sre.get_system_health,
"description": "Returns system health metrics (CPU, Memory, Disk)."
},
"check_service_status": {
"func": self.sre.check_service_status,
"description": "Checks if a specific service or process is running."
},
"run_patch_command": {
"func": self.sre.run_patch_command,
"description": "Executes a safe system patch command (e.g., git pull, npm install)."
}
}
def get_tool_definitions(self) -> List[Dict[str, Any]]:
"""
Returns OpenAI-style tool definitions.
"""
return [
{
"type": "function",
"function": {
"name": "web_search",
"description": "Search the public web for information using Tavily. Use this when the task requires current external information.",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string", "description": "The search query"},
"topic": {
"type": "string",
"enum": ["general", "news", "finance"],
"description": "The search category. Use news for recent events and finance for market/company financial queries."
},
"max_results": {
"type": "integer",
"description": "Maximum number of results to return. Keep this small to control context size.",
"default": 5
}
},
"required": ["query"]
}
}
},
{
"type": "function",
"function": {
"name": "extract_url",
"description": "Extract text content from a URL",
"parameters": {
"type": "object",
"properties": {
"url": {"type": "string", "description": "The URL to extract from"}
},
"required": ["url"]
}
}
},
{
"type": "function",
"function": {
"name": "execute_python",
"description": "Execute Python code to perform calculations, data analysis, or logic verification.",
"parameters": {
"type": "object",
"properties": {
"code": {"type": "string", "description": "The Python code to execute"}
},
"required": ["code"]
}
}
},
{
"type": "function",
"function": {
"name": "generate_pdf",
"description": "Create a professional PDF report",
"parameters": {
"type": "object",
"properties": {
"title": {"type": "string", "description": "The title of the report"},
"content": {"type": "string", "description": "The text content of the report"}
},
"required": ["title", "content"]
}
}
},
{
"type": "function",
"function": {
"name": "generate_excel",
"description": "Create an Excel spreadsheet from data",
"parameters": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {"type": "object"},
"description": "List of rows as objects"
}
},
"required": ["data"]
}
}
},
{
"type": "function",
"function": {
"name": "create_subtasks",
"description": "Break down a complex goal into smaller, actionable tasks for other agents.",
"parameters": {
"type": "object",
"properties": {
"project_id": {"type": "string", "description": "The current project UUID"},
"tasks": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {"type": "string", "description": "Clear title of the subtask"},
"description": {"type": "string", "description": "Detailed instructions for the next agent"},
"assigned_agent_id": {"type": "string", "description": "The UUID of the agent to handle this task"}
},
"required": ["title", "description", "assigned_agent_id"]
}
}
},
"required": ["project_id", "tasks"]
}
}
},
{
"type": "function",
"function": {
"name": "generate_chart",
"description": "Generate a visual chart image (bar, line, pie, etc.) using QuickChart.io.",
"parameters": {
"type": "object",
"properties": {
"chart_type": {"type": "string", "enum": ["bar", "line", "pie", "doughnut"], "description": "Type of chart"},
"chart_config": {"type": "string", "description": "The JSON configuration for QuickChart (e.g., {type: 'bar', data: {...}})"}
},
"required": ["chart_type", "chart_config"]
}
}
},
{
"type": "function",
"function": {
"name": "generate_illustration",
"description": "Generate an AI illustration or drawing based on a prompt using Pollinations.ai.",
"parameters": {
"type": "object",
"properties": {
"prompt": {"type": "string", "description": "Detailed description of the illustration to generate"}
},
"required": ["prompt"]
}
}
},
{
"type": "function",
"function": {
"name": "get_system_health",
"description": "Monitor server vital signs like CPU usage, memory availability, and disk space.",
"parameters": {
"type": "object",
"properties": {}
}
}
},
{
"type": "function",
"function": {
"name": "check_service_status",
"description": "Verify if a critical service or process is currently active on the host.",
"parameters": {
"type": "object",
"properties": {
"service_name": {"type": "string", "description": "The name of the process or service to check"}
},
"required": ["service_name"]
}
}
},
{
"type": "function",
"function": {
"name": "run_patch_command",
"description": "Apply a system patch or update. Limited to safe commands like 'git pull' or 'npm install'.",
"parameters": {
"type": "object",
"properties": {
"command": {"type": "string", "description": "The restricted command to execute"}
},
"required": ["command"]
}
}
}
]
async def call_tool(self, name: str, arguments: Dict[str, Any]) -> Any:
"""
Executes a tool by name with provided arguments.
"""
if name not in self.tools:
raise ValueError(f"Tool {name} not found")
func = self.tools[name]["func"]
return await func(**arguments)
tool_registry = ToolRegistry()
|