Coverage for /home/admin/Documents/AI/applications/lexigram-dev/lexigram/experimental/ai/lexigram-ai-agents/src/lexigram/ai/agents/tools/base.py: 100%
17 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 07:19 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 07:19 +0800
1"""Base Tool class for class-based tools."""
3from __future__ import annotations
5from abc import ABC, abstractmethod
6from typing import Any
8from lexigram.contracts.ai.agents import ToolProtocol
11class AbstractTool(ABC, ToolProtocol):
12 """Abstract base class for class-based agent tools.
14 Subclass this to create tools with more complex behavior
15 than simple function wrappers.
17 Example::
19 class OrderLookupTool(AbstractTool):
20 def __init__(self, order_service: OrderService):
21 self.order_service = order_service
23 @property
24 def name(self) -> str:
25 return "lookup_order"
27 @property
28 def description(self) -> str:
29 return "Look up an order by its ID"
31 @property
32 def parameters_schema(self) -> dict[str, Any]:
33 return {
34 "type": "object",
35 "properties": {
36 "order_id": {"type": "string"}
37 },
38 "required": ["order_id"]
39 }
41 async def execute(self, **kwargs: Any) -> Any:
42 order_id = kwargs.get("order_id")
43 return await self.order_service.find(order_id)
44 """
46 @property
47 @abstractmethod
48 def name(self) -> str:
49 """Unique tool identifier. Must be implemented by subclass."""
51 @property
52 @abstractmethod
53 def description(self) -> str:
54 """Human-readable description for the LLM. Must be implemented by subclass."""
56 @property
57 @abstractmethod
58 def parameters_schema(self) -> dict[str, Any]:
59 """JSON Schema describing the tool's parameters. Must be implemented by subclass."""
61 @abstractmethod
62 async def execute(self, **kwargs: Any) -> Any:
63 """Execute the tool with the given arguments. Must be implemented by subclass."""
66__all__ = ["AbstractTool"]