agentic-compiler
Runtime-adaptive compilation for Python. Automatically profiles hot functions, compiles them to optimized backends (Numba, Rust, CUDA), and hot-swaps them at runtime — no human intervention required.
The Pitch
You write plain Python. The compiler watches. After 100+ calls it notices your function is slow, compiles it with Numba, verifies the output is identical, measures the speedup, and silently replaces the slow version — all while your program is still running. If the compiled version is ever wrong, it rolls back in one call.
Installation
pip install agentic-compiler
With Numba support (recommended):
pip install agentic-compiler[numba]
Quickstart
from agentic_compiler import Compiler
import numpy as np
compiler = Compiler()
compiler.install() # monkey-patch all hot paths
# Your normal code — the compiler is watching
def slow_sum(arr):
total = 0.0
for i in range(len(arr)):
total += arr[i] * arr[i]
return total
# Run it enough times to trigger compilation
for _ in range(200):
slow_sum(np.random.randn(1000))
# The compiler will auto-compile and hot-swap if speedup > 2x
print(compiler.profiler.report())
Decorator-style profiling
from agentic_compiler import Profiler
profiler = Profiler(sample_rate=0.05)
@profiler.watch
def my_hot_function(x):
return np.sum(x ** 2)
Manual hot-swap
from agentic_compiler import Compiler
compiler = Compiler()
result = compiler.hot_swap(my_slow_function)
print(f"Speedup: {result.speedup:.1f}x, Validated: {result.validated}")
# Rollback if something goes wrong
compiler.restore()
One-shot compilation
from agentic_compiler import ast_to_numba
kernel = ast_to_numba(my_function)
if kernel.ready:
print(f"Compiled to {kernel.backend} in {kernel.compile_time_ms:.1f}ms")
Grid-Aware Backend Selection
The GridBackendSelector automatically picks the right backend based on workload size:
| Workload Size | Backend | Why |
|---|---|---|
| n < 50 | numpy | ctypes overhead dominates |
| 50–500 | rust_oneshot | medium arrays |
| 500+ | rust_persistent | zero-copy, weights in Rust |
| 1000+ (GPU available) | cuda | maximum parallelism |
from agentic_compiler import GridBackendSelector
backend = GridBackendSelector.select(n_rooms=750)
print(GridBackendSelector.report())
API Reference
Compiler
install(module_name=None)— monkey-patch functions for profilinguninstall()— restore originalscompile_hotspots(top_n=5)— auto-compile top-N hot functionscompile_function(func, module, attr_name)— manual compile + swaphot_swap(func, module, attr_name, backend)— compile + swap in one callrestore(key=None)— rollback to original function
Profiler
watch(func)— decorator to profile a functionget_hotspots(top_n=10)— ranked list by optimization potentialreport()— human-readable profiling summary
CodeGenerator
compile(func)— compile to best available backendvalidate(kernel, original, test_args)— A/B test for correctnessmeasure_speedup(kernel, original, test_args)— benchmark speedupdeploy(kernel, module, attr_name)— hot-swap into module
GeneratedKernel
ready— bool, True if compilation succeededcompiled— the compiled callablebackend— "numba", "rust", or "python"compile_time_ms— how long compilation tookspeedup— measured speedup vs original
Architecture
Profiler → Analyzer → CodeGenerator → Validator → Deployer
(watch) (rank) (compile) (A/B test) (hot-swap)
- Profiler samples 5% of calls, tracks timing and input shapes
- Analyzer scores functions for Numba vs Rust suitability via AST
- CodeGenerator compiles to best backend, with fallback to identity
- Validator runs A/B tests to verify correctness
- Deployer hot-swaps if speedup exceeds 2× threshold
Testing
pip install -e ".[numba]"
pytest
Tests cover profiler instrumentation, backend selection, hot-swap correctness, and Numba integration (mocked when unavailable).
Related Repos
- forgemaster — Forge orchestration (uses agentic compilation for swarm deliberation)
- cocapn-plato — Fleet PLATO integration
- tensor-spline — Compressed neural network layers
License
MIT
Metadata
Release files for agentic-compiler 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| agentic_compiler-0.1.0.tar.gz | 18.9 kB | Without provenance | Details for agentic_compiler-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agentic_compiler-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for agentic_compiler-0.1.0-py3-none-any.whl |
Total release size: 34.9 kB
Release files / agentic_compiler-0.1.0.tar.gz
| Download URL | agentic_compiler-0.1.0.tar.gz |
|---|---|
| Size | 18.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
425a2000e1a4e119570b35b461bbacd2d218d08f893f98489219986162e77556
|
|
BLAKE2b-256 checksum How to use checksums |
de541f492ad3f9f5b6a601a65e6276a8a5a75bfa2588f881e96ffa9b6dd59829
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Release files / agentic_compiler-0.1.0-py3-none-any.whl
| Download URL | agentic_compiler-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72f3a00edcfff614ddb19b025a0948218168e0fc1983dd4d9d927130e0380cdf
|
|
BLAKE2b-256 checksum How to use checksums |
4799bc81e03c70e785f6b81dca6c90cfc7d98ba3c8f659a55860198da2b28f1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Security for agentic-compiler 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.