Implement the core autonomy layer — AgentLoop streams LLM responses, parses tool calls, executes them with permission checks, feeds results back, and repeats until the task completes or finish is called. - Add FinishTool for explicit loop termination - Add tools parameter to LLMClient.stream_chat() for function calling - Add compact tool result display (status line, not full output) - Refactor REPL to delegate to AgentLoop.run_turn() - Fix Ollama null content rejection (always send content as string) - Add finish to auto_approve permissions - 9 unit tests for agent loop (34 total, zero regressions) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
"""Tool registration and schema export."""
|
|
|
|
import logging
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from app.models.config import AppConfig
|
|
from app.tools.base import BaseTool
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ToolRegistry:
|
|
"""Registry of available tools, keyed by name."""
|
|
|
|
def __init__(self) -> None:
|
|
self._tools: dict[str, BaseTool] = {}
|
|
|
|
def register(self, tool: BaseTool) -> None:
|
|
"""Register a tool instance. Raises ValueError on duplicate name."""
|
|
if tool.name in self._tools:
|
|
raise ValueError(f"Duplicate tool name: '{tool.name}'")
|
|
self._tools[tool.name] = tool
|
|
logger.debug("Registered tool: %s", tool.name)
|
|
|
|
def get(self, name: str) -> BaseTool | None:
|
|
"""Look up a tool by name."""
|
|
return self._tools.get(name)
|
|
|
|
def get_all(self) -> dict[str, BaseTool]:
|
|
"""Return all registered tools."""
|
|
return dict(self._tools)
|
|
|
|
def get_openai_tools_schema(self) -> list[dict[str, Any]]:
|
|
"""Return OpenAI function-calling schemas for all registered tools."""
|
|
return [tool.get_openai_schema() for tool in self._tools.values()]
|
|
|
|
|
|
def create_default_registry(workspace_root: Path, config: AppConfig) -> ToolRegistry:
|
|
"""Create a ToolRegistry populated with all built-in tools."""
|
|
from app.tools.filesystem import ListDirTool, ReadFileTool
|
|
from app.tools.finish import FinishTool
|
|
from app.tools.search import FindFilesTool, GrepFilesTool
|
|
|
|
registry = ToolRegistry()
|
|
registry.register(ReadFileTool(workspace_root, config))
|
|
registry.register(ListDirTool(workspace_root, config))
|
|
registry.register(GrepFilesTool(workspace_root, config))
|
|
registry.register(FindFilesTool(workspace_root, config))
|
|
registry.register(FinishTool(workspace_root, config))
|
|
return registry
|