Implementation:Volcengine Verl Initialize Tools From Config
| Field | Value |
|---|---|
| Knowledge Sources | verl source code, tool registry module |
| Domains | Tool Configuration, Plugin Initialization |
| Last Updated | 2026-02-07 |
Overview
Description
initialize_tools_from_config is a factory function that reads a YAML configuration file and returns a list of fully initialized BaseTool instances. It supports two tool types: NATIVE (in-process Python tools) and MCP (Model Context Protocol remote tools). For native tools, the function dynamically imports the tool class, optionally validates an OpenAI-compatible tool schema, and instantiates the tool. For MCP tools, a temporary asyncio event loop is created to connect to MCP servers, fetch tool schemas, and construct tool instances. The event loop is properly cleaned up after initialization to prevent memory leaks.
This function is the central entry point used by the multi-turn rollout infrastructure to bootstrap all available tools before any agent loop begins execution.
Usage
Call this function at system startup, typically from within ToolAgentLoop.__init__, passing the path to a YAML configuration file that describes the tools to load. The returned list is then indexed by tool name to build a dispatch map.
Code Reference
| Field | Value |
|---|---|
| Source Location | verl/tools/utils/tool_registry.py, Lines 82-142
|
| Signature | def initialize_tools_from_config(tools_config_file) -> list
|
| Import | from verl.tools.utils.tool_registry import initialize_tools_from_config
|
I/O Contract
Inputs
| Parameter | Type | Description |
|---|---|---|
tools_config_file |
str |
File path to a YAML configuration file defining the tools to initialize. |
The YAML file must follow this structure:
tools:
- class_name: "verl.tools.gsm8k_tool.Gsm8kTool"
config:
type: "native"
tool_schema:
type: "function"
function:
name: "calculate"
description: "Evaluate a math expression"
parameters:
type: "object"
properties:
expression:
type: "string"
description: "The math expression to evaluate"
required:
- "expression"
- class_name: "verl.tools.mcp_tool.McpTool"
config:
type: "mcp"
rate_limit: 10
mcp:
mcp_servers_config_path: "/path/to/mcp_servers.json"
tool_selected_list:
- "search"
- "browse"
Outputs
| Return | Type | Description |
|---|---|---|
| tool_list | list[BaseTool] |
A list of fully initialized tool instances, each carrying an OpenAIFunctionToolSchema attribute suitable for inclusion in chat-completion API calls.
|
Usage Examples
Basic initialization from a YAML config file:
from verl.tools.utils.tool_registry import initialize_tools_from_config
# Load and initialize all tools defined in the config
tool_list = initialize_tools_from_config("configs/tools/gsm8k_tools.yaml")
# Build a name-to-tool dispatch map
tools = {tool.name: tool for tool in tool_list}
# Extract OpenAI-compatible schemas for the chat completion API
tool_schemas = [
tool.tool_schema.model_dump(exclude_unset=True, exclude_none=True)
for tool in tool_list
]
print(f"Loaded {len(tool_list)} tools: {list(tools.keys())}")
Usage within ToolAgentLoop initialization:
# Inside ToolAgentLoop.__init__
tool_config_path = config.actor_rollout_ref.rollout.multi_turn.tool_config_path
tool_list = initialize_tools_from_config(tool_config_path) if tool_config_path else []
self.tools = {tool.name: tool for tool in tool_list}
self.tool_schemas = [
tool.tool_schema.model_dump(exclude_unset=True, exclude_none=True)
for tool in tool_list
]