Skip to main content

Function Quest Game - Training environment for Symphony Conductor

Project description

FQG - Function Quest Game

Reinforcement Learning Training Environment for Symphony Conductor

Python 3.11+ License: MIT Tests Type Checked

FQG is a TorchRL-based training environment that simulates extension orchestration challenges with known scoring rubrics. It trains AI models (like Symphony Conductor) to make intelligent orchestration decisions through narrative-based challenges.

โœจ Features

  • ๐ŸŽฏ Narrative-Based Challenges - Story-driven orchestration problems with clear goals
  • ๐Ÿ“Š Ground Truth Validation - Known optimal paths for training validation
  • ๐Ÿ“ˆ Comprehensive Metrics - Detailed tracking of training progress
  • ๐Ÿ”ง Hierarchical Configuration - Flexible YAML-based configuration system
  • ๐Ÿค– AI-Powered Generation - Create challenges from natural language descriptions
  • ๐Ÿš€ TorchRL Integration - Standard RL environment interface
  • ๐Ÿ’พ Lazy Loading - Memory-efficient generator-based collections
  • ๐ŸŽ“ Progressive Difficulty - Curriculum learning with level progression

๐Ÿ“ฆ Installation

Quick Start (uv - recommended)

# Install uv if not already installed
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install FQG
cd fqg
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv pip install -e ".[dev]"

Using pip

cd fqg
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
pip install -e ".[dev]"

Verify Installation

python -c "from fqg import FQG; print('โœ“ FQG installed successfully!')"

๐Ÿš€ Quick Start

Basic Usage

from fqg import FQG

# Initialize FQG
fqg = FQG(tier_name="vivace", metrics_enabled=True)

# Get a level
level = fqg.level(1)

# Get a challenge
challenge = level.challenges().get(1)

# Run an episode
tensordict = challenge.reset()
done = False

while not done:
    # Your policy selects action
    action = select_action(tensordict)
    tensordict['action'] = action
    
    # Step environment
    tensordict = challenge.step(tensordict)
    done = tensordict['done'].item()

# View metrics
metrics = fqg.metrics()
summary = metrics.summary(tier_name="vivace")
print(f"Success rate: {summary['success_rate']:.2%}")

Configuration Overrides

# Override YAML configuration with constructor parameters
fqg = FQG(
    tier_name="vivace",
    max_steps=30,           # Override max steps per episode
    step_penalty=-0.02,     # Override step penalty
    eval_fraction=0.20      # Override evaluation set fraction
)

Filtering and Sampling

# Filter challenges
easy_challenges = level.challenges().filter(complexity="easy")
household = level.challenges().filter(tags=["household"])

# Sample challenges
sampled = level.challenges().sample(n=5, strategy="uniform", seed=42)

# Chain operations
easy_household = level.challenges().filter(complexity="easy").filter(tags=["household"])

๐Ÿ“š Documentation

Getting Started

Reference Documentation

๐Ÿ—๏ธ Project Structure

fqg/
โ”œโ”€โ”€ __init__.py              # Public API exports
โ”œโ”€โ”€ core/                    # Core infrastructure
โ”‚   โ”œโ”€โ”€ base.py              # FQGConfigBase, FQGError
โ”‚   โ”œโ”€โ”€ fqg.py               # FQG main entry point
โ”‚   โ”œโ”€โ”€ loader.py            # ConfigLoader
โ”‚   โ””โ”€โ”€ yaml_utils.py        # YAML parsing utilities
โ”œโ”€โ”€ global_config/           # Global configuration module
โ”œโ”€โ”€ tier/                    # Tier configuration module
โ”œโ”€โ”€ level_collection/        # Level collection module
โ”œโ”€โ”€ level/                   # Level module
โ”œโ”€โ”€ challenge/               # Challenge module (TorchRL environment)
โ”œโ”€โ”€ extension/               # Extension manifest module
โ”œโ”€โ”€ path/                    # Path configuration module
โ”œโ”€โ”€ quality/                 # Quality/scoring module
โ”œโ”€โ”€ execution/               # Extension execution module
โ”œโ”€โ”€ scoring/                 # Reward computation module
โ”œโ”€โ”€ state/                   # Episode state management
โ”œโ”€โ”€ metrics/                 # Metrics collection and analysis
โ””โ”€โ”€ generation/              # AI-powered challenge generation

tests/
โ”œโ”€โ”€ unit/                    # Unit tests (80% of tests)
โ”œโ”€โ”€ integration/             # Integration tests (15%)
โ””โ”€โ”€ acceptance/              # End-to-end tests (5%)

examples/                    # Runnable usage examples
notebooks/                   # Interactive tutorials
docs/                        # Complete documentation

๐Ÿ”ง Configuration

FQG uses a five-level hierarchical configuration system:

Global Config (.fqg/config.yaml)
  โ†“
Tier Config (.fqg/game/<tier_name>/config.yaml)
  โ†“
Levels Collection Config (.fqg/game/<tier_name>/levels/config.yaml)
  โ†“
Level Config (.fqg/game/<tier_name>/levels/level1/config.yaml)
  โ†“
Challenge Config (.fqg/game/<tier_name>/levels/level1/challenge1.yaml)
  โ†“
