Spaces:
Running
Running
Commit ·
c92b763
1
Parent(s): 8688b66
Remove utils_tools and disable private_hf_repo_tool
Browse files- Delete utils_tools.py (datetime now provided in system prompt)
- Comment out private_hf_repo_tool registration (system prompt now
reliably instructs agent to push outputs to hub)
- agent/core/tools.py +10 -17
- agent/tools/utils_tools.py +0 -203
agent/core/tools.py
CHANGED
|
@@ -37,13 +37,12 @@ from agent.tools.github_read_file import (
|
|
| 37 |
)
|
| 38 |
from agent.tools.jobs_tool import HF_JOBS_TOOL_SPEC, hf_jobs_handler
|
| 39 |
from agent.tools.plan_tool import PLAN_TOOL_SPEC, plan_tool_handler
|
| 40 |
-
from agent.tools.private_hf_repo_tools import (
|
| 41 |
-
PRIVATE_HF_REPO_TOOL_SPEC,
|
| 42 |
-
private_hf_repo_handler,
|
| 43 |
-
)
|
| 44 |
|
| 45 |
-
# NOTE:
|
| 46 |
-
# from agent.tools.
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Suppress aiohttp deprecation warning
|
| 49 |
warnings.filterwarnings(
|
|
@@ -281,18 +280,12 @@ def create_builtin_tools() -> list[ToolSpec]:
|
|
| 281 |
parameters=HF_JOBS_TOOL_SPEC["parameters"],
|
| 282 |
handler=hf_jobs_handler,
|
| 283 |
),
|
| 284 |
-
|
| 285 |
-
name=PRIVATE_HF_REPO_TOOL_SPEC["name"],
|
| 286 |
-
description=PRIVATE_HF_REPO_TOOL_SPEC["description"],
|
| 287 |
-
parameters=PRIVATE_HF_REPO_TOOL_SPEC["parameters"],
|
| 288 |
-
handler=private_hf_repo_handler,
|
| 289 |
-
),
|
| 290 |
-
# NOTE: Utils tool disabled - date/time now loaded into system prompt at initialization (less tool calls=more reliablity)
|
| 291 |
# ToolSpec(
|
| 292 |
-
# name=
|
| 293 |
-
# description=
|
| 294 |
-
# parameters=
|
| 295 |
-
# handler=
|
| 296 |
# ),
|
| 297 |
# GitHub tools
|
| 298 |
# NOTE: Github search code tool disabled - a bit buggy
|
|
|
|
| 37 |
)
|
| 38 |
from agent.tools.jobs_tool import HF_JOBS_TOOL_SPEC, hf_jobs_handler
|
| 39 |
from agent.tools.plan_tool import PLAN_TOOL_SPEC, plan_tool_handler
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
# NOTE: Private HF repo tool disabled - system prompt handles pushing to hub pretty well now
|
| 42 |
+
# from agent.tools.private_hf_repo_tools import (
|
| 43 |
+
# PRIVATE_HF_REPO_TOOL_SPEC,
|
| 44 |
+
# private_hf_repo_handler,
|
| 45 |
+
# )
|
| 46 |
|
| 47 |
# Suppress aiohttp deprecation warning
|
| 48 |
warnings.filterwarnings(
|
|
|
|
| 280 |
parameters=HF_JOBS_TOOL_SPEC["parameters"],
|
| 281 |
handler=hf_jobs_handler,
|
| 282 |
),
|
| 283 |
+
# NOTE: Private HF repo tool disabled - system prompt now reliably instructs agent to push to hub
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
# ToolSpec(
|
| 285 |
+
# name=PRIVATE_HF_REPO_TOOL_SPEC["name"],
|
| 286 |
+
# description=PRIVATE_HF_REPO_TOOL_SPEC["description"],
|
| 287 |
+
# parameters=PRIVATE_HF_REPO_TOOL_SPEC["parameters"],
|
| 288 |
+
# handler=private_hf_repo_handler,
|
| 289 |
# ),
|
| 290 |
# GitHub tools
|
| 291 |
# NOTE: Github search code tool disabled - a bit buggy
|
agent/tools/utils_tools.py
DELETED
|
@@ -1,203 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Utils Tools - General utility operations
|
| 3 |
-
|
| 4 |
-
Provides system information like current date/time with timezone support.
|
| 5 |
-
"""
|
| 6 |
-
|
| 7 |
-
import zoneinfo
|
| 8 |
-
from datetime import datetime
|
| 9 |
-
from typing import Any, Dict, Literal
|
| 10 |
-
|
| 11 |
-
from agent.tools.types import ToolResult
|
| 12 |
-
|
| 13 |
-
# Operation names
|
| 14 |
-
OperationType = Literal["get_datetime"]
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
class UtilsTool:
|
| 18 |
-
"""Tool for general utility operations."""
|
| 19 |
-
|
| 20 |
-
async def execute(self, params: Dict[str, Any]) -> ToolResult:
|
| 21 |
-
"""Execute the specified utility operation."""
|
| 22 |
-
operation = params.get("operation")
|
| 23 |
-
args = params.get("args", {})
|
| 24 |
-
|
| 25 |
-
# If no operation provided, return usage instructions
|
| 26 |
-
if not operation:
|
| 27 |
-
return self._show_help()
|
| 28 |
-
|
| 29 |
-
# Normalize operation name
|
| 30 |
-
operation = operation.lower()
|
| 31 |
-
|
| 32 |
-
# Check if help is requested
|
| 33 |
-
if args.get("help"):
|
| 34 |
-
return self._show_operation_help(operation)
|
| 35 |
-
|
| 36 |
-
try:
|
| 37 |
-
# Route to appropriate handler
|
| 38 |
-
if operation == "get_datetime":
|
| 39 |
-
return await self._get_datetime(args)
|
| 40 |
-
else:
|
| 41 |
-
return {
|
| 42 |
-
"formatted": f'Unknown operation: "{operation}"\n\n'
|
| 43 |
-
"Available operations: get_datetime\n\n"
|
| 44 |
-
"Call this tool with no operation for full usage instructions.",
|
| 45 |
-
"totalResults": 0,
|
| 46 |
-
"resultsShared": 0,
|
| 47 |
-
"isError": True,
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
except Exception as e:
|
| 51 |
-
return {
|
| 52 |
-
"formatted": f"Error executing {operation}: {str(e)}",
|
| 53 |
-
"totalResults": 0,
|
| 54 |
-
"resultsShared": 0,
|
| 55 |
-
"isError": True,
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
def _show_help(self) -> ToolResult:
|
| 59 |
-
"""Show usage instructions when tool is called with no arguments."""
|
| 60 |
-
usage_text = """# Utils Tool
|
| 61 |
-
|
| 62 |
-
Utility operations for system information.
|
| 63 |
-
|
| 64 |
-
## Available Commands
|
| 65 |
-
|
| 66 |
-
- **get_datetime** - Get current date and time with timezone support
|
| 67 |
-
|
| 68 |
-
## Examples
|
| 69 |
-
|
| 70 |
-
### Get current date and time (Paris timezone by default)
|
| 71 |
-
Call this tool with:
|
| 72 |
-
```json
|
| 73 |
-
{
|
| 74 |
-
"operation": "get_datetime",
|
| 75 |
-
"args": {}
|
| 76 |
-
}
|
| 77 |
-
```
|
| 78 |
-
|
| 79 |
-
### Get current date and time in a specific timezone
|
| 80 |
-
Call this tool with:
|
| 81 |
-
```json
|
| 82 |
-
{
|
| 83 |
-
"operation": "get_datetime",
|
| 84 |
-
"args": {
|
| 85 |
-
"timezone": "America/New_York"
|
| 86 |
-
}
|
| 87 |
-
}
|
| 88 |
-
```
|
| 89 |
-
|
| 90 |
-
Common timezones: Europe/Paris, America/New_York, America/Los_Angeles, Asia/Tokyo, UTC
|
| 91 |
-
|
| 92 |
-
## Tips
|
| 93 |
-
|
| 94 |
-
- **Default timezone**: Paris (Europe/Paris)
|
| 95 |
-
- **Date format**: dd-mm-yyyy
|
| 96 |
-
- **Time format**: HH:MM:SS.mmm (24-hour format with milliseconds)
|
| 97 |
-
- **Timezone names**: Use IANA timezone database names (e.g., "Europe/Paris", "UTC")
|
| 98 |
-
"""
|
| 99 |
-
return {"formatted": usage_text, "totalResults": 1, "resultsShared": 1}
|
| 100 |
-
|
| 101 |
-
def _show_operation_help(self, operation: str) -> ToolResult:
|
| 102 |
-
"""Show help for a specific operation."""
|
| 103 |
-
help_text = f"Help for operation: {operation}\n\nCall with appropriate arguments. Use the main help for examples."
|
| 104 |
-
return {"formatted": help_text, "totalResults": 1, "resultsShared": 1}
|
| 105 |
-
|
| 106 |
-
async def _get_datetime(self, args: Dict[str, Any]) -> ToolResult:
|
| 107 |
-
"""Get current date and time with timezone support."""
|
| 108 |
-
timezone_name = args.get("timezone", "Europe/Paris")
|
| 109 |
-
|
| 110 |
-
try:
|
| 111 |
-
# Get timezone object
|
| 112 |
-
tz = zoneinfo.ZoneInfo(timezone_name)
|
| 113 |
-
|
| 114 |
-
# Get current datetime in specified timezone
|
| 115 |
-
now = datetime.now(tz)
|
| 116 |
-
|
| 117 |
-
# Format date as dd-mm-yyyy
|
| 118 |
-
date_str = now.strftime("%d-%m-%Y")
|
| 119 |
-
|
| 120 |
-
# Format time as HH:MM:SS.mmm
|
| 121 |
-
time_str = now.strftime("%H:%M:%S.%f")[
|
| 122 |
-
:-3
|
| 123 |
-
] # Remove last 3 digits to keep only milliseconds
|
| 124 |
-
|
| 125 |
-
# Get timezone abbreviation/offset
|
| 126 |
-
tz_offset = now.strftime("%z")
|
| 127 |
-
tz_name = now.strftime("%Z")
|
| 128 |
-
|
| 129 |
-
response = f"""✓ Current date and time
|
| 130 |
-
|
| 131 |
-
**Date:** {date_str}
|
| 132 |
-
**Time:** {time_str}
|
| 133 |
-
**Timezone:** {timezone_name} ({tz_name}, UTC{tz_offset[:3]}:{tz_offset[3:]})
|
| 134 |
-
|
| 135 |
-
**ISO Format:** {now.isoformat()}
|
| 136 |
-
**Unix Timestamp:** {int(now.timestamp())}"""
|
| 137 |
-
|
| 138 |
-
return {"formatted": response, "totalResults": 1, "resultsShared": 1}
|
| 139 |
-
|
| 140 |
-
except zoneinfo.ZoneInfoNotFoundError:
|
| 141 |
-
return {
|
| 142 |
-
"formatted": f"Invalid timezone: {timezone_name}\n\n"
|
| 143 |
-
"Use IANA timezone database names like:\n"
|
| 144 |
-
"- Europe/Paris\n"
|
| 145 |
-
"- America/New_York\n"
|
| 146 |
-
"- Asia/Tokyo\n"
|
| 147 |
-
"- UTC\n\n"
|
| 148 |
-
"See: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones",
|
| 149 |
-
"totalResults": 0,
|
| 150 |
-
"resultsShared": 0,
|
| 151 |
-
"isError": True,
|
| 152 |
-
}
|
| 153 |
-
except Exception as e:
|
| 154 |
-
return {
|
| 155 |
-
"formatted": f"Failed to get date/time: {str(e)}",
|
| 156 |
-
"totalResults": 0,
|
| 157 |
-
"resultsShared": 0,
|
| 158 |
-
"isError": True,
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
# Tool specification for agent registration
|
| 163 |
-
UTILS_TOOL_SPEC = {
|
| 164 |
-
"name": "utils",
|
| 165 |
-
"description": (
|
| 166 |
-
"System utility operations - currently provides date/time with timezone support. "
|
| 167 |
-
"**Use when:** (1) Need current date for logging/timestamps, (2) User asks 'what time is it', "
|
| 168 |
-
"(3) Need timezone-aware datetime for scheduling/coordination, (4) Creating timestamped filenames. "
|
| 169 |
-
"**Operation:** get_datetime with optional timezone parameter (default: Europe/Paris). "
|
| 170 |
-
"Returns: Date (dd-mm-yyyy), time (HH:MM:SS.mmm), timezone info, ISO format, Unix timestamp. "
|
| 171 |
-
"**Pattern:** utils get_datetime → use timestamp in filename/log → upload to hf_private_repos. "
|
| 172 |
-
"Supports IANA timezone names: 'Europe/Paris', 'America/New_York', 'Asia/Tokyo', 'UTC'."
|
| 173 |
-
),
|
| 174 |
-
"parameters": {
|
| 175 |
-
"type": "object",
|
| 176 |
-
"properties": {
|
| 177 |
-
"operation": {
|
| 178 |
-
"type": "string",
|
| 179 |
-
"enum": ["get_datetime"],
|
| 180 |
-
"description": "Operation to execute. Valid values: [get_datetime]",
|
| 181 |
-
},
|
| 182 |
-
"args": {
|
| 183 |
-
"type": "object",
|
| 184 |
-
"description": (
|
| 185 |
-
"Operation-specific arguments as a JSON object. "
|
| 186 |
-
"For get_datetime: timezone (string, optional, default: Europe/Paris). "
|
| 187 |
-
"Use IANA timezone names like 'America/New_York', 'Asia/Tokyo', 'UTC'."
|
| 188 |
-
),
|
| 189 |
-
"additionalProperties": True,
|
| 190 |
-
},
|
| 191 |
-
},
|
| 192 |
-
},
|
| 193 |
-
}
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
async def utils_handler(arguments: Dict[str, Any]) -> tuple[str, bool]:
|
| 197 |
-
"""Handler for agent tool router."""
|
| 198 |
-
try:
|
| 199 |
-
tool = UtilsTool()
|
| 200 |
-
result = await tool.execute(arguments)
|
| 201 |
-
return result["formatted"], not result.get("isError", False)
|
| 202 |
-
except Exception as e:
|
| 203 |
-
return f"Error executing Utils tool: {str(e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