xml-pipeline/run_organism.py
dullfig a5e2ab22da Add thread registry, LLM router, console handler, and docs updates
Thread Registry:
- Root thread initialization at boot
- Thread chain tracking for message flow
- register_thread() for external message UUIDs

LLM Router:
- Multi-backend support with failover strategy
- Token bucket rate limiting per backend
- Async completion API with retries

Console Handler:
- Message-driven REPL (not separate async loop)
- ConsolePrompt/ConsoleInput payloads
- Handler returns None to disconnect

Boot System:
- System primitives module
- Boot message injected at startup
- Initializes root thread context

Documentation:
- Updated v2.1 docs for new architecture
- LLM router documentation
- Gap analysis cross-check

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 16:53:38 -08:00

59 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""
run_organism.py — Start the organism.
Usage:
python run_organism.py [config.yaml]
This boots the organism and runs the message pump.
The console is a regular handler in the message flow:
boot -> system.boot -> console (await input) -> console-router -> ... -> console
The pump continues until the console returns None (EOF or /quit).
"""
import asyncio
import sys
from pathlib import Path
from agentserver.message_bus import bootstrap
async def run_organism(config_path: str = "config/organism.yaml"):
"""Boot organism and run the message pump."""
# Bootstrap the pump (registers listeners, injects boot message)
pump = await bootstrap(config_path)
# Set pump reference for console introspection commands
from handlers.console import set_pump_ref
set_pump_ref(pump)
# Run the pump - it will process boot -> console -> ... flow
# The pump runs until shutdown is called
try:
await pump.run()
except asyncio.CancelledError:
pass
finally:
await pump.shutdown()
print("Goodbye!")
def main():
config_path = sys.argv[1] if len(sys.argv) > 1 else "config/organism.yaml"
if not Path(config_path).exists():
print(f"Config not found: {config_path}")
sys.exit(1)
try:
asyncio.run(run_organism(config_path))
except KeyboardInterrupt:
print("\nInterrupted")
if __name__ == "__main__":
main()