Tools¶
Tool (Protocol)¶
Tool ¶
Bases: Protocol
Protocol for tool implementations.
Tools are pluggable components that agents can use to interact with external systems (databases, APIs, caches, etc.).
Using Protocol so that third-party tool implementations can satisfy this interface without depending on AgenticAPI.
Source code in src/agenticapi/runtime/tools/base.py
invoke
async
¶
Invoke the tool with the given keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Tool-specific parameters. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The tool's result (type depends on the tool). |
ToolDefinition¶
ToolDefinition
dataclass
¶
Metadata describing a tool's interface and capabilities.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique identifier for the tool. |
description |
str
|
Human-readable description of what the tool does. |
capabilities |
list[ToolCapability]
|
List of capabilities this tool provides. |
parameters_schema |
dict[str, Any]
|
JSON Schema describing the tool's parameters. |
Source code in src/agenticapi/runtime/tools/base.py
ToolCapability¶
ToolCapability ¶
Bases: StrEnum
Capabilities that a tool can provide.
Used for policy evaluation to determine what operations a tool is permitted to perform.
Source code in src/agenticapi/runtime/tools/base.py
ToolRegistry¶
ToolRegistry ¶
Registry for managing available tools.
Manages tool registration, lookup by name, and provides tool definitions for code generation prompts.
Example
registry = ToolRegistry() registry.register(database_tool) tool = registry.get("database") definitions = registry.get_definitions()
Source code in src/agenticapi/runtime/tools/registry.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
__init__ ¶
Initialize the registry with optional initial tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tools
|
list[Tool | Callable[..., Any]] | None
|
Optional list of tools to register immediately.
Each entry may be either a :class: |
None
|
Source code in src/agenticapi/runtime/tools/registry.py
register ¶
Register a tool in the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool
|
Tool | Callable[..., Any]
|
The tool to register. May be either a :class: |
required |
Raises:
| Type | Description |
|---|---|
ToolError
|
If a tool with the same name is already registered. |
Source code in src/agenticapi/runtime/tools/registry.py
get ¶
Look up a tool by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the tool to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Tool
|
The registered tool. |
Raises:
| Type | Description |
|---|---|
ToolError
|
If no tool with the given name is registered. |
Source code in src/agenticapi/runtime/tools/registry.py
list_tools ¶
Return definitions for all registered tools.
Returns:
| Type | Description |
|---|---|
list[ToolDefinition]
|
List of ToolDefinition objects for all registered tools. |
Source code in src/agenticapi/runtime/tools/registry.py
get_definitions ¶
Return definitions for all registered tools.
Alias for list_tools() for API consistency.
Returns:
| Type | Description |
|---|---|
list[ToolDefinition]
|
List of ToolDefinition objects for all registered tools. |
Source code in src/agenticapi/runtime/tools/registry.py
@tool decorator¶
FastAPI-style decorator that turns a plain Python function into a registered tool with an auto-generated JSON Schema. See the Tool Decorator guide for usage patterns.
tool ¶
tool(
func: Callable[..., Any] | None = None,
/,
*,
name: str | None = None,
description: str | None = None,
capabilities: list[ToolCapability] | None = None,
) -> Any
Decorate a function so it satisfies the :class:Tool protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any] | None
|
The function to decorate. Supplied automatically by the
|
None
|
name
|
str | None
|
Optional override for the tool name. Defaults to the
function's |
None
|
description
|
str | None
|
Optional override for the tool description. Defaults to the first non-empty line of the function's docstring, or a generic placeholder. |
None
|
capabilities
|
list[ToolCapability] | None
|
Optional list of :class: |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
An object satisfying the :class: |
Any
|
callable as the original function. |
Source code in src/agenticapi/runtime/tools/decorator.py
DatabaseTool¶
DatabaseTool ¶
A tool that executes database queries via an async callable.
Wraps a user-provided async function for executing queries, enforcing read-only mode when configured.
Example
async def execute_query(query: str, params: dict | None = None): return await db.fetch_all(query, params or {})
tool = DatabaseTool(execute_fn=execute_query, read_only=True) result = await tool.invoke(query="SELECT COUNT(*) FROM orders")
Source code in src/agenticapi/runtime/tools/database.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
__init__ ¶
__init__(
*,
name: str = "database",
description: str = "Execute SQL queries against a database",
execute_fn: AsyncExecuteFn | None = None,
read_only: bool = True,
) -> None
Initialize the database tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name for this tool instance. |
'database'
|
description
|
str
|
Human-readable description. |
'Execute SQL queries against a database'
|
execute_fn
|
AsyncExecuteFn | None
|
Async callable that executes queries. Signature: async (query: str, params: dict | None) -> Any |
None
|
read_only
|
bool
|
If True, reject write operations. |
True
|
Source code in src/agenticapi/runtime/tools/database.py
invoke
async
¶
Execute a database query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
The SQL query string to execute. |
required |
params
|
dict[str, Any] | None
|
Optional parameters for parameterized queries. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The query result from the execute function. |
Raises:
| Type | Description |
|---|---|
ToolError
|
If the tool has no execute function configured, or if a write operation is attempted in read-only mode. |
Source code in src/agenticapi/runtime/tools/database.py
CacheTool¶
CacheTool ¶
An in-memory cache tool with TTL support.
Provides get, set, delete, and exists operations on a key-value store with per-entry expiration.
Example
tool = CacheTool(default_ttl_seconds=300) await tool.invoke(action="set", key="user:1", value={"name": "Alice"}) result = await tool.invoke(action="get", key="user:1")
Source code in src/agenticapi/runtime/tools/cache.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
__init__ ¶
__init__(
*,
name: str = "cache",
description: str = "In-memory key-value cache with TTL",
max_size: int = 1000,
default_ttl_seconds: float = 300.0,
) -> None
Initialize the cache tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name for this tool instance. |
'cache'
|
description
|
str
|
Human-readable description. |
'In-memory key-value cache with TTL'
|
max_size
|
int
|
Maximum number of entries before eviction. |
1000
|
default_ttl_seconds
|
float
|
Default TTL for entries in seconds. |
300.0
|
Source code in src/agenticapi/runtime/tools/cache.py
invoke
async
¶
Perform a cache operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
str
|
One of "get", "set", "delete", "exists". |
required |
key
|
str
|
The cache key. |
required |
value
|
Any
|
The value to store (required for "set"). |
None
|
ttl
|
float | None
|
TTL in seconds (defaults to default_ttl_seconds). |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The cached value for "get", True/False for "exists", |
Any
|
None for "set" and "delete". |
Raises:
| Type | Description |
|---|---|
ToolError
|
If the action is invalid. |
Source code in src/agenticapi/runtime/tools/cache.py
HttpClientTool¶
HttpClientTool ¶
A tool for making HTTP requests.
Wraps httpx.AsyncClient with optional host allowlisting. Supports GET, POST, PUT, PATCH, DELETE methods.
Example
tool = HttpClientTool(allowed_hosts=["api.example.com"]) result = await tool.invoke(method="GET", url="https://api.example.com/data")
Source code in src/agenticapi/runtime/tools/http_client.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
__init__ ¶
__init__(
*,
name: str = "http_client",
description: str = "Make HTTP requests to external APIs",
allowed_hosts: list[str] | None = None,
timeout: float = 30.0,
default_headers: dict[str, str] | None = None,
) -> None
Initialize the HTTP client tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name for this tool instance. |
'http_client'
|
description
|
str
|
Human-readable description. |
'Make HTTP requests to external APIs'
|
allowed_hosts
|
list[str] | None
|
If set, only requests to these hosts are permitted. |
None
|
timeout
|
float
|
Default request timeout in seconds. |
30.0
|
default_headers
|
dict[str, str] | None
|
Default headers to include in every request. |
None
|
Source code in src/agenticapi/runtime/tools/http_client.py
invoke
async
¶
invoke(
*,
method: str,
url: str,
headers: dict[str, str] | None = None,
body: Any = None,
) -> dict[str, Any]
Make an HTTP request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
HTTP method (GET, POST, etc.). |
required |
url
|
str
|
The URL to request. |
required |
headers
|
dict[str, str] | None
|
Optional additional headers. |
None
|
body
|
Any
|
Optional request body (JSON-serializable). |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with status, headers, and body. |
Raises:
| Type | Description |
|---|---|
ToolError
|
If the host is not allowed, method is invalid, or the request fails. |
Source code in src/agenticapi/runtime/tools/http_client.py
QueueTool¶
QueueTool ¶
An in-memory async queue tool for message passing.
Provides enqueue, dequeue, peek, and size operations on named queues.
Example
tool = QueueTool() await tool.invoke(action="enqueue", queue_name="tasks", message={"id": 1}) msg = await tool.invoke(action="dequeue", queue_name="tasks")
Source code in src/agenticapi/runtime/tools/queue.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
__init__ ¶
__init__(
*,
name: str = "queue",
description: str = "In-memory async message queue",
max_size: int = 0,
) -> None
Initialize the queue tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name for this tool instance. |
'queue'
|
description
|
str
|
Human-readable description. |
'In-memory async message queue'
|
max_size
|
int
|
Maximum queue size (0 for unlimited). |
0
|
Source code in src/agenticapi/runtime/tools/queue.py
invoke
async
¶
invoke(
*,
action: str,
queue_name: str,
message: Any = None,
timeout: float | None = None,
) -> Any
Perform a queue operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
str
|
One of "enqueue", "dequeue", "peek", "size". |
required |
queue_name
|
str
|
Name of the queue to operate on. |
required |
message
|
Any
|
Message to enqueue (required for "enqueue"). |
None
|
timeout
|
float | None
|
Timeout for dequeue in seconds. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The message for "dequeue"/"peek", int for "size", None for "enqueue". |
Raises:
| Type | Description |
|---|---|
ToolError
|
If the action is invalid or the operation fails. |