Tools¶
Define tools and register them for an agent to call.
Tool¶
Tool
¶
Bases: BaseModel
Concrete tool combining definition, metadata, and executor.
ToolDefinition¶
ToolDefinition
¶
Bases: BaseModel
Definition of a tool that the LLM can call.
This describes the tool schema in OpenAI function calling format.
to_openai_schema
¶
Convert to OpenAI function calling format.
Source code in redis_agent_kit/tools/models.py
ToolManager¶
ToolManager
¶
Manages tool providers and routes tool calls.
Example
manager = ToolManager() manager.add_provider(WeatherProvider()) manager.add_provider(KnowledgeProvider(knowledge_store))
Get all tools in OpenAI format¶
tools = manager.get_openai_tools()
Execute a tool call¶
result = await manager.execute("get_weather", {"location": "NYC"})
Initialize tool manager.
Source code in redis_agent_kit/tools/manager.py
add_provider
¶
add_provider(provider: ToolProvider) -> None
Add a tool provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
ToolProvider
|
ToolProvider instance to add. |
required |
Source code in redis_agent_kit/tools/manager.py
remove_provider
¶
Remove a provider by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Provider name to remove. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if removed, False if not found. |
Source code in redis_agent_kit/tools/manager.py
get_tools
¶
get_tools(capabilities: set[ToolCapability] | None = None, exclude_capabilities: set[ToolCapability] | None = None) -> list[Tool]
Get tools, optionally filtered by capability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capabilities
|
set[ToolCapability] | None
|
If set, only include tools with these capabilities. |
None
|
exclude_capabilities
|
set[ToolCapability] | None
|
If set, exclude tools with these capabilities. |
None
|
Returns:
| Type | Description |
|---|---|
list[Tool]
|
List of Tool objects. |
Source code in redis_agent_kit/tools/manager.py
get_openai_tools
¶
get_openai_tools(capabilities: set[ToolCapability] | None = None, exclude_capabilities: set[ToolCapability] | None = None) -> list[dict[str, Any]]
Get tools in OpenAI function calling format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capabilities
|
set[ToolCapability] | None
|
If set, only include tools with these capabilities. |
None
|
exclude_capabilities
|
set[ToolCapability] | None
|
If set, exclude tools with these capabilities. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of OpenAI tool schemas. |
Source code in redis_agent_kit/tools/manager.py
execute
async
¶
Execute a tool by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
str
|
Name of the tool to execute. |
required |
args
|
dict[str, Any]
|
Arguments to pass to the tool. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Tool execution result. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If tool not found. |
Source code in redis_agent_kit/tools/manager.py
ToolProvider¶
ToolProvider
¶
Bases: ABC
Base class for tool providers.
Tool providers expose tools that LLMs can call. Each provider can expose multiple tools and is responsible for implementing them.
Example
class WeatherProvider(ToolProvider): @property def provider_name(self) -> str: return "weather"
@property
def capabilities(self) -> set[ToolCapability]:
return {ToolCapability.UTILITIES}
def create_tool_schemas(self) -> list[ToolDefinition]:
return [
ToolDefinition(
name="get_weather",
description="Get current weather for a location",
capability=ToolCapability.UTILITIES,
parameters={
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"}
},
"required": ["location"],
},
)
]
async def get_weather(self, location: str) -> dict:
return {"location": location, "temp": 72, "conditions": "sunny"}
provider_name
abstractmethod
property
¶
Unique provider name (e.g., 'weather', 'github').
create_tool_schemas
abstractmethod
¶
create_tool_schemas() -> list[ToolDefinition]
tools
¶
tools() -> list[Tool]
Return Tool objects ready for use.
Builds Tool objects from create_tool_schemas(), wiring each to the corresponding method on this provider.
Source code in redis_agent_kit/tools/provider.py
ToolCapability¶
ToolCapability
¶
Bases: StrEnum
Capabilities that tools can provide.
ToolMetadata¶
ToolMetadata
¶
Bases: BaseModel
Metadata about a tool implementation.