tooluniverse.profile package

ToolUniverse Profile Configuration Management

This module provides tools for loading, validating, and managing ToolUniverse Profile configurations. Profile allows users to define collections of tools with specific configurations, LLM settings, and hooks for advanced scientific workflows.

Main Components: - ProfileLoader: Loads Profile configurations from various sources (HuggingFace, local files, URLs) - ProfileValidator: Validates Profile configurations using JSON Schema - ValidationError: Exception raised when configuration validation fails

Usage:

from tooluniverse.profile import ProfileLoader, validate_profile_config

# Load a Profile configuration loader = ProfileLoader() config = loader.load(“hf:user/repo”)

# Validate a configuration is_valid, errors = validate_profile_config(config)

class tooluniverse.profile.ProfileLoader[源代码]

基类:object

Simplified loader for ToolUniverse Profile configurations.

__init__(cache_dir=None)[源代码]

Initialize the Profile loader.

参数:

cache_dir (str | Path | None) – Directory for caching downloaded configurations

load(uri)[源代码]

Load Profile configuration from URI.

参数:

uri (str) – Profile URI (e.g., “hf:user/repo”, “./config.yaml”, “https://example.com/config.yaml”)

Returns

Loaded configuration dictionary

抛出:

ValueError – If URI is unsupported or configuration is invalid

resolve_to_local_dir(uri)[源代码]

Resolve any URI to a local directory that contains Profile tool files.

Supported URI forms: - Local path (file or directory): returned as a Path (file → parent) - hf:user/repo: full repo downloaded via snapshot_download - https://github.com/user/repo[/tree/branch]: zip downloaded & extracted - Other http(s):// URL: single file downloaded; its parent dir returned

The result is always a Path to an existing directory.

static get_tool_files_from_dir(dir_path)[源代码]

Scan dir_path for Python tool files and JSON config files.

Follows the same layout convention as _get_user_tool_files(): - Flat: *.py / *.json directly in the directory - Organised: tools/*.py and data/*.json / configs/*.json

profile.yaml / profile.json are excluded (handled separately). __init__.py is excluded (not a tool file).

返回:

(python_files, json_files) — both are lists of Path objects.

返回类型:

Tuple[List[Path], List[Path]]

tooluniverse.profile.validate_profile_config(config)[源代码]

Validate a Profile configuration using JSON Schema.

This is a legacy function that now uses the JSON Schema validation system. For new code, use validate_with_schema() instead.

参数:

config (Dict[str, Any]) – Configuration dictionary

返回:

Tuple of (is_valid, list_of_errors)

返回类型:

Tuple[bool, List[str]]

tooluniverse.profile.validate_with_schema(yaml_content, fill_defaults_flag=True)[源代码]

Validate YAML content using JSON Schema and optionally fill default values.

参数:
  • yaml_content (str) – YAML content string

  • fill_defaults_flag (bool) – Whether to fill default values

返回:

Tuple of (is_valid, list_of_errors, processed_config)

返回类型:

Tuple[bool, List[str], Dict[str, Any]]

tooluniverse.profile.validate_yaml_file_with_schema(file_path, fill_defaults_flag=True)[源代码]

Validate a YAML file using JSON Schema and optionally fill default values.

参数:
  • file_path (str) – Path to YAML file

  • fill_defaults_flag (bool) – Whether to fill default values

返回:

Tuple of (is_valid, list_of_errors, processed_config)

返回类型:

Tuple[bool, List[str], Dict[str, Any]]

tooluniverse.profile.validate_yaml_format_by_template(yaml_content)[源代码]

Validate YAML format by comparing against default template format.

This method uses the JSON Schema as a reference to validate the structure and content of Profile YAML configurations.

参数:

yaml_content (str) – YAML content string

返回:

Tuple of (is_valid, list_of_errors)

返回类型:

Tuple[bool, List[str]]

tooluniverse.profile.validate_yaml_file(file_path)[源代码]

Validate a YAML file by comparing against default template format.

参数:

file_path (str) – Path to YAML file

返回:

Tuple of (is_valid, list_of_errors)

返回类型:

Tuple[bool, List[str]]

tooluniverse.profile.fill_defaults(data, schema)[源代码]

Recursively fill default values from JSON schema.

参数:
  • data (Dict[str, Any]) – Configuration data

  • schema (Dict[str, Any]) – JSON schema with default values

返回:

Configuration with default values filled

返回类型:

Dict[str, Any]

exception tooluniverse.profile.ValidationError[源代码]

基类:Exception

Raised when configuration validation fails.

Submodules

tooluniverse.profile.loader module

ToolUniverse Profile Configuration Loader

Simplified loader supporting HuggingFace, local files, and HTTP/HTTPS.

class tooluniverse.profile.loader.ProfileLoader[源代码]

基类:object

Simplified loader for ToolUniverse Profile configurations.

__init__(cache_dir=None)[源代码]

Initialize the Profile loader.

参数:

cache_dir (str | Path | None) – Directory for caching downloaded configurations

load(uri)[源代码]

Load Profile configuration from URI.

参数:

uri (str) – Profile URI (e.g., “hf:user/repo”, “./config.yaml”, “https://example.com/config.yaml”)

Returns

Loaded configuration dictionary

抛出:

ValueError – If URI is unsupported or configuration is invalid

resolve_to_local_dir(uri)[源代码]

Resolve any URI to a local directory that contains Profile tool files.

Supported URI forms: - Local path (file or directory): returned as a Path (file → parent) - hf:user/repo: full repo downloaded via snapshot_download - https://github.com/user/repo[/tree/branch]: zip downloaded & extracted - Other http(s):// URL: single file downloaded; its parent dir returned

The result is always a Path to an existing directory.

static get_tool_files_from_dir(dir_path)[源代码]

Scan dir_path for Python tool files and JSON config files.

Follows the same layout convention as _get_user_tool_files(): - Flat: *.py / *.json directly in the directory - Organised: tools/*.py and data/*.json / configs/*.json

profile.yaml / profile.json are excluded (handled separately). __init__.py is excluded (not a tool file).

返回:

(python_files, json_files) — both are lists of Path objects.

返回类型:

Tuple[List[Path], List[Path]]

tooluniverse.profile.validator module

Profile Configuration Validator

Comprehensive validation for Profile configurations using JSON Schema. Supports validation, default value filling, and structure checking for Profile YAML files.

The validation system is based on a comprehensive JSON Schema that defines: - All possible fields and their types - Default values for optional fields - Required fields and validation rules - Enum values for specific fields - Nested object structures and arrays

This provides a robust, flexible, and maintainable validation system that can: 1. Validate YAML structure and content 2. Fill in missing default values automatically 3. Provide detailed error messages for validation failures 4. Support both simple tool collections and complex workspaces

exception tooluniverse.profile.validator.ValidationError[源代码]

基类:Exception

Raised when configuration validation fails.

tooluniverse.profile.validator.validate_profile_config(config)[源代码]

Validate a Profile configuration using JSON Schema.

This is a legacy function that now uses the JSON Schema validation system. For new code, use validate_with_schema() instead.

参数:

config (Dict[str, Any]) – Configuration dictionary

返回:

Tuple of (is_valid, list_of_errors)

返回类型:

Tuple[bool, List[str]]

tooluniverse.profile.validator.validate_yaml_format_by_template(yaml_content)[源代码]

Validate YAML format by comparing against default template format.

This method uses the JSON Schema as a reference to validate the structure and content of Profile YAML configurations.

参数:

yaml_content (str) – YAML content string

返回:

Tuple of (is_valid, list_of_errors)

返回类型:

Tuple[bool, List[str]]

tooluniverse.profile.validator.validate_yaml_file(file_path)[源代码]

Validate a YAML file by comparing against default template format.

参数:

file_path (str) – Path to YAML file

返回:

Tuple of (is_valid, list_of_errors)

返回类型:

Tuple[bool, List[str]]

tooluniverse.profile.validator.fill_defaults(data, schema)[源代码]

Recursively fill default values from JSON schema.

参数:
  • data (Dict[str, Any]) – Configuration data

  • schema (Dict[str, Any]) – JSON schema with default values

返回:

Configuration with default values filled

返回类型:

Dict[str, Any]

tooluniverse.profile.validator.validate_with_schema(yaml_content, fill_defaults_flag=True)[源代码]

Validate YAML content using JSON Schema and optionally fill default values.

参数:
  • yaml_content (str) – YAML content string

  • fill_defaults_flag (bool) – Whether to fill default values

返回:

Tuple of (is_valid, list_of_errors, processed_config)

返回类型:

Tuple[bool, List[str], Dict[str, Any]]

tooluniverse.profile.validator.validate_yaml_file_with_schema(file_path, fill_defaults_flag=True)[源代码]

Validate a YAML file using JSON Schema and optionally fill default values.

参数:
  • file_path (str) – Path to YAML file

  • fill_defaults_flag (bool) – Whether to fill default values

返回:

Tuple of (is_valid, list_of_errors, processed_config)

返回类型:

Tuple[bool, List[str], Dict[str, Any]]