MatrixSwarm agents don’t hardcode their behavior. Instead, they inject it at runtime using factories
.
This allows agents to be reused, reprogrammed, and rewired without rewriting the class — making logic deployment modular, like loading ammo.
🧩 What is a Factory?
A factory is a Python module with an attach(agent, config)
function.
threading.Thread(target=reflex_loop, daemon=True, name="agent_reflex").start()
The agent loads this during boot using the resolve_factory_injections()
hook built into BootAgent
.
🔧 Declaring Factories
Factories are defined in the swarm tree:
"config": {
"role": "alert_listener",
"factories": {
"alert.subscriber": {
"levels": ["critical", "warning"],
"chat_id": "...",
"bot_token": "..."
}
}
}
This will load:
agent/your_agent/factory/alert/subscriber/__init__.py
When Matrix spawns the agent, it will automatically call:
import agent.your_agent.factory.alert.subscriber
subscriber.attach(agent, config["factories"]["alert.subscriber"])
📡 Why it Matters
- Hot-swappable logic with no restarts
- One agent class, infinite behaviors
- Perfect for relays, listeners, responders, even AI stacks
Factory injection makes MatrixSwarm modular. You don’t build new agents. You train them to behave differently — live.