Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Commit ·
706d95d
1
Parent(s): 6513064
formatting + typo fix
Browse files- agent/core/tools.py +4 -4
- agent/main.py +2 -4
- agent/tools/plan_tool.py +10 -10
- agent/tools/search_docs_tool.py +3 -1
- agent/utils/terminal_display.py +13 -6
agent/core/tools.py
CHANGED
|
@@ -14,8 +14,8 @@ from mcp.types import EmbeddedResource, ImageContent, TextContent
|
|
| 14 |
|
| 15 |
from agent.config import MCPServerConfig
|
| 16 |
from agent.tools.jobs_tool import HF_JOBS_TOOL_SPEC, hf_jobs_handler
|
| 17 |
-
from agent.tools.search_docs_tool import SEARCH_DOCS_TOOL_SPEC, search_docs_handler
|
| 18 |
from agent.tools.plan_tool import PLAN_TOOL_SPEC, plan_tool_handler
|
|
|
|
| 19 |
|
| 20 |
# Suppress aiohttp deprecation warning
|
| 21 |
warnings.filterwarnings(
|
|
@@ -204,10 +204,10 @@ def create_builtin_tools() -> list[ToolSpec]:
|
|
| 204 |
parameters=SEARCH_DOCS_TOOL_SPEC["parameters"],
|
| 205 |
handler=search_docs_handler,
|
| 206 |
),
|
| 207 |
-
|
| 208 |
-
|
| 209 |
description=PLAN_TOOL_SPEC["description"],
|
| 210 |
parameters=PLAN_TOOL_SPEC["parameters"],
|
| 211 |
handler=plan_tool_handler,
|
| 212 |
-
)
|
| 213 |
]
|
|
|
|
| 14 |
|
| 15 |
from agent.config import MCPServerConfig
|
| 16 |
from agent.tools.jobs_tool import HF_JOBS_TOOL_SPEC, hf_jobs_handler
|
|
|
|
| 17 |
from agent.tools.plan_tool import PLAN_TOOL_SPEC, plan_tool_handler
|
| 18 |
+
from agent.tools.search_docs_tool import SEARCH_DOCS_TOOL_SPEC, search_docs_handler
|
| 19 |
|
| 20 |
# Suppress aiohttp deprecation warning
|
| 21 |
warnings.filterwarnings(
|
|
|
|
| 204 |
parameters=SEARCH_DOCS_TOOL_SPEC["parameters"],
|
| 205 |
handler=search_docs_handler,
|
| 206 |
),
|
| 207 |
+
ToolSpec(
|
| 208 |
+
name=PLAN_TOOL_SPEC["name"],
|
| 209 |
description=PLAN_TOOL_SPEC["description"],
|
| 210 |
parameters=PLAN_TOOL_SPEC["parameters"],
|
| 211 |
handler=plan_tool_handler,
|
| 212 |
+
),
|
| 213 |
]
|
agent/main.py
CHANGED
|
@@ -71,7 +71,7 @@ async def event_listener(
|
|
| 71 |
|
| 72 |
# Display event
|
| 73 |
if event.event_type == "ready":
|
| 74 |
-
print(format_success("\
|
| 75 |
ready_event.set()
|
| 76 |
elif event.event_type == "assistant_message":
|
| 77 |
content = event.data.get("content", "") if event.data else ""
|
|
@@ -194,8 +194,7 @@ async def main():
|
|
| 194 |
from agent.utils.terminal_display import Colors
|
| 195 |
|
| 196 |
# Clear screen
|
| 197 |
-
os.system(
|
| 198 |
-
|
| 199 |
|
| 200 |
banner = r"""
|
| 201 |
_ _ _ _____ _ _
|
|
@@ -206,7 +205,6 @@ async def main():
|
|
| 206 |
|___/ |___/ |___/ |___/
|
| 207 |
"""
|
| 208 |
|
| 209 |
-
|
| 210 |
print(format_separator())
|
| 211 |
print(f"{Colors.YELLOW} {banner}{Colors.RESET}")
|
| 212 |
print("Type your messages below. Type 'exit', 'quit', or '/quit' to end.\n")
|
|
|
|
| 71 |
|
| 72 |
# Display event
|
| 73 |
if event.event_type == "ready":
|
| 74 |
+
print(format_success("\U0001f917 Agent ready"))
|
| 75 |
ready_event.set()
|
| 76 |
elif event.event_type == "assistant_message":
|
| 77 |
content = event.data.get("content", "") if event.data else ""
|
|
|
|
| 194 |
from agent.utils.terminal_display import Colors
|
| 195 |
|
| 196 |
# Clear screen
|
| 197 |
+
os.system("clear" if os.name != "nt" else "cls")
|
|
|
|
| 198 |
|
| 199 |
banner = r"""
|
| 200 |
_ _ _ _____ _ _
|
|
|
|
| 205 |
|___/ |___/ |___/ |___/
|
| 206 |
"""
|
| 207 |
|
|
|
|
| 208 |
print(format_separator())
|
| 209 |
print(f"{Colors.YELLOW} {banner}{Colors.RESET}")
|
| 210 |
print("Type your messages below. Type 'exit', 'quit', or '/quit' to end.\n")
|
agent/tools/plan_tool.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
-
import json
|
| 2 |
from typing import Any, Dict, List
|
| 3 |
-
|
| 4 |
from agent.utils.terminal_display import format_plan_tool_output
|
| 5 |
|
|
|
|
| 6 |
|
| 7 |
# In-memory storage for the current plan (raw structure from agent)
|
| 8 |
_current_plan: List[Dict[str, str]] = []
|
|
@@ -86,24 +86,24 @@ PLAN_TOOL_SPEC = {
|
|
| 86 |
"properties": {
|
| 87 |
"id": {
|
| 88 |
"type": "string",
|
| 89 |
-
"description": "Unique identifier for the todo"
|
| 90 |
},
|
| 91 |
"content": {
|
| 92 |
"type": "string",
|
| 93 |
-
"description": "Description of the todo task"
|
| 94 |
},
|
| 95 |
"status": {
|
| 96 |
"type": "string",
|
| 97 |
"enum": ["pending", "in_progress", "completed"],
|
| 98 |
-
"description": "Current status of the todo"
|
| 99 |
-
}
|
| 100 |
},
|
| 101 |
-
"required": ["id", "content", "status"]
|
| 102 |
-
}
|
| 103 |
}
|
| 104 |
},
|
| 105 |
-
"required": ["todos"]
|
| 106 |
-
}
|
| 107 |
}
|
| 108 |
|
| 109 |
|
|
|
|
|
|
|
| 1 |
from typing import Any, Dict, List
|
| 2 |
+
|
| 3 |
from agent.utils.terminal_display import format_plan_tool_output
|
| 4 |
|
| 5 |
+
from .types import ToolResult
|
| 6 |
|
| 7 |
# In-memory storage for the current plan (raw structure from agent)
|
| 8 |
_current_plan: List[Dict[str, str]] = []
|
|
|
|
| 86 |
"properties": {
|
| 87 |
"id": {
|
| 88 |
"type": "string",
|
| 89 |
+
"description": "Unique identifier for the todo",
|
| 90 |
},
|
| 91 |
"content": {
|
| 92 |
"type": "string",
|
| 93 |
+
"description": "Description of the todo task",
|
| 94 |
},
|
| 95 |
"status": {
|
| 96 |
"type": "string",
|
| 97 |
"enum": ["pending", "in_progress", "completed"],
|
| 98 |
+
"description": "Current status of the todo",
|
| 99 |
+
},
|
| 100 |
},
|
| 101 |
+
"required": ["id", "content", "status"],
|
| 102 |
+
},
|
| 103 |
}
|
| 104 |
},
|
| 105 |
+
"required": ["todos"],
|
| 106 |
+
},
|
| 107 |
}
|
| 108 |
|
| 109 |
|
agent/tools/search_docs_tool.py
CHANGED
|
@@ -113,7 +113,9 @@ async def search_docs_handler(arguments: dict[str, Any]) -> tuple[str, bool]:
|
|
| 113 |
|
| 114 |
# Load the search agent's own config file with GitHub MCP server
|
| 115 |
search_agent_config_path = (
|
| 116 |
-
Path(__file__).parent.parent.parent
|
|
|
|
|
|
|
| 117 |
)
|
| 118 |
search_agent_config = load_config(search_agent_config_path)
|
| 119 |
|
|
|
|
| 113 |
|
| 114 |
# Load the search agent's own config file with GitHub MCP server
|
| 115 |
search_agent_config_path = (
|
| 116 |
+
Path(__file__).parent.parent.parent
|
| 117 |
+
/ "configs"
|
| 118 |
+
/ "_subagent_config_search_agent.json"
|
| 119 |
)
|
| 120 |
search_agent_config = load_config(search_agent_config_path)
|
| 121 |
|
agent/utils/terminal_display.py
CHANGED
|
@@ -18,10 +18,13 @@ class Colors:
|
|
| 18 |
|
| 19 |
def truncate_to_lines(text: str, max_lines: int = 6) -> str:
|
| 20 |
"""Truncate text to max_lines, adding '...' if truncated"""
|
| 21 |
-
lines = text.split(
|
| 22 |
if len(lines) <= max_lines:
|
| 23 |
return text
|
| 24 |
-
return
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
def format_header(text: str, emoji: str = "") -> str:
|
|
@@ -65,10 +68,12 @@ def format_plan_display() -> str:
|
|
| 65 |
lines.append(f" [ ] {todo['id']}. {todo['content']}")
|
| 66 |
lines.append("")
|
| 67 |
|
| 68 |
-
lines.append(
|
|
|
|
|
|
|
| 69 |
lines.append("=" * 60 + "\n")
|
| 70 |
|
| 71 |
-
return
|
| 72 |
|
| 73 |
|
| 74 |
def format_error(message: str) -> str:
|
|
@@ -100,7 +105,7 @@ def format_tool_output(output: str, success: bool, truncate: bool = True) -> str
|
|
| 100 |
|
| 101 |
def format_turn_complete() -> str:
|
| 102 |
"""Format turn complete message in green with hugging face emoji"""
|
| 103 |
-
return f"{Colors.GREEN}{Colors.BOLD}\
|
| 104 |
|
| 105 |
|
| 106 |
def format_separator(char: str = "=", length: int = 60) -> str:
|
|
@@ -138,6 +143,8 @@ def format_plan_tool_output(todos: list) -> str:
|
|
| 138 |
lines.append(f" [ ] {todo['id']}. {todo['content']}")
|
| 139 |
lines.append("")
|
| 140 |
|
| 141 |
-
lines.append(
|
|
|
|
|
|
|
| 142 |
|
| 143 |
return "\n".join(lines)
|
|
|
|
| 18 |
|
| 19 |
def truncate_to_lines(text: str, max_lines: int = 6) -> str:
|
| 20 |
"""Truncate text to max_lines, adding '...' if truncated"""
|
| 21 |
+
lines = text.split("\n")
|
| 22 |
if len(lines) <= max_lines:
|
| 23 |
return text
|
| 24 |
+
return (
|
| 25 |
+
"\n".join(lines[:max_lines])
|
| 26 |
+
+ f"\n{Colors.CYAN}... ({len(lines) - max_lines} more lines){Colors.RESET}"
|
| 27 |
+
)
|
| 28 |
|
| 29 |
|
| 30 |
def format_header(text: str, emoji: str = "") -> str:
|
|
|
|
| 68 |
lines.append(f" [ ] {todo['id']}. {todo['content']}")
|
| 69 |
lines.append("")
|
| 70 |
|
| 71 |
+
lines.append(
|
| 72 |
+
f"Total: {len(plan)} todos ({len(completed)} completed, {len(in_progress)} in progress, {len(pending)} pending)"
|
| 73 |
+
)
|
| 74 |
lines.append("=" * 60 + "\n")
|
| 75 |
|
| 76 |
+
return "\n".join(lines)
|
| 77 |
|
| 78 |
|
| 79 |
def format_error(message: str) -> str:
|
|
|
|
| 105 |
|
| 106 |
def format_turn_complete() -> str:
|
| 107 |
"""Format turn complete message in green with hugging face emoji"""
|
| 108 |
+
return f"{Colors.GREEN}{Colors.BOLD}\U0001f917 Turn complete{Colors.RESET}\n"
|
| 109 |
|
| 110 |
|
| 111 |
def format_separator(char: str = "=", length: int = 60) -> str:
|
|
|
|
| 143 |
lines.append(f" [ ] {todo['id']}. {todo['content']}")
|
| 144 |
lines.append("")
|
| 145 |
|
| 146 |
+
lines.append(
|
| 147 |
+
f"Total: {len(todos)} todos ({len(completed)} completed, {len(in_progress)} in progress, {len(pending)} pending)"
|
| 148 |
+
)
|
| 149 |
|
| 150 |
return "\n".join(lines)
|