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
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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
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
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 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 | |
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
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
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 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 | |
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 |
|---|---|
Optional[AbstractTool]
|
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
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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
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)
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)
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:
|
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
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 156 157 158 159 160 | |