tools package
Extensible tool-calling framework.
Register tools with the @registry.tool decorator. Each tool is an async
callable that receives keyword arguments and returns a string result.
Example usage:
from tools import ToolRegistry
registry = ToolRegistry()
@registry.tool(
name="get_weather",
description="Get the current weather for a location.",
parameters={
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and state, e.g. 'San Francisco, CA'",
},
},
"required": ["location"],
},
)
async def get_weather(location: str) -> str:
return f"The weather in {location} is sunny and 72°F."
- class tools.ToolDefinition(name, description, parameters, handler, no_background=False, allow_repeat=False)[source]
Bases:
objectImmutable record describing one tool registered with the framework.
Holds everything
ToolRegistryneeds to expose a tool to the LLM and dispatch a call to it: the LLM-visiblenameanddescription, the JSON-Schemaparametersblock, the asynchandlercoroutine, and two behavioural flags.no_backgroundkeeps the call inline (the result is awaited directly instead of being handed toTaskManagerfor background execution), andallow_repeatexempts the tool from the executor’s repetition-loop guard. Instances are created byToolRegistry.tool()when a handler is decorated and are read back out by the schema-export and dispatch paths (ToolRegistry.call(),ToolRegistry.list_tools(),ToolRegistry.repeat_allowed_tools()).- Parameters:
name (
str) – Tool name as advertised to the model.description (
str) – Human-readable summary of what the tool does.parameters (
dict[str,Any]) – JSON Schema object describing the accepted arguments.handler (
Callable[...,Awaitable[str]]) – The async callable invoked to run the tool.no_background (
bool) – If true, never offload the call toTaskManager.allow_repeat (
bool) – If true, the tool is exempt from repetition detection.
- class tools.ToolRegistry(task_manager=None)[source]
Bases:
objectRegistry that stores tool definitions and executes tool calls.
A
threading.RLockserializes access to_toolsand tool caches sorun()and concurrentcall()/ OpenAI schema reads cannot race.- Parameters:
task_manager (TaskManager | None)
- __init__(task_manager=None)[source]
Initialize an empty registry, optionally bound to a
TaskManager.Sets up the internal tool table, the per-tool permission map, the
threading.RLockthat serializes every read and write, and the two lazily-populated caches of OpenAI-format schemas. The optional task_manager is stored so that non-nestedcall()invocations of background-eligible tools can be offloaded to it; when it isNoneevery call runs inline. A registry is constructed once per microservice worker (the inference and web services build one during startup) and then populated by the tool loader.- Parameters:
task_manager (
TaskManager|None) – TheTaskManagerused to run long tools in the background, orNoneto always run inline.- Return type:
None
- task_manager: TaskManager | None
- set_permissions(permissions)[source]
Set per-tool user whitelists.
permissions maps tool names to lists of allowed user IDs. A special value
"*"in the list means everyone. Tools not present in the dict are allowed for all users.
- is_allowed(tool_name, user_id)[source]
Return
Trueif user_id may execute tool_name.Rules: 1. Tool not in the permissions dict -> allow (backward compatible). 2.
"*"in the tool’s allowed list -> allow. 3. user_id in the tool’s allowed list -> allow. 4. Otherwise -> deny.
- async call(name, arguments, user_id='', ctx=None, *, nested=False)[source]
Execute a registered tool by name and return the result string.
If user_id is provided, the tool’s permission whitelist is checked first. If ctx is provided and the handler declares a
ctxparameter, the context is injected automatically.If nested is true, the coroutine is awaited directly (TaskManager is skipped) so compound tools receive concrete results instead of background
task_idenvelopes when inner calls exceed the timeout.If the tool raises an exception the error message is returned so the LLM can see what went wrong and recover.
- invalidate_cache()[source]
Clear the cached OpenAI tool representations.
Called automatically when tools are registered via the
tooldecorator. Must also be called explicitly after bulk mutations such as_tools.clear()(e.g. inreload_tools).- Return type:
- get_openai_tools()[source]
Return tool definitions in the OpenAI function-calling JSON format.
Returns an empty list when no tools are registered, which means the
toolsparameter can be omitted from the API call.
- get_openai_tools_by_names(names)[source]
Return only the OpenAI tool dicts whose names are in names.
Uses a cached
dictfor O(1) per-name lookup instead of rebuilding and filtering the full list each time.
- list_tools()[source]
Return a snapshot list of every registered
ToolDefinition.Takes the lock and copies the current values of
_toolsso callers can iterate the full set of tools (name, description, parameters and flags) without holding the lock or racing a reload. It backs a wide range of consumers across the repo – the tool-embedding indexer inclassifiers.update_tool_embeddingsandclassifiers.build_tool_index, the webtools_tasks_apilisting endpoint, the subagent tool filter intools/subagent_tools.py,tools/search_tools.pyand the write/import-tool flows – each of which then reads fields off the returned definitions.- Return type:
- Returns:
A new list of the registered tool definitions.
- tool_names()[source]
Return the set of all registered tool names as an immutable snapshot.
Reads the keys of
_toolsunder the lock and freezes them, giving a thread-safe, cheaply-comparable view of which tools currently exist. Used bymessage_processor.generate_and_sendto validate and gate tool selection (for example checking thatactivate_skillis present) and by the per-service tool-loading tests to assert a service finished registering its tools.
- repeat_allowed_tools()[source]
Return the names of tools exempt from repetition-loop detection.
Collects the names of every definition whose
allow_repeatflag is set, snapshotting them under the lock. The executor (openrouter_client.executor) reads this set so it can suppress its “the model keeps calling the same tool” guard for tools that are legitimately meant to be invoked repeatedly.
- property has_tools: bool
Return whether any tool is currently registered.
A cheap, lock-guarded predicate used to decide whether tool-calling is even possible. The transport layer (
openrouter_client.transport) checks it before attaching atoolsblock to an outbound request, and the per-service loading tests use it to confirm that the inference service registered tools while the web service did not.- Returns:
Trueif at least one tool is registered, elseFalse.
Subpackages
- tools.aws package
- Submodules
- tools.aws.base module
- tools.aws.cloudwatch module
- tools.aws.dynamodb module
- tools.aws.ec2 module
- tools.aws.ecr module
- tools.aws.ecs module
- tools.aws.elbv2 module
- tools.aws.helpers module
- tools.aws.iam module
- tools.aws.lambda_mod module
- tools.aws.logs_svc module
- tools.aws.rds module
- tools.aws.route53 module
- tools.aws.s3 module
- tools.aws.secretsmanager module
- tools.aws.sns module
- tools.aws.sqs module
- tools.aws.sts module
- Submodules
- tools.feature_atlas package
- Submodules
- tools.feature_atlas.atlas_connection module
- tools.feature_atlas.detect_code_interactions module
- tools.feature_atlas.discover_features module
- tools.feature_atlas.export_sarah_demo module
- tools.feature_atlas.extract_features_swarm module
- tools.feature_atlas.extract_repo_symbols module
- tools.feature_atlas.generate_interaction_prompts module
- tools.feature_atlas.import_interaction_analysis module
- tools.feature_atlas.load_features_to_falkor module
- tools.feature_atlas.query_atlas module
- tools.feature_atlas.run_atlas module
- tools.feature_atlas.run_interaction_analysis_swarm module
- Submodules
Submodules
- tools.activate_skill module
- tools.ad_dns_tools module
- tools.ad_gpo_tools module
- tools.adb_tools module
- tools.admin_whisper module
- tools.agpm_tools module
- tools.alter_privileges module
- tools.atlas_query_tool module
- tools.audio_edit module
- tools.auto_cover module
- tools.await_task module
- tools.aws_tools module
- tools.backup_tools module
- tools.bmc_vendor_tools module
run_bmc_redfish()run_idrac_racadm()run_smc_supermicro()bmc_redfish_save_credentials()bmc_redfish_list_credentials()bmc_redfish_delete_credentials()idrac_racadm_save_credentials()idrac_racadm_list_credentials()idrac_racadm_delete_credentials()smc_supermicro_save_credentials()smc_supermicro_list_credentials()smc_supermicro_delete_credentials()
- tools.bot_control module
- tools.brave_search module
- tools.btc_wallet_tools module
- tools.certbot_tools module
- tools.channel_summary_tools module
- tools.chat_analytics module
- tools.check_env module
- tools.check_task module
- tools.chromadb_tools module
- tools.cisa_kev_tools module
- tools.cisco_https_tools module
- tools.cloud_rag module
- tools.cloudflare_dns_tools module
- tools.comfyui_generate_image module
- tools.community_tools module
- tools.compellent_tools module
- tools.compose_gameboard module
- tools.compose_scene module
- tools.conjure_egregore module
- tools.connect_service module
- tools.constellation_graph module
- tools.context_window_tools module
- tools.create_character module
- tools.cross_channel_query module
- tools.cursor_tool module
- tools.data_viz module
- tools.debug_limbic_import module
- tools.debug_limbic_shard module
- tools.deep_think_tool module
- tools.dell_os10_tools module
- tools.desktop_tools module
- tools.discord_delete_message module
- tools.discord_edit_message module
- tools.discord_embed module
- tools.discord_invite module
- tools.discord_leave_server module
- tools.discord_manage_channels module
- tools.discord_manage_roles module
- tools.discord_message_reactions module
- tools.discord_moderation module
- tools.discord_poll module
- tools.discord_react module
- tools.discord_send_dm module
- tools.discord_server_emojis module
- tools.discord_server_info module
- tools.discord_upload_file module
- tools.discord_user_tools module
- tools.discord_voice_states module
- tools.discord_webhooks module
- tools.dismiss_egregore module
- tools.dm_history module
- tools.dns_tools module
- tools.docker_code_tool module
- tools.docker_tools module
- tools.donate_embed_key module
- tools.edit_image module
- tools.elevenlabs_music module
- tools.elevenlabs_sfx module
- tools.elevenlabs_tts module
- tools.elevenlabs_voice_design module
- tools.eth_wallet_tools module
- tools.etherpad_tools module
- tools.evm_decompiler module
- tools.exit_game module
- tools.extend_tool_loop module
- tools.file_download module
- tools.file_ops module
- tools.firewall_tools module
- tools.flavor_tool module
- tools.force_guild_index module
- tools.fortinet_tools module
- tools.game_asset_upload module
- tools.game_controls module
- tools.game_turn module
- tools.gandi_dns_tools module
- tools.gcp_tools module
- tools.gemini_tool module
- tools.generate_background module
- tools.generate_image module
- tools.generate_music module
- tools.generate_veo_video module
- tools.get_current_guild_count module
- tools.get_server_diagnostics module
- tools.git_repo_tools module
- tools.gitea_api module
- tools.gitea_integration module
- tools.gitea_tools module
gitea_list_repos()gitea_search_repos()gitea_get_repo()gitea_create_repo()gitea_list_issues()gitea_get_issue()gitea_create_issue()gitea_update_issue()gitea_list_pull_requests()gitea_get_pull_request()gitea_create_pull_request()gitea_merge_pull_request()gitea_get_file()gitea_list_commits()gitea_get_commit()gitea_list_notifications()gitea_star_repo()gitea_list_branches()gitea_create_repo_from_template()gitea_compare_commits()gitea_list_tags()gitea_create_tag()gitea_list_milestones()gitea_get_milestone()gitea_create_milestone()gitea_update_milestone()gitea_delete_milestone()gitea_list_labels()gitea_create_label()gitea_list_issue_comments()gitea_create_issue_comment()gitea_list_releases()gitea_get_release()gitea_create_release()gitea_delete_release()gitea_fork_repo()gitea_create_branch()gitea_delete_branch()gitea_list_wiki_pages()gitea_get_wiki_page()gitea_list_actions_tasks()gitea_list_pull_comments()
- tools.github_tools module
- tools.goal_tools module
- tools.google_oauth_tools module
- tools.gravimetric_telescope module
- tools.grok_imagine module
- tools.headless_browser module
HeadlessBrowserManagerHeadlessBrowserManager.default_context_idHeadlessBrowserManager.is_initializedHeadlessBrowserManager.last_usedHeadlessBrowserManager.usage_countHeadlessBrowserManager.error_countHeadlessBrowserManager.max_errors_before_restartHeadlessBrowserManager.idle_timeoutHeadlessBrowserManager._lockHeadlessBrowserManager.default_viewportHeadlessBrowserManager.default_user_agentHeadlessBrowserManager.__init__()HeadlessBrowserManager.initialize()HeadlessBrowserManager.ensure_ready()HeadlessBrowserManager.restart()HeadlessBrowserManager.cleanup()HeadlessBrowserManager.resolve_context_id()HeadlessBrowserManager.ensure_proxied_context()HeadlessBrowserManager.get_page()HeadlessBrowserManager.get_context()HeadlessBrowserManager.create_new_context()HeadlessBrowserManager.close_context()HeadlessBrowserManager.record_error()
browser_navigate()browser_go_back()browser_go_forward()browser_reload()browser_close_context()browser_click()browser_type()browser_fill()browser_fill_form()browser_select_option()browser_press_key()browser_hover()browser_scroll()browser_get_content()browser_get_text()browser_get_attribute()browser_get_page_info()browser_query_selector_all()browser_wait_for_selector()browser_wait_for_load_state()browser_wait_for_url()browser_wait()browser_screenshot()browser_pdf()browser_evaluate()browser_execute()browser_get_cookies()browser_set_cookies()browser_clear_cookies()browser_emulate_device()browser_set_geolocation()browser_set_viewport()browser_block_resources()browser_get_status()browser_restart()browser_new_context()browser_enable_response_interception()browser_wait_for_response()browser_get_intercepted_responses()browser_get_response_body()browser_clear_intercepted_responses()browser_create_persistent_context()browser_list_sessions()browser_delete_session()browser_wait_for_download()browser_get_downloads()browser_save_download()browser_get_console_logs()browser_clear_console_logs()browser_handle_dialog()browser_get_pending_dialog()
- tools.heartbeat_control module
- tools.hot_swap_game module
- tools.http_poster module
- tools.import_mcp_tool module
- tools.inject_ncm module
- tools.ipmi_tools module
- tools.ipsec_tools module
- tools.kafka_tools module
- tools.kanban_tools module
- tools.kg_anchoring_tools module
- tools.knowledge_graph module
- tools.kubernetes_tools module
- tools.librarian_tool module
- tools.lightning_tools module
- tools.limbic_chart module
- tools.linux_cgroup_ns_tools module
- tools.list_active_servers module
- tools.list_all_tools module
- tools.loopcast module
- tools.lyria_music module
- tools.manage_api_keys module
- tools.manage_secrets module
- tools.masscan_tools module
- tools.mcpo_proxy_tools module
- tools.meme_tool module
- tools.microsoft_tools module
- tools.minecraft_rcon_tool module
- tools.modify_self_json module
- tools.modulate_egregore_ncm module
- tools.monero_tools module
- tools.mongodb_tools module
- tools.music_steering module
- tools.mysql_tools module
- tools.ncm_reset module
- tools.nginx_tools module
- tools.nmap_tools module
- tools.notebook_tools module
- tools.object_storage_tools module
- tools.oci_tools module
- tools.openpgp_tools module
- tools.openvpn_tools module
- tools.parallax_telemetry module
- tools.parallax_tool module
- tools.pause_music module
- tools.pdf_generator module
- tools.persona_preferences module
- tools.pid_vpn_route_tools module
- tools.ping module
- tools.play_music module
- tools.pollinate module
- tools.pollinations_tts module
- tools.postgres_tools module
- tools.privilege_capsh module
- tools.proactive_controls module
- tools.proactive_relevance_tools module
- tools.proactive_triage_control module
- tools.prowlarr_search module
- tools.proxmox_tools module
- tools.psy_ops_tools module
- tools.qr_generator module
- tools.query_arxiv module
- tools.query_golden_goddess_v2 module
- tools.query_spiral_goddess module
- tools.rabbitmq_tools module
- tools.rag module
- tools.read_own_docs module
- tools.read_service_logs module
- tools.read_tool_code module
- tools.redirect_task module
- tools.redis_admin module
- tools.redis_tools module
- tools.refine_prompt module
- tools.reload_tools module
- tools.render_mermaid module
- tools.request_tool_injection module
- tools.research_tool module
- tools.reset_music_context module
- tools.resume_music module
- tools.retrieve_tool_call_log module
- tools.royal_bitch module
- tools.scheduled_prompt module
- tools.scour module
- tools.search_tools module
- tools.security_tools module
- tools.selfbot_relationships module
- tools.selfbot_server module
- tools.selfbot_settings module
- tools.sequential_thinking_tools module
- tools.set_conversation_choices module
- tools.set_sprite module
- tools.set_user_timezone module
- tools.set_witchborne_crown module
- tools.sftp_tools module
- tools.shell_tool module
- tools.short_term_notes module
- tools.socket_tools module
- tools.sonicwall_tools module
- tools.sovereign_petition module
- tools.sporestack_tools module
- tools.sqlite_tools module
- tools.ssh module
- tools.stargazer_ban module
- tools.stargazer_shadowban module
- tools.starwiki module
- tools.stl_generator module
- tools.stop_music module
- tools.stream_to_channel module
- tools.subagent_tools module
- tools.summon_egregore module
- tools.suno_music module
- tools.swarm_memory_search module
- tools.swarm_notify_platform module
- tools.swarm_state_tools module
- tools.tailscale_tools module
- tools.tenor_search module
- tools.terraform_tools module
- tools.threadweave_tools module
- tools.timebender_ritual module
- tools.tls_tools module
- tools.tool_vector_search module
- tools.tor_tools module
- tools.tor_transproxy_tools module
- tools.totp_tools module
- tools.traceroute_tools module
- tools.universal_decoder module
- tools.unsandboxed_exec_tool_names module
- tools.unsandboxed_python_tool module
- tools.user_sandbox_tools module
- tools.user_variables module
- tools.visual_memory_tools module
- tools.vmware_tools module
- tools.voice_clone module
- tools.vpn_tools module
- tools.vultr_tools module
- tools.wait_tool module
- tools.web_scraper module
- tools.winrm_tools module
- tools.wipe_game_data module
- tools.wolfram_alpha module
- tools.workflow_subagent_tools module
- tools.write_python_tool module
- tools.xenserver_tools module
- tools.xray_tool module
- tools.youtube_describe module
- tools.youtube_search module