An agent in 100 lines of Lisp
TL;DR Highlight
Giving a 100-line Lisp agent only eval, it wrote its own search tool
Who Should Read
Backend developers using LLM APIs who are rethinking agent loops and fixed tool catalogs
Core Mechanics
- An agent is one recursive function
- Send messages to the model, run any tool calls, append results, and call again.
- With no tool calls, return the history and stop.
- The post writes this loop in 8 lines of Common Lisp.
- The whole agent is about 100 lines
- Built with Claude's help against OpenRouter.
- Uses SBCL and just two libraries: dexador for HTTP and shasht for JSON.
- The only tool is eval
- The model writes a Common Lisp form as a string, and the agent evals it and returns the output.
- Asked for the 30th Fibonacci number, it defined a function, called it, and got 832040.
- The author warns that this runs arbitrary code on your machine, so it's a sandbox toy.
- Memory is 20 lines of JSON save and load
- Messages are already hash tables, so they can be written and read back as JSON.
- The entry point is recall, run the loop, then remember.
- The author notes that unbounded transcripts will eventually hit the context window.
- The agent built a second tool itself
- After a Brave Search API key was pasted into the chat, it used eval to define a brave-search function.
- The author never built a search tool.
- Skills are memories in the transcript
- Functions vanish when the process exits, but their source stays in memory.json.
- In a new session, the agent has to re-read its history and eval the function back.
Community Reactions
- Pushback that eval matters more than Lisp
- One commenter says JS, Python, and Ruby also have eval.
- They say it's rarely used because of security, not capability.
- Question on how this differs from a bash or python -c tool
- One commenter says eval extends the harness process itself, unlike out-of-process scripts.
- They add that it's powerful but dangerous and only for sandboxes.
- Experience writing the same loop in 9 lines of Python
- A commenter shared code with one shell tool and a while loop, giving the same structure.
- Opinion that Claude Code's tools aren't fixed
- One commenter says Claude Code regularly generates new code and you can promote it to skills or workflows.
- Warning that it's like skipping all permissions
- A commenter compares it to always running with --dangerously-skip-permissions.
- Another shared that elisp can be sandboxed by allowing only pure functions by default.
How to Apply
- Shrink your agent loop to a recursive form
- Strip your current agent code down to send, run tool calls, and append results.
- Check that the stop condition for no tool calls lives in one place.
- Add memory by saving and loading message JSON
- Read messages from a file at session start and write them back at the end.
- Run without a vector DB first, and add a summarize step only once context overflows.
- Open code-execution tools only in a sandbox
- Enable any tool that lets the model run code only inside isolation such as local Docker.
- Keep a fixed, permission-limited tool list in production.
Try It
# Paste into Claude Code (simplified version of the post's method: the eval-tool agent ported to Python, sandbox experiment)
Create agent.py in a new empty folder. Requirements:
1. Call model {{model name}} via the OpenRouter chat completions API.
2. Provide exactly one tool, run_python. The model gives a code string, you run it and return stdout.
3. Write the agent loop as a recursive function: return the message list if there are no tool calls, otherwise append results and call again.
4. Save the message list to memory.json and load it at startup.
5. Put a warning in the first line of README that this is dangerous code to run only inside Docker.
Then test it with "What is the 30th Fibonacci number? Compute it, don't recall it."Terminology
Related Papers
Frostbite: A new CPU architecture discovered, designed and verified by AI
AI agents designed a CPU from scratch, claiming 4.59x perf/W over a traditional core
Restricting AI agents in mobile operating systems platforms from capturing data
Signal now blocks OS-level AI agents from reading its screen on iOS 27 and Android
Actions Speak Louder than Words: Stateful Privacy Sniffing of LLM Agents via Behavioral Covert Channels in Web Interactions
Agents' link choices alone let attackers rebuild user queries at F1 0.89; SOR cuts it to 0.39.
Tracking and Limiting Unsupported Claim Propagation in Multi-Agent LLM Systems: A Provenance-Aware Framework
Passing claims with source, evidence and history kept equivalence at 5 agent stages at 96% versus 31%.
LLM assisted reverse engineering
Pointing an agent at binaries with skills and MD notes made years-long hacks feasible
Metrics-in-the-Loop: Complexity Feedback Reshapes Agent-Written Code
Injecting per-turn complexity reports into coding agents cut code erosion without changing correctness
Why is Gemini 4 Carbon taking so long?
Carbon took nearly an hour on bug fixes that Astra and Opus finished in minutes, mostly from extra unrequested work.
Weight-Space Programming builds neural networks like a 1990s researcher
LLM hand-wrote MNIST weights to 91.3%, using 1990s-style techniques