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.
The Core Workflow
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.
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.
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.