xml-pipeline/xml_pipeline/message_bus/__init__.py
dullfig a623c534d5 Add Sequence and Buffer orchestration primitives
Implement two virtual node patterns for message flow orchestration:

- Sequence: Chains listeners in order (A→B→C), feeding each step's
  output as input to the next. Uses ephemeral listeners to intercept
  step results without modifying core pump behavior.

- Buffer: Fan-out to parallel worker threads with optional result
  collection. Supports fire-and-forget mode (collect=False) for
  non-blocking dispatch.

New files:
- sequence_registry.py / buffer_registry.py: State tracking
- sequence.py / buffer.py: Payloads and handlers
- test_sequence.py / test_buffer.py: 52 new tests

Pump additions:
- register_generic_listener(): Accept any payload type
- unregister_listener(): Cleanup ephemeral listeners
- Global singleton accessors for pump instance

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 14:56:15 -08:00

91 lines
2.1 KiB
Python

"""
message_bus — Stream-based message pump for AgentServer v2.1
The message pump handles message flow through the organism:
- YAML config → bootstrap → pump → handlers → responses → loop
Key classes:
StreamPump Main pump class (queue-backed, aiostream-powered)
SystemPipeline Entry point for external messages (console, webhook)
ConfigLoader Load organism.yaml and resolve imports
Listener Runtime listener with handler and routing info
MessageState Message flowing through pipeline steps
Usage:
from xml_pipeline.message_bus import StreamPump, SystemPipeline, bootstrap
pump = await bootstrap("config/organism.yaml")
system = SystemPipeline(pump)
# Inject from console
thread_id = await system.inject_console("@greeter Dan", user="admin")
await pump.run()
"""
from xml_pipeline.message_bus.stream_pump import (
StreamPump,
ConfigLoader,
Listener,
ListenerConfig,
OrganismConfig,
bootstrap,
get_stream_pump,
set_stream_pump,
reset_stream_pump,
)
from xml_pipeline.message_bus.message_state import (
MessageState,
HandlerMetadata,
)
from xml_pipeline.message_bus.system_pipeline import (
SystemPipeline,
ExternalMessage,
)
from xml_pipeline.message_bus.sequence_registry import (
SequenceState,
SequenceRegistry,
get_sequence_registry,
reset_sequence_registry,
)
from xml_pipeline.message_bus.buffer_registry import (
BufferState,
BufferItemResult,
BufferRegistry,
get_buffer_registry,
reset_buffer_registry,
)
__all__ = [
# Pump
"StreamPump",
"ConfigLoader",
"Listener",
"ListenerConfig",
"OrganismConfig",
"bootstrap",
"get_stream_pump",
"set_stream_pump",
"reset_stream_pump",
# Message state
"MessageState",
"HandlerMetadata",
# System pipeline
"SystemPipeline",
"ExternalMessage",
# Sequence registry
"SequenceState",
"SequenceRegistry",
"get_sequence_registry",
"reset_sequence_registry",
# Buffer registry
"BufferState",
"BufferItemResult",
"BufferRegistry",
"get_buffer_registry",
"reset_buffer_registry",
]