Constructor Parameters (highest priority)

Priority Order: Constructor > Challenge > Level > Collection > Tier > Global

See Configuration Schema for complete reference.

๐Ÿงช Development

Run Tests

# All tests
pytest

# With coverage
pytest --cov=fqg --cov-report=html

# Specific test file
pytest tests/unit/core/test_fqg.py

# Specific test
pytest tests/unit/core/test_fqg.py::test_fqg_initialization

Type Checking

mypy fqg

Linting and Formatting

# Check linting
ruff check .

# Fix linting issues
ruff check --fix .

# Format code
ruff format .

# Check formatting
ruff format --check .

All Quality Checks

# Run all checks at once
ruff check . && ruff format --check . && mypy fqg && pytest

Code Complexity

# Check complexity with radon
radon cc fqg -a -nb

# Check complexity with lizard
lizard fqg

๐Ÿ“Š Metrics

FQG automatically collects comprehensive metrics:

# Enable metrics
fqg = FQG(tier_name="vivace", metrics_enabled=True)

# Run training...

# Query metrics
metrics = fqg.metrics()

# Get recent episodes
episodes = metrics.episodes(tier_name="vivace", level_index=1, limit=100)

# Get summary statistics
summary = metrics.summary(tier_name="vivace")
print(f"Total episodes: {summary['total_episodes']}")
print(f"Success rate: {summary['success_rate']:.2%}")
print(f"Average reward: {summary['avg_reward']:.2f}")

# Get path distribution
path_dist = metrics.path_distribution(tier_name="vivace", level_index=1)

Metrics are stored in SQLite (.fqg/metrics.db) for persistence and analysis.

๐Ÿค– Challenge Generation

Generate challenges from natural language descriptions:

from fqg.generation import FQGGenerator

# Initialize generator
generator = FQGGenerator(model="deepseek-r1")

# Generate challenge
challenge_config = generator.generate(
    description="User wants to send an email with attachment",
    domain="enterprise",
    complexity="medium",
    noise_ratio=0.2
)

# Save to YAML
challenge_config.save(".fqg/game/vivace/levels/level1/email_challenge.yaml")

๐ŸŽฏ Use Cases

Training RL Agents

for episode in range(10000):
    challenge = sample_challenge()
    state = challenge.reset()
    
    while not done:
        action = agent.select_action(state)
        state, reward, done, info = challenge.step(action)
    
    agent.update(episode_data)

Curriculum Learning

current_level = 1
while current_level <= max_levels:
    success_rate = train_on_level(current_level)
    
    if success_rate > 0.70:  # 70% success threshold
        current_level += 1

Challenge Design

# Create custom challenges
generator = FQGGenerator()
challenge = generator.generate(
    description="Your custom scenario",
    domain="your_domain",
    complexity="medium"
)

๐Ÿค Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run quality checks (ruff check . && mypy fqg && pytest)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Development Guidelines

  • Follow existing code style (enforced by ruff)
  • Add type hints to all functions
  • Write tests for new features
  • Update documentation
  • Keep commits focused and atomic

๐Ÿ“ˆ Project Status

  • โœ… Phase 0-11: Complete (589 tests passing)
  • ๐Ÿšง Phase 12: Documentation & Polish (in progress)
  • ๐Ÿ“Š Test Coverage: 80%+
  • ๐ŸŽฏ Type Coverage: 100% (mypy strict mode)
  • ๐Ÿ“ Documentation: Comprehensive

๐Ÿ› Troubleshooting

Common issues and solutions:

Import Error

# Reinstall in development mode
pip install -e .

Configuration Error

# Verify .fqg directory structure
ls -la .fqg/game/vivace/levels/level1/

Metrics Database Locked

# Close other FQG instances or delete database
rm .fqg/metrics.db

See Troubleshooting Guide for more solutions.

๐Ÿ“„ License

MIT License - see LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built with TorchRL for RL environment interface
  • Uses Pydantic for configuration validation
  • Inspired by OpenAI Gym and Gymnasium

๐Ÿ“ž Support


Made with โค๏ธ for the Symphony project

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fqg-0.1.0.tar.gz (71.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fqg-0.1.0-py3-none-any.whl (91.2 kB view details)

Uploaded Python 3

File details

Details for the file fqg-0.1.0.tar.gz.

File metadata

  • Download URL: fqg-0.1.0.tar.gz
  • Upload date:
  • Size: 71.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for fqg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cdff2b3e55a8c41dbd8fcc7269492231244e26583ac7f8a64d687692da365069
MD5 19c6bcd73342dfe13791a858a70ff2e5
BLAKE2b-256 dba38140c3599b918cf7ba7d15528dc759b762d3a8be8cd51af362e50810ecdb

See more details on using hashes here.

File details

Details for the file fqg-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fqg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 91.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for fqg-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c253be0e8e28ab3c7c744ecf521e20c23266082bef81659e85e65a794a7edeaf
MD5 796dfcb7e68b604030b5a8df8a17135c
BLAKE2b-256 8e2b9d9837c7d89d32452fc8c78ef0c4cfb4c9e6f3e04a97dc3d4a6d1997265d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page