Function Quest Game - Training environment for Symphony Conductor
Project description
FQG - Function Quest Game
Reinforcement Learning Training Environment for Symphony Conductor
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
- Examples - 7 runnable Python scripts covering common use cases
- Tutorial Notebooks - Interactive Jupyter notebooks for learning
- Troubleshooting Guide - Solutions to common issues
Reference Documentation
- API Documentation - Complete API reference with examples
- Configuration Schema - YAML configuration reference
- Architecture Guide - System design and patterns
- Metrics System - Metrics collection and analysis
- Challenge Generation - AI-powered generation
๐๏ธ 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:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run quality checks (
ruff check . && mypy fqg && pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
- Documentation: docs/
- Examples: examples/
- Tutorials: notebooks/
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with โค๏ธ for the Symphony project
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cdff2b3e55a8c41dbd8fcc7269492231244e26583ac7f8a64d687692da365069
|
|
| MD5 |
19c6bcd73342dfe13791a858a70ff2e5
|
|
| BLAKE2b-256 |
dba38140c3599b918cf7ba7d15528dc759b762d3a8be8cd51af362e50810ecdb
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c253be0e8e28ab3c7c744ecf521e20c23266082bef81659e85e65a794a7edeaf
|
|
| MD5 |
796dfcb7e68b604030b5a8df8a17135c
|
|
| BLAKE2b-256 |
8e2b9d9837c7d89d32452fc8c78ef0c4cfb4c9e6f3e04a97dc3d4a6d1997265d
|