mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-08-21 04:02:22 +02:00
- PostHog integration: collector, analytics subapp, opt-in UI, Analytics page - 9Router: auto-start, OAuth subscription flow, /v1/messages Anthropic format support - Settings overhaul: multi-provider API keys, subscription connect UI, onboarding modal - Unified usage: merge 9Router cost/token data into Settings Usage tab - Provider system: providers/, agent_loop, tools/ (unused, for future non-Anthropic support) - Agent SDK: restored as primary with 9Router ANTHROPIC_BASE_URL fallback - Updated system prompt, credential resolution, dashboard analytics
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
"""Base classes for builtin tool implementations."""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
|
|
@dataclass
|
|
class ToolContext:
|
|
"""Runtime context passed to every tool execution."""
|
|
cwd: str
|
|
session_id: str
|
|
|
|
|
|
class BaseTool(ABC):
|
|
"""Abstract base for all builtin tools.
|
|
|
|
Subclasses must set ``name`` and ``description`` as class attributes and
|
|
implement ``get_schema`` (JSON Schema for tool input) and ``execute``.
|
|
"""
|
|
|
|
name: str
|
|
description: str
|
|
|
|
@abstractmethod
|
|
def get_schema(self) -> dict:
|
|
"""Return JSON Schema for this tool's input parameters."""
|
|
...
|
|
|
|
@abstractmethod
|
|
async def execute(self, input_data: dict, context: ToolContext) -> list[dict]:
|
|
"""Execute the tool.
|
|
|
|
Returns a list of content blocks, e.g.
|
|
``[{"type": "text", "text": "..."}]``.
|
|
"""
|
|
...
|
|
|
|
def to_tool_schema(self):
|
|
"""Convert to the provider-agnostic ``ToolSchema`` used everywhere."""
|
|
from backend.apps.agents.providers.base import ToolSchema
|
|
|
|
return ToolSchema(
|
|
name=self.name,
|
|
description=self.description,
|
|
input_schema=self.get_schema(),
|
|
)
|