praval.core.tool_registry
Tool Registry for Praval Framework.
This module provides a centralized registry for managing tools and their relationships to agents. Tools can be registered, discovered, and assigned to agents dynamically.
Functions
Get the global tool registry instance. |
|
Reset the global tool registry (primarily for testing). |
Classes
|
Wrapper class for a registered tool function. |
|
Metadata for a registered tool. |
Centralized registry for managing tools and their relationships to agents. |
- class praval.core.tool_registry.ToolMetadata(tool_name, owned_by=None, description='', category='general', shared=False, version='1.0.0', author='', tags=<factory>, parameters=<factory>, return_type='Any', requires_approval=False, risk_level='low', approval_reason='')[source]
Bases:
objectMetadata for a registered tool.
- Parameters:
tool_name (str)
owned_by (str | None)
description (str)
category (str)
shared (bool)
version (str)
author (str)
tags (List[str])
parameters (Dict[str, Any])
return_type (str)
requires_approval (bool)
risk_level (str)
approval_reason (str)
- tool_name: str
- owned_by: str | None = None
- description: str = ''
- category: str = 'general'
- version: str = '1.0.0'
- author: str = ''
- tags: List[str]
- parameters: Dict[str, Any]
- return_type: str = 'Any'
- requires_approval: bool = False
- risk_level: str = 'low'
- approval_reason: str = ''
- __init__(tool_name, owned_by=None, description='', category='general', shared=False, version='1.0.0', author='', tags=<factory>, parameters=<factory>, return_type='Any', requires_approval=False, risk_level='low', approval_reason='')
- Parameters:
tool_name (str)
owned_by (str | None)
description (str)
category (str)
shared (bool)
version (str)
author (str)
tags (List[str])
parameters (Dict[str, Any])
return_type (str)
requires_approval (bool)
risk_level (str)
approval_reason (str)
- Return type:
None
- class praval.core.tool_registry.Tool(func, metadata)[source]
Bases:
objectWrapper class for a registered tool function.
Provides metadata, validation, and execution capabilities for functions registered as tools in the Praval framework.
- Parameters:
func (Callable)
metadata (ToolMetadata)
- __init__(func, metadata)[source]
Initialize a Tool instance.
- Parameters:
func (
Callable) – The function to wrap as a toolmetadata (
ToolMetadata) – Metadata describing the tool
- Raises:
ToolError – If function validation fails
- class praval.core.tool_registry.ToolRegistry[source]
Bases:
objectCentralized registry for managing tools and their relationships to agents.
The registry provides functionality to: - Register and retrieve tools - Associate tools with agents - Manage shared tools - Query tools by category - Handle tool lifecycle
- get_tool(tool_name)[source]
Retrieve a tool by name.
- Parameters:
tool_name (
str) – Name of the tool to retrieve- Return type:
Optional[Tool]- Returns:
Tool instance if found, None otherwise
- get_tools_for_agent(agent_name)[source]
Get all tools available to a specific agent.
This includes: - Tools owned by the agent - Shared tools - Tools explicitly assigned to the agent
- Parameters:
agent_name (
str) – Name of the agent- Return type:
List[Tool]- Returns:
List of Tool instances available to the agent
- get_tools_by_category(category)[source]
Get all tools in a specific category.
- Parameters:
category (
str) – Category name- Return type:
List[Tool]- Returns:
List of Tool instances in the category
Get all shared tools.
- Return type:
List[Tool]- Returns:
List of all shared Tool instances
- list_all_tools()[source]
List all registered tools.
- Return type:
List[Tool]- Returns:
List of all Tool instances
- assign_tool_to_agent(tool_name, agent_name)[source]
Assign a tool to an agent at runtime.
- Parameters:
tool_name (
str) – Name of the tool to assignagent_name (
str) – Name of the agent to assign to
- Return type:
bool- Returns:
True if assignment successful, False if tool doesn’t exist
- remove_tool_from_agent(tool_name, agent_name)[source]
Remove a tool assignment from an agent.
- Parameters:
tool_name (
str) – Name of the tool to removeagent_name (
str) – Name of the agent to remove from
- Return type:
bool- Returns:
True if removal successful, False if assignment didn’t exist
- unregister_tool(tool_name)[source]
Unregister a tool from the registry.
- Parameters:
tool_name (
str) – Name of the tool to unregister- Return type:
bool- Returns:
True if unregistration successful, False if tool didn’t exist
- get_registry_stats()[source]
Get statistics about the registry.
- Return type:
Dict[str,Any]- Returns:
Dictionary with registry statistics
- search_tools(name_pattern=None, category=None, owned_by=None, shared_only=False, tags=None)[source]
Search for tools based on multiple criteria.
- Parameters:
name_pattern (
Optional[str]) – Pattern to match in tool names (case-insensitive)category (
Optional[str]) – Specific category to filter byowned_by (
Optional[str]) – Specific owner to filter byshared_only (
bool) – Only return shared toolstags (
Optional[List[str]]) – Tags that tools must have (any match)
- Return type:
List[Tool]- Returns:
List of Tool instances matching the criteria