Tools¶
Tools infrastructure for building Agents.
Resolution chain for tool imports: 1. Core tools (always available — defined directly in this module) 2. parrot_tools (ai-parrot-tools installed package) 3. plugins.tools (user/deploy-time plugin directory) 4. TOOL_REGISTRY (declarative registry from ai-parrot-tools) 5. Legacy dynamic_import_helper (backward-compat submodule resolution)
Submodule redirector
from parrot.tools.prophetforecast import X is transparently redirected
to from parrot_tools.prophetforecast import X when no local submodule
exists. This is done via a sys.meta_path finder installed at import time.
AbstractTool ¶
AbstractTool(name: Optional[str] = None, description: Optional[str] = None, output_dir: Optional[Union[str, Path]] = None, base_url: Optional[str] = None, static_dir: Optional[Union[str, Path]] = None, routing_meta: Optional[Dict] = None, executor: Optional[AbstractToolExecutor] = None, webhook_callback_url: Optional[str] = None, remote_timeout_seconds: int = 300, **kwargs)
Bases: EventEmitterMixin, ABC
Abstract base class for all tools in the ai-parrot framework.
This class provides a unified interface for tools that can be used by both conversational bots and agents. It includes common functionality like: - Name and description management - JSON schema generation - File path management - Logging and error handling - Async/sync execution support - Lifecycle event emission (FEAT-176)
Initialize the tool.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Tool name (defaults to class name)
TYPE:
|
description
|
Tool description
TYPE:
|
output_dir
|
Directory for output files (if tool generates files)
TYPE:
|
base_url
|
Base URL for serving static files
TYPE:
|
static_dir
|
Static directory path
TYPE:
|
routing_meta
|
Optional routing hints dict for CapabilityRegistry.
Supported keys:
TYPE:
|
executor
|
Optional :class:
TYPE:
|
webhook_callback_url
|
When set, the executor returns a
TYPE:
|
remote_timeout_seconds
|
Max wall-clock seconds the executor
waits for the remote runtime to return. Ignored when
TYPE:
|
**kwargs
|
Additional configuration
DEFAULT:
|
Source code in packages/ai-parrot/src/parrot/tools/abstract.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
clone ¶
Create a new instance of this tool with the same configuration.
This method creates a new instance of the tool class with all the initialization parameters that were passed to the current instance. Subclasses can override _get_clone_kwargs() to customize which parameters are cloned and which are not.
| RETURNS | DESCRIPTION |
|---|---|
|
New instance of the same tool class with cloned configuration |
Example
dbtool = DatabaseTool(connection_string="postgresql://...") new_tool = dbtool.clone()
new_tool is a fresh instance with the same configuration¶
Source code in packages/ai-parrot/src/parrot/tools/abstract.py
get_schema ¶
Get the JSON schema for this tool.
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
JSON schema dictionary compatible with LLM tool registration |
Source code in packages/ai-parrot/src/parrot/tools/abstract.py
get_tool_schema ¶
Get the JSON schema for the tool's arguments. Alias for get_schema() for backward compatibility.
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
Dictionary containing the JSON schema |
Source code in packages/ai-parrot/src/parrot/tools/abstract.py
validate_args ¶
Validate arguments using the tool's schema.
| PARAMETER | DESCRIPTION |
|---|---|
**kwargs
|
Arguments to validate
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
BaseModel
|
Validated arguments as Pydantic model instance |
Source code in packages/ai-parrot/src/parrot/tools/abstract.py
execute
async
¶
Execute the tool with error handling and result standardization.
| PARAMETER | DESCRIPTION |
|---|---|
*args
|
Positional arguments for the tool.
DEFAULT:
|
**kwargs
|
Tool arguments. Special kwargs are:
- _permission_context: PermissionContext for Layer 2 enforcement
- _resolver: AbstractPermissionResolver for permission checks
- _a2ui_surface_state: The A2UI SurfaceState for the turn that
triggered this call, if any (FEAT-469 spec §3 Module 8).
When given, applied to the per-call
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
ToolResult
|
Standardized ToolResult. Returns status='forbidden' if permission denied. |
TODO: Use the Global Registry to share data between tools.
Source code in packages/ai-parrot/src/parrot/tools/abstract.py
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 | |
run
async
¶
Public alias for executing the tool directly without the ToolResult wrapper. Provides a direct way to get raw results instead of calling _execute().
Source code in packages/ai-parrot/src/parrot/tools/abstract.py
to_static_url ¶
Convert an absolute file path to a static URL.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
Absolute path to the file
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
URL-based path for serving the static file |
Source code in packages/ai-parrot/src/parrot/tools/abstract.py
relative_url ¶
Convert an absolute URL to a relative URL based on the base URL.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
Absolute URL to convert
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Relative URL based on the base URL |
Source code in packages/ai-parrot/src/parrot/tools/abstract.py
generate_filename ¶
generate_filename(prefix: str = 'output', extension: str = '', include_timestamp: bool = True) -> str
Generate a unique filename with optional timestamp.
| PARAMETER | DESCRIPTION |
|---|---|
prefix
|
File prefix
TYPE:
|
extension
|
File extension (with or without dot)
TYPE:
|
include_timestamp
|
Whether to include timestamp
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Generated filename |
Source code in packages/ai-parrot/src/parrot/tools/abstract.py
validate_output_path ¶
Validate and ensure the output path is within allowed directories.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
Path to validate
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Validated Path object |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If path is outside allowed directories |
Source code in packages/ai-parrot/src/parrot/tools/abstract.py
ToolResult ¶
AbstractToolkit ¶
Bases: ABC
Abstract base class for creating toolkits - collections of related tools.
A toolkit automatically converts all public async methods into tools. Each method becomes a tool with: - Name: method name - Description: method docstring - Schema: automatically generated from type hints
Usage
class MyToolkit(AbstractToolkit): async def search_web(self, query: str) -> str: '''Search the web for information.''' # Implementation here return result
async def calculate(self, expression: str) -> float:
'''Calculate a mathematical expression.'''
# Implementation here
return result
Get all tools¶
toolkit = MyToolkit() tools = toolkit.get_tools()
Initialize the toolkit.
| PARAMETER | DESCRIPTION |
|---|---|
executor
|
Optional
|
webhook_callback_url
|
Forwarded to each generated tool's
|
remote_timeout_seconds
|
Forwarded as the per-tool remote timeout.
|
**kwargs
|
Additional configuration
DEFAULT:
|
Source code in packages/ai-parrot/src/parrot/tools/toolkit.py
start
async
¶
stop
async
¶
cleanup
async
¶
get_tools ¶
get_tools(permission_context: Optional[PermissionContext] = None, resolver: Optional[AbstractPermissionResolver] = None) -> list[AbstractTool]
Get all tools from this toolkit, optionally filtered by permissions.
Inspects all public methods and converts them to tools.
.. note::
Permission filtering requires ``await`` because resolvers are
async. Use :meth:`get_tools_filtered` for the async path.
When *permission_context* and *resolver* are passed here the
method returns **all** tools (backward-compatible) — callers
must migrate to ``get_tools_filtered()`` for actual filtering.
| PARAMETER | DESCRIPTION |
|---|---|
permission_context
|
Ignored (kept for signature compat).
Use :meth:
TYPE:
|
resolver
|
Ignored (kept for signature compat).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[AbstractTool]
|
List of AbstractTool instances (unfiltered). |
Source code in packages/ai-parrot/src/parrot/tools/toolkit.py
get_tools_filtered
async
¶
get_tools_filtered(permission_context: PermissionContext, resolver: AbstractPermissionResolver) -> list[AbstractTool]
Get tools filtered by async permission resolver.
This is the async-aware version of :meth:get_tools that supports
Layer 1 preventive filtering through the resolver.
| PARAMETER | DESCRIPTION |
|---|---|
permission_context
|
User context for permission filtering.
TYPE:
|
resolver
|
Permission resolver for checking access (async).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[AbstractTool]
|
Filtered list of AbstractTool instances the user may execute. |
Source code in packages/ai-parrot/src/parrot/tools/toolkit.py
get_tools_sync ¶
get_tools_sync(permission_context: Optional[PermissionContext] = None, resolver: Optional[AbstractPermissionResolver] = None) -> list[AbstractTool]
Synchronous alias for get_tools(). Returns all tools (unfiltered).
Source code in packages/ai-parrot/src/parrot/tools/toolkit.py
get_tool ¶
Get a specific tool by name.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Tool name
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AbstractTool | None
|
AbstractTool instance or None if not found |
Source code in packages/ai-parrot/src/parrot/tools/toolkit.py
list_tool_names ¶
Get a list of all tool names in this toolkit.
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of tool names |
Source code in packages/ai-parrot/src/parrot/tools/toolkit.py
get_toolkit_info ¶
Get information about this toolkit.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Any]
|
Dictionary with toolkit information |
Source code in packages/ai-parrot/src/parrot/tools/toolkit.py
ToolkitTool ¶
ToolkitTool(name: str, bound_method: callable, description: str = None, args_schema: type[BaseModel] = None, **kwargs)
Bases: AbstractTool
A specialized AbstractTool that wraps a method from a toolkit.
Initialize a toolkit tool.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Tool name
TYPE:
|
bound_method
|
The bound coroutine method to wrap
TYPE:
|
description
|
Tool description
TYPE:
|
args_schema
|
Pydantic model for arguments
TYPE:
|
**kwargs
|
Additional arguments
DEFAULT:
|
Source code in packages/ai-parrot/src/parrot/tools/toolkit.py
ToolkitRegistry ¶
Registry for supported toolkits with lazy loading.
.. deprecated::
Use ToolManager with discovery instead. This class is
maintained for backward compatibility.
AbstractToolExecutor ¶
Bases: ABC
Pluggable transport that runs a tool somewhere other than here.
Concrete executors translate a :class:ToolExecutionEnvelope into
whatever protocol the remote runtime speaks (HTTP, gRPC, k8s API,
Redis Streams, etc.) and return a :class:ToolResult once the
remote side finishes — either by waiting synchronously up to
envelope.timeout_seconds or by returning a pending
ToolResult and arranging for the final result to arrive via webhook.
Concrete implementations:
- :class:
LocalToolExecutor— in-process; reference / tests - :class:
K8sToolExecutor— ephemeral Pod via kubernetes-asyncio - :class:
QworkerToolExecutor— Qworker service (HTTP / Redis)
execute
abstractmethod
async
¶
Run the tool described by envelope and return its ToolResult.
Implementations must:
- raise :class:
asyncio.TimeoutError(or a structuredToolResult(status="error", error="timeout")) when the remote side fails to respond withinenvelope.timeout_seconds. - never re-run permission checks. Those happen on the caller.
- propagate
envelope.trace_contextto the worker so the trace stays connected.
| RETURNS | DESCRIPTION |
|---|---|
'ToolResult'
|
The final ToolResult, or a |
'ToolResult'
|
with |
'ToolResult'
|
constructed with a webhook delivery configuration. |
Source code in packages/ai-parrot/src/parrot/tools/executors/abstract.py
close
abstractmethod
async
¶
Release any pooled resources (HTTP sessions, k8s clients, etc.).
Idempotent: calling close() multiple times must not raise.
LocalToolExecutor ¶
Bases: AbstractToolExecutor
Executor that runs the tool in the current Python process.
Used as the reference implementation: it imports the tool by path,
instantiates it from envelope.tool_init_kwargs, and awaits its
_execute(**envelope.arguments). Because it shares the runner
module with the worker entrypoint, this is what the
K8sToolExecutor worker pod ends up doing inside its own
process — and what unit tests can exercise without ceremony.
ToolExecutionEnvelope ¶
Bases: BaseModel
The wire-format payload describing a single remote tool invocation.
| ATTRIBUTE | DESCRIPTION |
|---|---|
tool_import_path |
Dotted Python path of the tool class, formatted
as
TYPE:
|
tool_init_kwargs |
Constructor arguments captured from the caller's
instance. Forwarded as
TYPE:
|
method_name |
For
TYPE:
|
arguments |
Validated tool arguments (the kwargs that would
normally be passed to
TYPE:
|
permission_context |
JSON projection of the caller's
TYPE:
|
trace_context |
JSON projection of the parent span so the remote runtime can mint a child span and keep the trace connected.
TYPE:
|
timeout_seconds |
Maximum wall-clock seconds to wait for the remote runtime to return a result.
TYPE:
|
webhook_callback_url |
When set, the executor returns immediately
with a
TYPE:
|
envelope_version |
Schema version. Bumped when the contract changes in a backwards-incompatible way.
TYPE:
|
MCPToolManagerMixin ¶
Mixin to add MCP capabilities to ToolManager.
This mixin adds the following capabilities: - Connect to MCP servers (HTTP, SSE, WebSocket, stdio, QUIC) - Register MCP tools as proxy tools in the ToolManager - Generate OpenAI-compatible MCP definitions - Manage server lifecycle (connect, disconnect, reconfigure)
| ATTRIBUTE | DESCRIPTION |
|---|---|
_mcp_clients |
Dictionary mapping server names to MCPClient instances
|
_mcp_configs |
Dictionary mapping server names to MCPServerConfig
|
_mcp_logger |
Logger for MCP operations
|
add_mcp_server
async
¶
Add MCP server with context-aware tool registration.
Connects to an MCP server and registers its tools as proxy tools in this ToolManager. The tools are filtered based on the config's allowed_tools, blocked_tools, and tool_filter settings.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
MCPServerConfig with connection and filtering options
TYPE:
|
context
|
Optional ReadonlyContext for dynamic filtering decisions
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of registered tool names (prefixed with mcp_{server_name}_) |
| RAISES | DESCRIPTION |
|---|---|
MCPConnectionError
|
If connection to server fails |
Example
Source code in packages/ai-parrot/src/parrot/tools/mcp_mixin.py
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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
add_database_mcp
async
¶
add_database_mcp(name: str, project_id: str, toolbox_path: str = './toolbox', database_type: str = 'bigquery', context: Optional['ReadonlyContext'] = None, extra_env: Optional[Dict[str, str]] = None) -> List[str]
Add a database MCP server using the genai-toolbox.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name for the MCP server instance
TYPE:
|
project_id
|
GCP Project ID to use
TYPE:
|
toolbox_path
|
Path to the toolbox binary (default: ./toolbox)
TYPE:
|
database_type
|
Type of database (default: bigquery)
TYPE:
|
context
|
Optional context for filtering
TYPE:
|
extra_env
|
Optional extra environment variables
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of registered tool names |
Source code in packages/ai-parrot/src/parrot/tools/mcp_mixin.py
add_github_mcp
async
¶
add_github_mcp(name: str = 'github', personal_access_token: Optional[str] = None, context: Optional['ReadonlyContext'] = None, **kwargs) -> List[str]
Add GitHub MCP server using npx.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Server name (default: "github")
TYPE:
|
personal_access_token
|
GitHub PAT. If None, checks GITHUB_PERSONAL_ACCESS_TOKEN env var.
TYPE:
|
context
|
Optional context for filtering
TYPE:
|
**kwargs
|
Additional config arguments
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of registered tool names |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If token is missing |
Source code in packages/ai-parrot/src/parrot/tools/mcp_mixin.py
add_github_remote_mcp
async
¶
add_github_remote_mcp(name: str = 'github-remote', personal_access_token: Optional[str] = None, toolsets: Union[List[str], str] = 'repos,issues', readonly: bool = True, lockdown: bool = False, context: Optional['ReadonlyContext'] = None, **kwargs) -> List[str]
Add GitHub Remote MCP server (insiders) via HTTP.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Server name (default: "github-remote")
TYPE:
|
personal_access_token
|
GitHub PAT. If None, checks GITHUB_PERSONAL_ACCESS_TOKEN.
TYPE:
|
toolsets
|
List or comma-separated string of toolsets (default: "repos,issues")
TYPE:
|
readonly
|
Whether to run in readonly mode (default: True)
TYPE:
|
lockdown
|
Whether to run in lockdown mode (default: False)
TYPE:
|
context
|
Optional context for filtering
TYPE:
|
**kwargs
|
Additional config arguments
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of registered tool names |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If token is missing |
Source code in packages/ai-parrot/src/parrot/tools/mcp_mixin.py
remove_mcp_server
async
¶
Remove an MCP server and unregister its tools.
Disconnects from the specified MCP server and removes all tools that were registered from it.
| PARAMETER | DESCRIPTION |
|---|---|
server_name
|
Name of the MCP server to remove
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if server was removed, False if not found |
Example
Source code in packages/ai-parrot/src/parrot/tools/mcp_mixin.py
reconfigure_mcp_server
async
¶
reconfigure_mcp_server(config: 'MCPServerConfig', context: Optional['ReadonlyContext'] = None) -> List[str]
Reconfigure an existing MCP server with new settings.
This removes the existing server and re-adds it with new configuration. Useful for changing auth tokens, allowed tools, etc.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
New MCPServerConfig (name must match existing server)
TYPE:
|
context
|
Optional ReadonlyContext for filtering
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of newly registered tool names |
Source code in packages/ai-parrot/src/parrot/tools/mcp_mixin.py
disconnect_all_mcp
async
¶
Disconnect from all MCP servers and unregister their tools.
Cleanly disconnects all MCP server connections and removes all associated proxy tools from this ToolManager. Safe to call at session teardown or during a full reset.
Source code in packages/ai-parrot/src/parrot/tools/mcp_mixin.py
list_mcp_servers ¶
List all connected MCP server names.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of server names that are currently connected |
get_mcp_client ¶
Get MCP client by server name.
| PARAMETER | DESCRIPTION |
|---|---|
server_name
|
Name of the server
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional['MCPClient']
|
MCPClient instance or None if not found |
Source code in packages/ai-parrot/src/parrot/tools/mcp_mixin.py
get_mcp_config ¶
Get MCP server configuration by name.
| PARAMETER | DESCRIPTION |
|---|---|
server_name
|
Name of the server
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Optional['MCPServerConfig']
|
MCPServerConfig or None if not found |
Source code in packages/ai-parrot/src/parrot/tools/mcp_mixin.py
get_openai_mcp_definitions ¶
Get OpenAI-compatible MCP tool definitions.
Generates definitions in the format OpenAI accepts for native MCP server injection. Only servers with HTTP-based transports (http, sse, websocket) are included since OpenAI doesn't support stdio.
The returned format is:
{
"type": "mcp",
"server_label": "server_name",
"server_description": "...", # optional
"server_url": "https://...",
"require_approval": "never" | "always",
"allowed_tools": [...], # optional
"headers": {...} # optional
}
| PARAMETER | DESCRIPTION |
|---|---|
server_names
|
Optional list of server names to include. If None, includes all HTTP-based servers.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[Dict[str, Any]]
|
List of OpenAI-compatible MCP definitions |
Example
# Get all definitions
tools = tool_manager.get_openai_mcp_definitions()
# Get specific servers only
tools = tool_manager.get_openai_mcp_definitions(['web-tools'])
# Use with OpenAI
from openai import OpenAI
client = OpenAI()
resp = client.responses.create(
model="gpt-5",
tools=tools,
input="Search for AI news"
)
Source code in packages/ai-parrot/src/parrot/tools/mcp_mixin.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
get_mcp_tools ¶
Get all MCP tools, optionally filtered by server.
| PARAMETER | DESCRIPTION |
|---|---|
server_name
|
Optional server name to filter by. If None, returns all MCP tools.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
List[Any]
|
List of MCPToolProxy instances |
Source code in packages/ai-parrot/src/parrot/tools/mcp_mixin.py
has_mcp_servers ¶
Check if any MCP servers are connected.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if at least one MCP server is connected |
get_mcp_server_info ¶
Get detailed information about all connected MCP servers.
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Dict[str, Any]]
|
Dictionary mapping server names to info dicts containing: |
Dict[str, Dict[str, Any]]
|
|
Dict[str, Dict[str, Any]]
|
|
Dict[str, Dict[str, Any]]
|
|
Dict[str, Dict[str, Any]]
|
|
Source code in packages/ai-parrot/src/parrot/tools/mcp_mixin.py
ToJsonTool ¶
ToJsonTool(name: Optional[str] = None, description: Optional[str] = None, output_dir: Optional[Union[str, Path]] = None, base_url: Optional[str] = None, static_dir: Optional[Union[str, Path]] = None, routing_meta: Optional[Dict] = None, executor: Optional[AbstractToolExecutor] = None, webhook_callback_url: Optional[str] = None, remote_timeout_seconds: int = 300, **kwargs)
Bases: AbstractTool
Tool to convert data to JSON using datamodel.parsers.json.
Source code in packages/ai-parrot/src/parrot/tools/abstract.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | |
AgentTool ¶
AgentTool(agent: 'AbstractBot', tool_name: str = None, tool_description: str = None, use_conversation_method: bool = True, context_filter: Optional[Callable[[AgentContext], AgentContext]] = None, execution_memory: Optional[Any] = None, **kwargs)
Bases: AbstractTool
Wraps any BasicAgent/AbstractBot as a tool for use by other agents.
- Schema includes "parameters" key for Google GenAI compatibility
- Uses Pydantic args_schema for validation
- Accepts all args as **kwargs in _execute()
Source code in packages/ai-parrot/src/parrot/tools/agent.py
get_schema ¶
Return the tool schema in the format expected by Google GenAI.
| RETURNS | DESCRIPTION |
|---|---|
Dict[str, Any]
|
Schema with structure: |
Dict[str, Any]
|
{ "name": "tool_name", "description": "...", "parameters": { # ← Google GenAI looks for this "type": "object", "properties": {...}, "required": [...] } |
Dict[str, Any]
|
} |
Source code in packages/ai-parrot/src/parrot/tools/agent.py
get_usage_stats ¶
Get usage statistics for this agent tool.
Source code in packages/ai-parrot/src/parrot/tools/agent.py
SpawnSubAgentTool ¶
SpawnSubAgentTool(bot_manager: Any, owner_id: str, *, allowed_tools: Optional[List[str]] = None, name: str = 'spawn_sub_agent', description: Optional[str] = None, routing_meta: Optional[Dict[str, Any]] = None)
Bases: AbstractTool
Spawn an ephemeral sub-agent to execute a single task.
Creates a short-lived sub-agent owned by the calling agent, executes one task with a restricted tool subset and a timeout, then discards the sub-agent — regardless of success, error, or timeout.
The tool never calls promote_user_bot; all sub-agents are
ephemeral and discarded after their task completes.
| PARAMETER | DESCRIPTION |
|---|---|
bot_manager
|
The
TYPE:
|
owner_id
|
Canonical string ID of the parent agent that owns the
sub-agent (e.g.
TYPE:
|
allowed_tools
|
Allowlist of tool names the parent authorises for
sub-agents. The sub-agent receives only the intersection of
this list and the
TYPE:
|
name
|
Tool name (default:
TYPE:
|
description
|
Tool description override.
TYPE:
|
routing_meta
|
Routing hints for the CapabilityRegistry. The key
TYPE:
|
Initialize SpawnSubAgentTool.
| PARAMETER | DESCRIPTION |
|---|---|
bot_manager
|
TYPE:
|
owner_id
|
Canonical owner ID of the parent agent.
TYPE:
|
allowed_tools
|
Parent-defined allowlist of tool names. Sub-agents may only use tools in this list. Empty list means no tools.
TYPE:
|
name
|
Tool name (default:
TYPE:
|
description
|
Override description for the LLM tool descriptor.
TYPE:
|
routing_meta
|
Optional routing hints. The
TYPE:
|
Source code in packages/ai-parrot/src/parrot/tools/spawn.py
SpawnSubAgentInput ¶
Bases: BaseModel
Input schema for SpawnSubAgentTool.
| ATTRIBUTE | DESCRIPTION |
|---|---|
task |
The question / task for the ephemeral sub-agent.
TYPE:
|
tools |
Allowed tool names for the sub-agent. Intersected with the
parent's
TYPE:
|
model |
LLM model override. Inherits parent default when not set.
TYPE:
|
system_prompt |
System prompt injected into the sub-agent.
TYPE:
|
timeout |
Max seconds the sub-agent is allowed to run before the call is cancelled. Defaults to 120 s.
TYPE:
|
ttl_seconds |
Ephemeral registry TTL. Keep short (default 300 s / 5 min) for sub-agents — they should be discarded well before this.
TYPE:
|
tool_schema ¶
Decorator to specify a custom argument schema for a toolkit method.
Usage
@tool_schema(MyCustomSchema) async def my_tool(self, arg1: str, arg2: int) -> str: '''My custom tool.''' return result
Source code in packages/ai-parrot/src/parrot/tools/decorators.py
tool ¶
tool(_func: Optional[Callable] = None, *, name: Optional[str] = None, description: Optional[str] = None, schema: Optional[Dict[str, Any]] = None, auto_register: bool = False, requires_confirmation: bool = False, confirm_template: Optional[str] = None, confirm_window_seconds: int = 0, allow_edit: bool = False, required_permissions: Optional[Set[str]] = None)
Decorator to mark a function as a tool with automatic schema generation.
Automatically extracts: - Name from function name (or use custom name) - Description from docstring (or use custom description) - Input schema from type hints (or use custom schema)
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Optional custom tool name (defaults to function name)
TYPE:
|
description
|
Optional custom description (defaults to docstring)
TYPE:
|
schema
|
Optional custom input schema (auto-generated from type hints if not provided)
TYPE:
|
auto_register
|
If True, automatically register with active client/bot
TYPE:
|
requires_confirmation
|
If True, the tool requires HITL confirmation before execution (via ConfirmationGuard in ToolManager — FEAT-235).
TYPE:
|
confirm_template
|
Optional Python format string for the briefing shown to the
human. Placeholders:
TYPE:
|
confirm_window_seconds
|
Seconds during which an identical call (same tool,
same args_hash) is skipped without re-asking.
TYPE:
|
allow_edit
|
When True, the human is offered a FORM interaction to edit the
parameter values before approving. Edited values are re-validated against
the tool's
TYPE:
|
required_permissions
|
Optional set of permission strings the caller's
TYPE:
|
Usage
@tool def get_weather(location: str) -> str: '''Get weather for a location.''' return f"Weather in {location}"
@tool() def get_weather(location: str) -> str: '''Get weather for a location.''' return f"Weather in {location}"
@tool(name="custom_name", description="Custom description") def my_function(param: int) -> str: return str(param)
@tool(requires_confirmation=True, confirm_template="Check in {employee_id}?", confirm_window_seconds=60, allow_edit=True) def workday_checkin(employee_id: int, time: str) -> str: '''Register a check-in.''' return "ok"
Source code in packages/ai-parrot/src/parrot/tools/decorators.py
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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |