Async trampolines for composing agent loops via mutual recursion.
pip install trampolinesfrom trampolines import trampoline
async def coder(task):
code = await call_llm(f"Write: {task}")
return tester(code)
async def tester(code):
result = await call_llm(f"Test: {code}")
if result.passed:
return code
return coder(result.failures)
final = await trampoline(coder("implement quicksort"))python -m trampolines run examples/adversarial_code_review.py- adversarial_code_review.py -- Two agents in the same HUD environment. One writes code, the other tries to break it. They bounce infinitely until the reviewer says LGTM.
The async analog of the trampoline pattern.
Since async generators can't return values (PEP 525), we use plain async def
coroutines instead. The return value's type is the signal:
- Coroutine returned -- bounce (the trampoline awaits it)
- Non-coroutine returned -- done (the trampoline returns it)
Runs indefinitely by default. Use timeout (seconds) or max_bounces as safety valves.