← portfolio  /  ML Optimizer
AI · LLM

LLM Powered Optimizer agent.

An autonomous agent that optimizes C code by automatically generating plans, modifying source, benchmarking against a baseline, and fixing its own errors via LLM feedback.

Optimization Loop

The Core Workflow

1. Extract HW & Baseline
2. LLM Generates JSON Plan
3. Apply Optimization
4. Check Safety & Compile
5. Benchmark & Diff Validation
↑ Fails? LLM Fix Prompt

Hardware and Baseline

The agent queries the system to extract hardware capabilities like cpu_count, avx2, and fma. It sets compiler flags and benchmarks the unoptimized C code to establish a strict ground truth for time and expected output.

Plan Generation

The LLM receives the hardware context, baseline source, and an optimization taxonomy. It analyzes hot loops and outputs a JSON plan ordering the most impactful optimizations.

Prompting and Tools

Groq and LLMs

The agent relies on fast Groq LLMs for high speed during iterations. It automatically cycles through models on HTTP rate limits and maintains a local Ollama fallback.

Strict Constraints

The system enforces strict rules during code generation to prevent arbitrary logic changes. Constants must remain identical, print formats cannot change, and function signatures must be preserved.

Safety

Execution Safety

Because the agent automatically compiles and executes LLM generated code, safety is critical. The is_safe_c() tool runs a regex blocklist against dangerous system calls.

If the LLM generates blocked commands, the code is rejected before compilation, ensuring malicious operations are never executed.