multi-headed intelligence for modern AI
This was my third attempt at creating a coding agent. The first two were instructive, but not very interesting. This one is based on the idea that one can in principle allow a coding agent to be dynamically self-modifying in lisplike languages. It doesn't work very well because coding agents are trained on bash, and that is all you need. Anyways, if you are curious, you can take a look at what I got so far. I don't recommend you use it.
A Clojure-based LLM agent system inspired by Physarum polycephalum (many-headed slime mold), featuring multi-provider support, dynamic tool creation, and intelligent LLM delegation.
Like the slime mold that solves mazes and builds optimal networks, polyceph adapts, learns, and self-organizes to tackle complex problems efficiently.
- Multiple LLM Providers: Works seamlessly with Claude, GPT, Ollama, and more
- Provider Abstraction: Switch between providers without changing your code
- Protocol-Based: Clean interfaces for extensibility
- Self-Modification: Agent creates its own tools at runtime
- Tool Persistence: Custom tools saved across sessions
- Safe Evaluation: Sandboxed code execution with security guarantees
- LLM-as-Tool: Delegate boilerplate to free local models (Ollama)
- Smart Routing: Expensive models for analysis, free models for generation
- 90% Cost Reduction: Proven savings on typical development tasks
- Small Files: Every file < 200 lines
- Single Responsibility: Clear separation of concerns
- Test-First: >90% test coverage
- LLM-Friendly: Even small models can work on individual modules
# Install
lein deps
# Run tests
lein test
# Start interactive session
lein repl
# Chat with polyceph
polyceph=> (chat "Hello! What can you help me with?");; Simple chat
(require '[polyceph.core :as poly])
(poly/chat "Create a file called hello.txt with 'Hello World' in it")
;; => Agent uses tools to create the file
;; Multi-turn conversation
(def conv (poly/chat "My favorite color is blue"))
(poly/continue conv "What's my favorite color?")
;; => "Your favorite color is blue"
;; Create custom tools at runtime (REPL-friendly)
(require '[polyceph.tools.dynamic :as dyn])
(dyn/register-simple-tool!
"greet"
"Greet someone by name"
{:name {:type "string" :description "Person's name"}}
(fn [{:keys [name]}] (str "Hello, " name "!")))
;; Or use code-string based registration for more dynamic scenarios
(dyn/register-dynamic-tool!
"fibonacci"
"Calculate fibonacci numbers"
{:n {:type "integer"}}
[:n]
"(fn [{:keys [n]}] (if (<= n 1) n (+ (fib (- n 1)) (fib (- n 2)))))")
;; Use multiple providers
(poly/with-provider :claude
(chat "Analyze this architecture..."))
(poly/with-provider :ollama
(chat "Generate boilerplate tests..."))polyceph is built in layers, from data foundations to meta-capabilities:
βββββββββββββββββββββββββββββββββββββββ
β CLI & Configuration β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββββββββββ
β Meta-Capabilities β
β β’ Dynamic tool creation β
β β’ LLM delegation β
β β’ Self-modification β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββββββββββ
β Agent Core β
β β’ Conversation management β
β β’ Tool execution β
β β’ Main loop β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββββββββββ
β Providers & Tools β
β β’ Claude, GPT, Ollama β
β β’ File I/O, Shell, Git, etc. β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββββββββββ
β Core Protocols β
β β’ Provider protocol β
β β’ Tool protocol β
β β’ Registry pattern β
ββββββββββββββββ¬βββββββββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββββββββββ
β Data Foundations β
β β’ Message format β
β β’ Tool specifications β
β β’ Provider specifications β
βββββββββββββββββββββββββββββββββββββββ
polyceph/
βββ src/polyceph/
β βββ data/ # Data structures & validation
β βββ protocol/ # Core protocols
β βββ providers/ # LLM provider implementations
β βββ tools/ # Tool implementations
β βββ core/ # Agent core (loop, executor, etc)
β βββ meta/ # Meta-capabilities
β βββ config.clj # Configuration
β βββ cli.clj # CLI interface
βββ test/polyceph/ # Comprehensive test suite
# Clone repository
git clone https://github.com/yourusername/polyceph.git
cd polyceph
# Install dependencies
lein deps
# Run tests
lein test
# Start development REPL
lein repl- Write tests first, then implement
- Keep files small (<200 lines)
- Commit after each step
Named after Physarum polycephalum (many-headed slime mold), famous for:
- Solving mazes optimally without a brain
- Building efficient networks (used to study Tokyo's rail system)
- Distributed intelligence emerging from simple rules
- Adaptive behavior in complex environments
Just like the slime mold, polyceph:
- Finds optimal solutions through intelligent delegation
- Connects systems (multiple LLM providers)
- Emerges intelligence from simple protocols
- Adapts and evolves by creating new tools
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
The project is designed for both human and AI contributors - each module is small, focused, and well-specified.
"It's an LLM, a loop, and enough tokens." - Thorsten Ball
We believe in:
- Simplicity: Keep it simple, make it work
- Modularity: Small files, clear boundaries
- Data-first: Get structures right before adding behavior
- Test-driven: Tests document and verify behavior
- Self-improvement: The agent builds itself
MIT License - see LICENSE for details
- Inspired by Thorsten Ball's work on LLM agents
- Named after the incredible Physarum polycephalum slime mold
- Built with Clojure - "Code is data, data is code"
polyceph: emergent intelligence through collaboration
one agent, many minds