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.3.1.tar.gz (109.4 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.3.1-py3-none-any.whl (132.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fqg-0.3.1.tar.gz
  • Upload date:
  • Size: 109.4 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.3.1.tar.gz
Algorithm Hash digest
SHA256 6ff5fb4e976d013511ca279b07755b6ad3c626cdf27e60feef421a6eee352921
MD5 d2d501917da112fbdcea0dcc9757fbd1
BLAKE2b-256 678b04def8bf98d4e7e619dce60bab60c60b65e83cf31d7efaf7616f6c19e6d7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fqg-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 132.3 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d749af39cd76774270eeed88cbad3861f4716bf3ae026807b287a677f950bd8d
MD5 d077217160db43f7e5e5bbe51f812497
BLAKE2b-256 8e65cbe557ef02c75a2b897f87fbef1e643ff3a1689876afe5e3eec3c534f7d2

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