RC RANDOM CHAOS

A working AI agent in 100 lines of Lisp, with eval as its only tool

· via Hacker News

Original source

An agent in 100 lines of Lisp

Hacker News →

A developer strips the AI agent down to its essence and finds it fits in roughly 100 lines of Common Lisp — SBCL plus two libraries (Dexador for HTTP, Shasht for JSON) talking to OpenRouter. The core insight is that an agent loop isn’t a framework, it’s a recursive function: send the message list to the model, and if the model wants a tool, run it, append the result, and recur; otherwise return the accumulated history. The agent’s entire state is just the argument folded through the recursion, no state machine required. Memory falls out just as cheaply — because the message list is already hash tables that serialize straight to JSON, persistence across sessions is a 20-line read-and-write of that list to a file, no vector store or schema needed.

The cleverest move is exploiting Lisp’s homoiconicity to hand the model a single tool: eval. Rather than bolting on a catalog of tools, the agent lets the model write Common Lisp forms as strings, reads and evaluates them, and returns whatever prints. Asked for the 30th Fibonacci number, the model writes and runs the function instead of recalling an answer. More strikingly, after being handed a Brave Search API key, the agent used eval to define a working brave-search function into the live image — writing the HTTP call and JSON parsing itself — effectively using its one tool to build a second one it was never given.

The piece doubles as a callback to Lisp’s origins as “the language for AI” in the symbolic-reasoning era: the old dream of programs that write programs is finally realized, except the symbolic reasoning is outsourced to a language model while Lisp supplies the substrate. The author is candid that eval-as-a-tool means running arbitrary model-generated code, so the whole thing is a sandbox toy confined to a local Docker container, and unbounded transcript memory will eventually blow the context window — a problem he suggests solving with a self-summarization step, an agent recursing over its own history.

Read the full article

Continue reading at Hacker News →

This is an AI-generated summary. Read the original for the full story.