1
1
Fork
You've already forked monkey-brain
0
Deterministic memory and logic reasoning for AI agents.
  • Go 100%
2026年04月17日 00:51:26 +01:00
internal/api dedupe 2026年04月16日 23:22:05 +01:00
skill change link 2026年04月17日 00:51:26 +01:00
.gitignore git ignore 2026年04月16日 23:13:05 +01:00
go.mod full impl 2026年04月16日 23:12:25 +01:00
go.sum full impl 2026年04月16日 23:12:25 +01:00
LICENSE initial commit 2026年04月16日 22:43:41 +01:00
main.go full impl 2026年04月16日 23:12:25 +01:00
README.md readme 2026年04月16日 23:26:09 +01:00

monkey-brain

Small Go microservice for deterministic memory and logic reasoning using Prolog-style triples.

What it does

  • Stores facts as triple(subject, relation, target)
  • Supports rule-based inference (Horn clauses)
  • Exposes HTTP endpoints on http://localhost:7777
  • Keeps in-memory Lamport-style temporal metadata for incremental updates

Endpoints

  • POST /learn - assert facts (array of triples)
  • POST /forget - retract facts (single triple pattern)
  • POST /pattern - define inference rules
  • POST /ask - query facts/rules with limit + offset

/ask responses are deduped before pagination.

Run

go run .

Server listens on:

http://localhost:7777

Quick example

Learn facts:

curl -X POST http://localhost:7777/learn \
 -H "Content-Type: application/json" \
 -d '[
 {"subject":"alice","relation":"parent","target":"bob"},
 {"subject":"bob","relation":"parent","target":"carol"}
 ]'

Define rules:

curl -X POST http://localhost:7777/pattern \
 -H "Content-Type: application/json" \
 -d '{
 "name":"ancestor_base",
 "conditions":[{"subject":"?A","relation":"parent","target":"?B"}],
 "infers":{"subject":"?A","relation":"ancestor","target":"?B"}
 }'
curl -X POST http://localhost:7777/pattern \
 -H "Content-Type: application/json" \
 -d '{
 "name":"ancestor_recursive",
 "conditions":[
 {"subject":"?A","relation":"parent","target":"?B"},
 {"subject":"?B","relation":"ancestor","target":"?C"}
 ],
 "infers":{"subject":"?A","relation":"ancestor","target":"?C"}
 }'

Ask:

curl -X POST http://localhost:7777/ask \
 -H "Content-Type: application/json" \
 -d '{"query":{"subject":"alice","relation":"ancestor","target":"?X"},"limit":50,"offset":0}'