tooluniverse.space package

ToolUniverse Space Configuration Management

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

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

Usage:

from tooluniverse.space import SpaceLoader, validate_space_config

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

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

class tooluniverse.space.SpaceLoader[source]

Bases: object

Simplified loader for ToolUniverse Space configurations.

__init__(cache_dir=None)[source]

Initialize the Space loader.

Parameters:

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

load(uri)[source]

Load Space configuration from URI.

Parameters:

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

Returns

Loaded configuration dictionary

Raises:

ValueError – If URI is unsupported or configuration is invalid

tooluniverse.space.validate_space_config(config)[source]

Validate a Space 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.

Parameters:

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

Returns:

Tuple of (is_valid, list_of_errors)

Return type:

Tuple[bool, List[str]]

tooluniverse.space.validate_with_schema(yaml_content, fill_defaults_flag=True)[source]

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

Parameters:
  • yaml_content (str) – YAML content string

  • fill_defaults_flag (bool) – Whether to fill default values

Returns:

Tuple of (is_valid, list_of_errors, processed_config)

Return type:

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

tooluniverse.space.validate_yaml_file_with_schema(file_path, fill_defaults_flag=True)[source]

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

Parameters:
  • file_path (str) – Path to YAML file

  • fill_defaults_flag (bool) – Whether to fill default values

Returns:

Tuple of (is_valid, list_of_errors, processed_config)

Return type:

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

tooluniverse.space.validate_yaml_format_by_template(yaml_content)[source]

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 Space YAML configurations.

Parameters:

yaml_content (str) – YAML content string

Returns:

Tuple of (is_valid, list_of_errors)

Return type:

Tuple[bool, List[str]]

tooluniverse.space.validate_yaml_file(file_path)[source]

Validate a YAML file by comparing against default template format.

Parameters:

file_path (str) – Path to YAML file

Returns:

Tuple of (is_valid, list_of_errors)

Return type:

Tuple[bool, List[str]]

tooluniverse.space.fill_defaults(data, schema)[source]

Recursively fill default values from JSON schema.

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

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

Returns:

Configuration with default values filled

Return type:

Dict[str, Any]

exception tooluniverse.space.ValidationError[source]

Bases: Exception

Raised when configuration validation fails.

Submodules

tooluniverse.space.loader module

ToolUniverse Space Configuration Loader

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

class tooluniverse.space.loader.SpaceLoader[source]

Bases: object

Simplified loader for ToolUniverse Space configurations.

__init__(cache_dir=None)[source]

Initialize the Space loader.

Parameters:

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

load(uri)[source]

Load Space configuration from URI.

Parameters:

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

Returns

Loaded configuration dictionary

Raises:

ValueError – If URI is unsupported or configuration is invalid

tooluniverse.space.validator module

Space Configuration Validator

Comprehensive validation for Space configurations using JSON Schema. Supports validation, default value filling, and structure checking for Space 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.space.validator.ValidationError[source]

Bases: Exception

Raised when configuration validation fails.

tooluniverse.space.validator.validate_space_config(config)[source]

Validate a Space 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.

Parameters:

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

Returns:

Tuple of (is_valid, list_of_errors)

Return type:

Tuple[bool, List[str]]

tooluniverse.space.validator.validate_yaml_format_by_template(yaml_content)[source]

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 Space YAML configurations.

Parameters:

yaml_content (str) – YAML content string

Returns:

Tuple of (is_valid, list_of_errors)

Return type:

Tuple[bool, List[str]]

tooluniverse.space.validator.validate_yaml_file(file_path)[source]

Validate a YAML file by comparing against default template format.

Parameters:

file_path (str) – Path to YAML file

Returns:

Tuple of (is_valid, list_of_errors)

Return type:

Tuple[bool, List[str]]

tooluniverse.space.validator.fill_defaults(data, schema)[source]

Recursively fill default values from JSON schema.

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

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

Returns:

Configuration with default values filled

Return type:

Dict[str, Any]

tooluniverse.space.validator.validate_with_schema(yaml_content, fill_defaults_flag=True)[source]

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

Parameters:
  • yaml_content (str) – YAML content string

  • fill_defaults_flag (bool) – Whether to fill default values

Returns:

Tuple of (is_valid, list_of_errors, processed_config)

Return type:

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

tooluniverse.space.validator.validate_yaml_file_with_schema(file_path, fill_defaults_flag=True)[source]

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

Parameters:
  • file_path (str) – Path to YAML file

  • fill_defaults_flag (bool) – Whether to fill default values

Returns:

Tuple of (is_valid, list_of_errors, processed_config)

Return type:

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