HN
Today

An agent in 100 lines of Lisp

A developer revisits Lisp, his old AI professor's 'language for AI,' and discovers its homoiconicity makes it uniquely suited for modern AI agents. In just 100 lines, he builds an agent that can write its own tools and store its capabilities as memories, challenging current agent framework paradigms. This minimalist, recursive approach resonates deeply on HN by connecting Lisp's historical elegance with the cutting edge of LLM orchestration.

61
Score
4
Comments
#5
Highest Rank
13h
on Front Page
First Seen
Jul 12, 4:00 AM
Last Seen
Jul 12, 4:00 PM
Rank Over Time
1098677851013151622

The Lowdown

The author, reflecting on his AI course from 25 years ago where he learned Lisp, explores whether the language once championed for symbolic AI holds unexpected relevance for today's large language model (LLM) agents. Despite Lisp's perceived obsolescence in the wake of statistical and deep learning triumphs, he finds its core principles align remarkably with the functional requirements of modern AI agents.

  • Minimalist Agent Core: The fundamental agent loop is distilled into an 8-line recursive Common Lisp function. It processes messages, queries a model, and either returns the model's response or executes tools, demonstrating an elegant, state-free design where the agent's state is simply the folded argument of recursion.
  • Dynamic Tool Creation via Homoiconicity: Leveraging Lisp's homoiconicity (code as data), the agent is given a single lisp-eval tool. This allows the LLM to write and execute arbitrary Lisp code. The agent independently defines a fibonacci function and, remarkably, constructs its own brave-search function using this capability, demonstrating on-the-fly tool generation.
  • Memory as Serialization: Persistence is achieved with 20 lines of Lisp by directly writing the message history (JSON-like data) to a file. The agent's "skills" are not hardcoded but are re-hydrated from its own conversational history, meaning capabilities are stored and re-evaluated from past interactions.
  • Rethinking Agent Capabilities: This approach contrasts with typical agent frameworks where tools are designed and fixed at development time. Here, the agent dynamically decides what capabilities it needs, writes them into its runtime environment, and stores the memory of creating them, suggesting a more organic model for skill acquisition.

Ultimately, the author posits that while the symbolic AI Lisp was designed for might have been overshadowed, Lisp's foundational strengths in manipulating programs and data are perfectly suited for the "loop" surrounding today's powerful LLMs. His old professor, it seems, wasn't wrong, just 25 years early.