Implements an observer pattern where agents can register watchers for conditions on their thread. When the condition is met, the agent gets "nagged" on subsequent invocations until it explicitly closes the todo. Key components: - TodoRegistry: thread-scoped watcher tracking with eyebrow state - TodoUntil/TodoComplete payloads and system handlers - HandlerMetadata.todo_nudge for delivering raised eyebrow notices - Integration in StreamPump dispatch to check and nudge Greeter now demonstrates the pattern: 1. Registers watcher for ShoutedResponse from shouter 2. On next invocation, sees nudge and closes completed todos 3. Includes nudge in LLM prompt for awareness Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
77 lines
2 KiB
Python
77 lines
2 KiB
Python
"""
|
|
boot.py — System boot primitive.
|
|
|
|
The <boot> message is the first message in every organism's lifetime.
|
|
It establishes the root thread from which all other threads descend.
|
|
|
|
The boot handler:
|
|
1. Logs organism startup
|
|
2. Initializes any system-level state
|
|
3. Sends initial ConsolePrompt to start the console REPL
|
|
|
|
All external messages that arrive without a known thread parent
|
|
will be registered as children of the boot thread.
|
|
"""
|
|
|
|
from dataclasses import dataclass
|
|
import logging
|
|
|
|
from third_party.xmlable import xmlify
|
|
from agentserver.message_bus.message_state import HandlerMetadata, HandlerResponse
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@xmlify
|
|
@dataclass
|
|
class Boot:
|
|
"""
|
|
System boot message — first message in organism lifetime.
|
|
|
|
Injected automatically at startup. Establishes root thread context.
|
|
"""
|
|
organism_name: str = ""
|
|
timestamp: str = ""
|
|
listener_count: int = 0
|
|
|
|
|
|
@xmlify
|
|
@dataclass
|
|
class ConsolePrompt:
|
|
"""
|
|
Prompt message to the console.
|
|
|
|
Duplicated here to avoid circular import with handlers.console.
|
|
The pump will route based on payload class name.
|
|
"""
|
|
output: str = ""
|
|
source: str = ""
|
|
show_banner: bool = False
|
|
|
|
|
|
async def handle_boot(payload: Boot, metadata: HandlerMetadata) -> HandlerResponse:
|
|
"""
|
|
Handle the system boot message.
|
|
|
|
Logs the boot event and sends initial ConsolePrompt to start the REPL.
|
|
"""
|
|
logger.info(
|
|
f"Organism '{payload.organism_name}' booted at {payload.timestamp} "
|
|
f"with {payload.listener_count} listeners. "
|
|
f"Root thread: {metadata.thread_id}"
|
|
)
|
|
|
|
# Could initialize system state here:
|
|
# - Warm up LLM connections
|
|
# - Load cached schemas
|
|
# - Pre-populate routing caches
|
|
|
|
# Send initial prompt to console to start the REPL
|
|
return HandlerResponse(
|
|
payload=ConsolePrompt(
|
|
output=f"Organism '{payload.organism_name}' ready.\n{payload.listener_count} listeners registered.",
|
|
source="system",
|
|
show_banner=True,
|
|
),
|
|
to="console",
|
|
)
|