Skip to content

tobiasosborne/polyceph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

96 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

polyceph

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.

Features

🧬 Multi-Headed Architecture

  • 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

πŸ› οΈ Dynamic Tool System

  • Self-Modification: Agent creates its own tools at runtime
  • Tool Persistence: Custom tools saved across sessions
  • Safe Evaluation: Sandboxed code execution with security guarantees

πŸ’° Cost Optimization

  • 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

🎯 Clean, Modular Design

  • 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

Quick Start

# Install
lein deps

# Run tests
lein test

# Start interactive session
lein repl

# Chat with polyceph
polyceph=> (chat "Hello! What can you help me with?")

Example Usage

;; 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..."))

Architecture

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          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

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

Development

Quick Setup

# 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

Development Workflow

  1. Write tests first, then implement
  2. Keep files small (<200 lines)
  3. Commit after each step

Why "polyceph"?

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

Contributing

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.

Philosophy

"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

License

MIT License - see LICENSE for details

Acknowledgments

  • 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

About

multi-headed intelligence for modern AI - a clojure agent system with dynamic tools and llm delegation

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors