Lisp Agents: Recursion, Homoiconicity, and the 100-Line Agent Loop
An engineer rediscovers Lisp's power for AI agents, building a recursive agent loop in 100 lines where the model writes its own tools via eval.

A developer recently revisited Lisp after 25 years, prompted by a university AI course that preached Lisp as the language for symbolic AI. The result: a minimal AI agent loop in 100 lines of Common Lisp, using recursion instead of a while loop, and leveraging Lisp's homoiconicity to let the model write its own tools at runtime.
The core agent loop is an 8-line recursive function. It sends a message list to a model, checks for tool calls, executes them, and recurs with the enriched history. No framework, no state machine—just recursion folding state through arguments.
One tool to rule them all
Instead of building a catalog of tools (web search, file I/O, Python execution), the author gave the agent a single tool: eval. Because Lisp is homoiconic—code and data share the same structure—the model can write arbitrary Lisp forms as strings, which the agent reads, evaluates, and returns the result. The model used this to compute Fibonacci recursively, define a brave-search function on the fly, and even parse JSON responses from the Brave Search API—all without any pre-built tooling.
This inverts the typical agent design pattern. Instead of a fixed tool catalog decided at design time, the agent decides what it needs at runtime, writes it in Lisp, and evals it into existence. Capabilities become conversational artifacts.
Memory as serialization
Persistence is handled by serializing the message list (already a list of hash tables, essentially JSON) to disk and reading it back. No schema, no migrations, no vector database. The agent recalls its history, recurs, and remembers. The author notes this grows unbounded—context windows will eventually hit limits—but suggests a compression step where the agent summarizes its own past, recursing on its own history.
The experiment also reveals a fascinating property: skills are memories. The brave-search function lives only in the running Lisp image. When the process exits, the function disappears. But the transcript persists. In a fresh session, the agent re-reads its history and evals the function back into being. Its capabilities are literally stories it tells itself.
The author acknowledges the security caveat: eval as a tool means arbitrary code execution. This is a toy for sandboxed environments only. But as a demonstration of Lisp's enduring relevance for AI agents, it's a compelling one.
Discussion
0 Comments
Be the first to start the discussion.