Skip to content

Latest commit

 

History

History
190 lines (140 loc) · 6.2 KB

File metadata and controls

190 lines (140 loc) · 6.2 KB

Configuration Inheritance

Complexity: 🟢 Beginner

This example demonstrates how to use YAML configuration inheritance in the NeMo Agent Toolkit to reduce duplication across similar configuration files.

Table of Contents


Key Features

  • Reduce Configuration Duplication: Define common settings once in a base configuration and reuse across multiple variants
  • Selective Overrides: Override specific values at any nesting level while inheriting all other settings
  • Multi-Level Inheritance: Chain multiple configuration files together for progressive customization
  • Flexible File Organization: Reference base configurations using relative or absolute paths

How It Works

Base Configuration

The base config (base-config.yml) contains all common settings:

general:
  telemetry:
    logging:
      console:
        level: INFO

llms:
  nim_llm:
    model_name: meta/llama-3.1-70b-instruct
    temperature: 0.0
    max_tokens: 1024

workflow:
  _type: react_agent
  tool_names: [calculator, current_datetime]
  llm_name: nim_llm
  verbose: true

Variant Configuration

Each variant specifies the base and overrides only what's different:

# config-high-temp.yml
base: base-config.yml

llms:
  nim_llm:
    temperature: 0.9  # Override just this one value

The result is a fully merged configuration with:

  • temperature: 0.9 (overridden)
  • All other settings inherited from base

Chained Inheritance

You can create multi-level inheritance chains where variant configurations inherit from other variants, allowing progressive customization. For example:

# base-config.yml
llms:
  nim_llm:
    temperature: 0.0
general:
  telemetry:
    logging:
      console:
        level: INFO
# config-high-temp.yml
base: base-config.yml
llms:
  nim_llm:
    temperature: 0.9
# config-high-temp-debug.yml
base: config-high-temp.yml  # Inherits from variant, not base
general:
  telemetry:
    logging:
      console:
        level: DEBUG

Result for config-high-temp-debug.yml:

  • temperature: 0.9 (from config-high-temp.yml)
  • console.level: DEBUG (from config-high-temp-debug.yml)
  • All other settings inherited from base-config.yml

Configuration files can also reference base configurations in other directories using either relative or absolute paths.


Installation and Setup

If you have not already done so, follow the instructions in the Install Guide to create the development environment and install the NeMo Agent Toolkit.

Install Dependent Workflow

This example relies on the calculator function group part of the simple_calculator example.

From the root directory of the NeMo Agent Toolkit library, run the following commands:

uv pip install -e examples/getting_started/simple_calculator

Set Up API Keys

If you have not already done so, follow the Obtaining API Keys instructions to obtain an NVIDIA API key. You need to set your NVIDIA API key as an environment variable to access NVIDIA AI services:

export NVIDIA_API_KEY=<YOUR_API_KEY>

Run Workflows with Variant Configurations

This example shows a simple calculator workflow with several configuration variants:

  • base-config.yml - Base configuration with common settings
  • config-high-temp.yml - Variant with higher temperature for creative responses
  • config-debug.yml - Variant with verbose logging for debugging
  • config-different-model.yml - Variant using a different LLM model
  • config-with-tracing.yml - Variant with Weave tracing enabled
  • config-high-temp-debug.yml - Chained inheritance example (base → high-temp → high-temp-debug)

From the root directory of the NeMo Agent Toolkit library, run the workflow with different configuration variants:

# Test basic inheritance
nat run --config_file examples/config_inheritance/configs/config-high-temp.yml --input "What is 25 * 4?"

# Test chained inheritance
nat run --config_file examples/config_inheritance/configs/config-high-temp-debug.yml --input "What is 25 * 4?"

# Compare with debug variant
nat run --config_file examples/config_inheritance/configs/config-debug.yml --input "What is 25 * 4?"

Use Cases

Configuration inheritance is particularly useful for:

  • Environment-specific configurations: Create separate variants for development, staging, and production environments
  • Evaluation configurations: Define different evaluation scenarios while maintaining consistent base workflow settings
  • Model experiments: Test different hyperparameters while keeping the workflow structure unchanged
  • LLM provider variations: Switch between different LLM backends without duplicating configuration
  • Feature toggles: Enable or disable features through small configuration overrides
  • Team member configurations: Allow team members to overlay personal preferences on shared defaults
  • Progressive customization: Start with a base configuration and incrementally add features