Page cover

Agents System

background logic that actually does the dirty work for you. brainz ships with a built-in agent layer—watchdogs that sit between your prompts, memory, and training pipeline. they watch, score, rewrite, and fine-tune without you lifting a finger.

agents live here: backend/agents/

run them inline with inference or fire them off async in the background.


what they do

  • hook directly into the llm lifecycle

  • log every action (if you want it)

  • fully scriptable + chainable

  • can be swapped, extended, or rewritten in minutes


brain flow (high level)

new prompt → score it  
│  
├── good → push to vector memory  
└── trash → autotrainer fires → feedbackloop grabs session → promptoptimizer rewrites → fine-tune queued → memory updated → system evolves  

the longer it runs, the smarter it gets.


autotrainer

the muscle. auto-corrects the brain when it screws up.

  • hooks into /api/llm/query

  • scores output via utils/eval_metrics.py

  • if score < threshold → logs prompt → triggers models/trainer.py live fine-tune → tags metadata for later digging

tweak it in core/config.py: DEFAULT_AUTO_TRAIN_THRESHOLD = 10

no cronjobs, no manual scripts. it literally teaches itself.


feedbackloop

the paranoia module. doesn’t trust a single answer, watches for failure patterns:

  • long response delays

  • repeated edits or retries

  • same topic spammed over & over

if it smells “low confidence”: → embeds prompt → dumps it into vector memory → queues retraining → tags it for prompt rewrite


promptoptimizer

rewrites garbage prompts before they hit the model.

what it does:

  • splits overstuffed queries

  • cleans slang + weird abbreviations

  • reshapes the question into llm-friendly structure

  • keeps intent, boosts clarity

example: "wtf is mev?" → "explain mev (maximal extractable value) in ethereum"

under the hood: zero-shot scoring + regex hacks + semantic distance checks.


full live loop

user: "wtf is zk-snarks vs starks?" model: weak answer autotrainer: flags score < threshold feedbackloop: logs session promptoptimizer: rewrites to "compare zk-snarks and zk-starks in zero-knowledge cryptography" training: queued instantly memory: updated with new vector

→ you didn’t do anything. it just got smarter.


build your own agent

drop a file in backend/agents/:

class MyAgent:
    def run(self, prompt: str, response: str) -> dict:
        return {"action": "log", "priority": "medium"}

register it:

registry.register("my-agent", MyAgent())

agents can:

  • write logs

  • trigger webhooks

  • mess with memory

  • chain other agents

  • queue training jobs

async, stackable, schedulable. your rules.


why it matters

agents = hands-free evolution.

  • the more you use it → the better it gets

  • no manual fine-tuning

  • sloppy prompts cleaned up automatically

  • output stabilizes over time

  • the system runs itself, degen-style

Last updated