Agentic Diffusion is an advanced diffusion-based generative framework that enables code generation and agentic planning through self-evolving models. The system utilizes denoising diffusion probabilistic models as its core generative mechanism, with specific adaptations for code generation and planning.
- Diffusion-based Generation: State-of-the-art denoising diffusion probabilistic models for high-quality generation
- Hybrid LLM + Diffusion Approach: Combines the strengths of Large Language Models with diffusion models for superior code generation
- Quality Improvements: Achieves 15-20% quality improvements over standard diffusion-only approaches
- Self-Optimization: Recursive improvement through reward-guided generation and adaptation
- Code Generation: Specialized diffusion models for syntax-aware code generation across multiple programming languages
- Multi-Domain Support: Extensible architecture supporting multiple domains and models
- High Test Coverage: Comprehensive test suite maintaining 90% code coverage
- Python 3.8+
- Git
This project uses UV, a fast pip-compatible installer for Python written in Rust. The installation script will automatically install UV if it's not already available.
# Clone the repository
git clone https://github.com/agentic-diffusion/agentic_diffusion.git
cd agentic_diffusion
# Run the installation script
python install.py
# For a development installation (including dev dependencies)
python install.py --dev --editable
# To install in a virtual environment
python install.py --venvIf you prefer a manual installation:
# Clone the repository
git clone https://github.com/agentic-diffusion/agentic_diffusion.git
cd agentic_diffusion
# Create and activate a virtual environment (optional but recommended)
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Install the package in development mode
pip install -e .agentic_diffusion/
├── core/ # Core diffusion model components
├── adaptation/ # Adaptation mechanisms
├── code_generation/ # Code generation components
│ ├── hybrid_llm_diffusion_generator.py # Hybrid LLM + diffusion generator
├── planning/ # Planning components
├── api/ # API interfaces
│ ├── hybrid_llm_diffusion_api.py # API for hybrid approach
├── infrastructure/ # Infrastructure components
├── testing/ # Testing utilities
├── examples/ # Usage examples
└── tests/ # Test suite
├── unit/ # Unit tests
├── integration/ # Integration tests
└── system/ # System tests
from agentic_diffusion.api.code_generation_api import CodeGenerationAPI
# Initialize the API
api = CodeGenerationAPI()
# Generate Python code
code, metadata = api.generate_code(
specification="Create a function to calculate the Fibonacci sequence",
language="python"
)
print(code)from agentic_diffusion.api.hybrid_llm_diffusion_api import create_hybrid_llm_diffusion_api
# Configure the hybrid approach
config = {
"llm_provider": "openai", # or "anthropic", etc.
"llm_model": "gpt-4",
"refinement_iterations": 3,
"temperature": 0.7
}
# Initialize the API
api = create_hybrid_llm_diffusion_api(config)
# Generate Python code with the hybrid approach
code, metadata = api.generate_code(
specification="Create a function to calculate the Fibonacci sequence",
language="python"
)
print(code)
# Print quality improvement percentage
print(f"Quality improvement: {metadata['quality']['quality_improvement_percentage']:.2f}%")# Generate code using standard diffusion approach
python -m agentic_diffusion generate "Create a function to calculate the Fibonacci sequence" -l python
# Generate code using hybrid LLM + diffusion approach
python -m agentic_diffusion generate "Create a function to calculate the Fibonacci sequence" -l python --approach hybrid
# Customize the hybrid approach parameters
python -m agentic_diffusion generate "Create a function to calculate the Fibonacci sequence" \
-l python \
--approach hybrid \
--llm-provider openai \
--llm-model gpt-4 \
--refinement-iterations 5 \
--temperature 0.5
# Run benchmarks comparing both approaches
python -m agentic_diffusion benchmark --approaches both --output-dir benchmark_resultsfrom agentic_diffusion.api.adaptation_api import AdaptationAPI
# Initialize the API
api = AdaptationAPI()
# Define a task
task_id = api.define_task(
task_description="Generate efficient sorting algorithms",
examples=[
{"prompt": "Sort an array", "code": "def quicksort(arr): ..."}
]
)
# Adapt a model to the task
adaptation_id = api.adapt_model(
model_id="code-model-v1",
task_id=task_id
)
# Check adaptation status
status = api.get_adaptation_status(adaptation_id)
print(f"Adaptation status: {status}")We use pytest for testing and maintain a test coverage of at least 90%.
# Run the full test suite with coverage
pytest
# Run only unit tests
pytest agentic_diffusion/tests/unit
# Run tests for a specific module
pytest agentic_diffusion/tests/unit/core
# Run tests specifically for the hybrid approach
pytest agentic_diffusion/tests/unit/code_generation/test_hybrid_llm_diffusion_generator.py
# Run tests and generate a coverage report
pytest --cov=agentic_diffusion --cov-report=html- Implement the component in the appropriate module
- Add comprehensive unit tests (aim for 90%+ coverage)
- Update relevant APIs if needed
- Add examples demonstrating the new functionality
Our hybrid approach combines the strengths of Large Language Models (LLMs) and diffusion models:
-
Initial Draft Generation: An LLM (like GPT-4 or Claude) generates an initial code draft based on the specification, leveraging its strong understanding of code structure and patterns.
-
Diffusion Refinement: The diffusion model then iteratively refines the code, improving correctness, optimizing patterns, and fixing potential issues.
-
Quality Metrics: The system measures improvements across various metrics, showing consistent 15-20% quality improvements over diffusion-only approaches.
This approach combines the understanding capabilities of LLMs with the refinement strengths of diffusion models, creating a pipeline that produces higher quality code than either approach alone.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- The AdaptDiffuser research that inspired this project
- All contributors who have helped shape and improve this framework