gunn.facades package¶
Submodules¶
gunn.facades.message module¶
Message-oriented facade interface for multi-agent simulation.
This module provides a message-oriented interface that wraps the Orchestrator functionality, allowing developers to interact with the simulation using event-driven patterns like emit() for broadcasting and subscription-based message delivery.
- class gunn.facades.message.MessageSubscription(agent_id, message_types=None, handler=None)[ソース]¶
ベースクラス:
object
Represents a message subscription for an agent.
- パラメータ:
- class gunn.facades.message.MessageFacade(orchestrator=None, config=None, world_id='default', timeout_seconds=30.0)[ソース]¶
ベースクラス:
object
Message-oriented facade wrapping Orchestrator functionality.
Provides an event-driven interface with emit() for broadcasting and subscription-based message delivery while operating on the same underlying event system as other facades.
Requirements addressed: - 5.3: Developers call env.emit() to broadcast events through ObservationPolicy filtering - 5.4: Agents receive messages according to their observation policies - 5.5: Operates on the same underlying event system
- パラメータ:
orchestrator (Orchestrator | None)
config (OrchestratorConfig | None)
world_id (str)
timeout_seconds (float)
- async register_agent(agent_id, policy)[ソース]¶
Register an agent with the simulation.
- 戻り値の型:
- パラメータ:
agent_id (str)
policy (ObservationPolicy)
- Args:
agent_id: Unique identifier for the agent policy: Observation policy for this agent
- Raises:
ValueError: If agent_id is invalid or already registered RuntimeError: If maximum agents exceeded
- async emit(message_type, payload, source_id, schema_version='1.0.0')[ソース]¶
Broadcast an event through observation policies.
This method implements requirement 5.3: developers call env.emit() to broadcast events through ObservationPolicy filtering.
- Args:
message_type: Type of message being emitted payload: Message payload data source_id: Identifier of the message source schema_version: Schema version for the message
- Raises:
ValueError: If message_type or source_id is invalid BackpressureError: If backpressure limits are exceeded ValidationError: If message validation fails TimeoutError: If emission times out
Requirements addressed: - 5.3: WHEN using message facade THEN developers SHALL call env.emit() to broadcast events through ObservationPolicy filtering
- async subscribe(agent_id, message_types=None, handler=None)[ソース]¶
Subscribe an agent to specific message types.
This method implements requirement 5.4: agents receive messages according to their observation policies.
- 戻り値の型:
- パラメータ:
- Args:
agent_id: Agent identifier message_types: Set of message types to subscribe to (None = all types) handler: Optional message handler function
- Returns:
MessageSubscription object for managing the subscription
- Raises:
ValueError: If agent_id is not registered
Requirements addressed: - 5.4: WHEN using message facade THEN agents SHALL receive messages according to their observation policies
- async unsubscribe(subscription)[ソース]¶
Remove a message subscription.
- 戻り値の型:
- パラメータ:
subscription (MessageSubscription)
- Args:
subscription: Subscription to remove
- async get_messages(agent_id, timeout=None)[ソース]¶
Get pending messages for an agent.
- Args:
agent_id: Agent identifier timeout: Optional timeout for waiting for messages
- Returns:
List of pending messages
- Raises:
ValueError: If agent_id is not registered TimeoutError: If timeout is exceeded
- async wait_for_message(agent_id, message_type=None, timeout=None)[ソース]¶
Wait for a specific message for an agent.
- Args:
agent_id: Agent identifier message_type: Optional specific message type to wait for timeout: Optional timeout for waiting
- Returns:
The received message
- Raises:
ValueError: If agent_id is not registered TimeoutError: If timeout is exceeded
- async shutdown()[ソース]¶
Shutdown the message facade and clean up resources.
Cancels all delivery tasks and shuts down the orchestrator.
- 戻り値の型:
- get_orchestrator()[ソース]¶
Get the underlying orchestrator instance.
- 戻り値の型:
- Returns:
The orchestrator instance used by this facade
Requirements addressed: - 5.5: Both facades operate on the same underlying event system
- set_timeout(timeout_seconds)[ソース]¶
Set the default timeout for operations.
- Args:
timeout_seconds: New timeout value in seconds
- Raises:
ValueError: If timeout_seconds is not positive
gunn.facades.rl module¶
RL-style facade interface for multi-agent simulation.
This module provides an RL-style interface that wraps the Orchestrator functionality, allowing developers to interact with the simulation using familiar RL patterns like observe() and step() methods.
- class gunn.facades.rl.RLFacade(orchestrator=None, config=None, world_id='default', timeout_seconds=30.0)[ソース]¶
ベースクラス:
object
RL-style facade wrapping Orchestrator functionality.
Provides a familiar RL interface with observe() and step() methods while operating on the same underlying event system as other facades.
Requirements addressed: - 5.1: Developers call env.observe(agent_id) to get observations - 5.2: Developers call env.step(agent_id, intent) and receive (Effect, ObservationDelta) tuple - 5.5: Operates on the same underlying event system
- パラメータ:
orchestrator (Orchestrator | None)
config (OrchestratorConfig | None)
world_id (str)
timeout_seconds (float)
- async register_agent(agent_id, policy)[ソース]¶
Register an agent with the simulation.
- 戻り値の型:
- パラメータ:
agent_id (str)
policy (ObservationPolicy)
- Args:
agent_id: Unique identifier for the agent policy: Observation policy for this agent
- Returns:
AgentHandle for the registered agent
- Raises:
ValueError: If agent_id is invalid or already registered RuntimeError: If maximum agents exceeded
- async observe(agent_id)[ソース]¶
Get current observations for an agent.
This method implements requirement 5.1: developers call env.observe(agent_id) to get observations.
- 戻り値の型:
- パラメータ:
agent_id (str)
- Args:
agent_id: Agent identifier
- Returns:
Current observation delta for the agent
- Raises:
ValueError: If agent_id is not registered TimeoutError: If observation retrieval times out RuntimeError: If agent handle is not available
Requirements addressed: - 5.1: WHEN using RL facade THEN developers SHALL call env.observe(agent_id) to get observations
- async step(agent_id, intent)[ソース]¶
Execute a step with an intent and return the effect and observation.
This method implements requirement 5.2: developers call env.step(agent_id, intent) and receive (Effect, ObservationDelta) tuple.
- 戻り値の型:
- パラメータ:
- Args:
agent_id: Agent identifier intent: Intent to execute
- Returns:
Tuple of (Effect, ObservationDelta) representing the action result
- Raises:
ValueError: If agent_id is not registered or intent is invalid StaleContextError: If intent context is stale QuotaExceededError: If agent quota is exceeded BackpressureError: If backpressure limits are exceeded ValidationError: If intent validation fails TimeoutError: If step execution times out
Requirements addressed: - 5.2: WHEN using RL facade THEN developers SHALL call env.step(agent_id, intent) and receive (Effect, ObservationDelta) tuple
- async shutdown()[ソース]¶
Shutdown the RL facade and clean up resources.
Cancels any pending step operations and shuts down the orchestrator.
- 戻り値の型:
- get_orchestrator()[ソース]¶
Get the underlying orchestrator instance.
- 戻り値の型:
- Returns:
The orchestrator instance used by this facade
Requirements addressed: - 5.5: Both facades operate on the same underlying event system
- set_timeout(timeout_seconds)[ソース]¶
Set the default timeout for operations.
- Args:
timeout_seconds: New timeout value in seconds
- Raises:
ValueError: If timeout_seconds is not positive
Module contents¶
- class gunn.facades.MessageFacade(orchestrator=None, config=None, world_id='default', timeout_seconds=30.0)[ソース]¶
ベースクラス:
object
Message-oriented facade wrapping Orchestrator functionality.
Provides an event-driven interface with emit() for broadcasting and subscription-based message delivery while operating on the same underlying event system as other facades.
Requirements addressed: - 5.3: Developers call env.emit() to broadcast events through ObservationPolicy filtering - 5.4: Agents receive messages according to their observation policies - 5.5: Operates on the same underlying event system
- パラメータ:
orchestrator (Orchestrator | None)
config (OrchestratorConfig | None)
world_id (str)
timeout_seconds (float)
- async emit(message_type, payload, source_id, schema_version='1.0.0')[ソース]¶
Broadcast an event through observation policies.
This method implements requirement 5.3: developers call env.emit() to broadcast events through ObservationPolicy filtering.
- Args:
message_type: Type of message being emitted payload: Message payload data source_id: Identifier of the message source schema_version: Schema version for the message
- Raises:
ValueError: If message_type or source_id is invalid BackpressureError: If backpressure limits are exceeded ValidationError: If message validation fails TimeoutError: If emission times out
Requirements addressed: - 5.3: WHEN using message facade THEN developers SHALL call env.emit() to broadcast events through ObservationPolicy filtering
- get_agent_subscriptions(agent_id)[ソース]¶
Get all active subscriptions for an agent.
- 戻り値の型:
- パラメータ:
agent_id (str)
- Args:
agent_id: Agent identifier
- Returns:
List of active subscriptions
- Raises:
ValueError: If agent_id is not registered
- get_message_queue_size(agent_id)[ソース]¶
Get the current size of an agent's message queue.
- Args:
agent_id: Agent identifier
- Returns:
Number of pending messages
- Raises:
ValueError: If agent_id is not registered
- async get_messages(agent_id, timeout=None)[ソース]¶
Get pending messages for an agent.
- Args:
agent_id: Agent identifier timeout: Optional timeout for waiting for messages
- Returns:
List of pending messages
- Raises:
ValueError: If agent_id is not registered TimeoutError: If timeout is exceeded
- get_orchestrator()[ソース]¶
Get the underlying orchestrator instance.
- 戻り値の型:
- Returns:
The orchestrator instance used by this facade
Requirements addressed: - 5.5: Both facades operate on the same underlying event system
- async register_agent(agent_id, policy)[ソース]¶
Register an agent with the simulation.
- 戻り値の型:
- パラメータ:
agent_id (str)
policy (ObservationPolicy)
- Args:
agent_id: Unique identifier for the agent policy: Observation policy for this agent
- Raises:
ValueError: If agent_id is invalid or already registered RuntimeError: If maximum agents exceeded
- set_timeout(timeout_seconds)[ソース]¶
Set the default timeout for operations.
- Args:
timeout_seconds: New timeout value in seconds
- Raises:
ValueError: If timeout_seconds is not positive
- async shutdown()[ソース]¶
Shutdown the message facade and clean up resources.
Cancels all delivery tasks and shuts down the orchestrator.
- 戻り値の型:
- async subscribe(agent_id, message_types=None, handler=None)[ソース]¶
Subscribe an agent to specific message types.
This method implements requirement 5.4: agents receive messages according to their observation policies.
- 戻り値の型:
- パラメータ:
- Args:
agent_id: Agent identifier message_types: Set of message types to subscribe to (None = all types) handler: Optional message handler function
- Returns:
MessageSubscription object for managing the subscription
- Raises:
ValueError: If agent_id is not registered
Requirements addressed: - 5.4: WHEN using message facade THEN agents SHALL receive messages according to their observation policies
- async unsubscribe(subscription)[ソース]¶
Remove a message subscription.
- 戻り値の型:
- パラメータ:
subscription (MessageSubscription)
- Args:
subscription: Subscription to remove
- async wait_for_message(agent_id, message_type=None, timeout=None)[ソース]¶
Wait for a specific message for an agent.
- Args:
agent_id: Agent identifier message_type: Optional specific message type to wait for timeout: Optional timeout for waiting
- Returns:
The received message
- Raises:
ValueError: If agent_id is not registered TimeoutError: If timeout is exceeded
- class gunn.facades.RLFacade(orchestrator=None, config=None, world_id='default', timeout_seconds=30.0)[ソース]¶
ベースクラス:
object
RL-style facade wrapping Orchestrator functionality.
Provides a familiar RL interface with observe() and step() methods while operating on the same underlying event system as other facades.
Requirements addressed: - 5.1: Developers call env.observe(agent_id) to get observations - 5.2: Developers call env.step(agent_id, intent) and receive (Effect, ObservationDelta) tuple - 5.5: Operates on the same underlying event system
- パラメータ:
orchestrator (Orchestrator | None)
config (OrchestratorConfig | None)
world_id (str)
timeout_seconds (float)
- async cancel_agent_step(agent_id)[ソース]¶
Cancel any pending step operation for an agent.
- Args:
agent_id: Agent identifier
- Returns:
True if a step was cancelled, False if no step was pending
- Raises:
ValueError: If agent_id is not registered
- async get_agent_view_seq(agent_id)[ソース]¶
Get the current view sequence for an agent.
- Args:
agent_id: Agent identifier
- Returns:
Current view sequence number
- Raises:
ValueError: If agent_id is not registered
- get_orchestrator()[ソース]¶
Get the underlying orchestrator instance.
- 戻り値の型:
- Returns:
The orchestrator instance used by this facade
Requirements addressed: - 5.5: Both facades operate on the same underlying event system
- async observe(agent_id)[ソース]¶
Get current observations for an agent.
This method implements requirement 5.1: developers call env.observe(agent_id) to get observations.
- 戻り値の型:
- パラメータ:
agent_id (str)
- Args:
agent_id: Agent identifier
- Returns:
Current observation delta for the agent
- Raises:
ValueError: If agent_id is not registered TimeoutError: If observation retrieval times out RuntimeError: If agent handle is not available
Requirements addressed: - 5.1: WHEN using RL facade THEN developers SHALL call env.observe(agent_id) to get observations
- async register_agent(agent_id, policy)[ソース]¶
Register an agent with the simulation.
- 戻り値の型:
- パラメータ:
agent_id (str)
policy (ObservationPolicy)
- Args:
agent_id: Unique identifier for the agent policy: Observation policy for this agent
- Returns:
AgentHandle for the registered agent
- Raises:
ValueError: If agent_id is invalid or already registered RuntimeError: If maximum agents exceeded
- set_timeout(timeout_seconds)[ソース]¶
Set the default timeout for operations.
- Args:
timeout_seconds: New timeout value in seconds
- Raises:
ValueError: If timeout_seconds is not positive
- async shutdown()[ソース]¶
Shutdown the RL facade and clean up resources.
Cancels any pending step operations and shuts down the orchestrator.
- 戻り値の型:
- async step(agent_id, intent)[ソース]¶
Execute a step with an intent and return the effect and observation.
This method implements requirement 5.2: developers call env.step(agent_id, intent) and receive (Effect, ObservationDelta) tuple.
- 戻り値の型:
- パラメータ:
- Args:
agent_id: Agent identifier intent: Intent to execute
- Returns:
Tuple of (Effect, ObservationDelta) representing the action result
- Raises:
ValueError: If agent_id is not registered or intent is invalid StaleContextError: If intent context is stale QuotaExceededError: If agent quota is exceeded BackpressureError: If backpressure limits are exceeded ValidationError: If intent validation fails TimeoutError: If step execution times out
Requirements addressed: - 5.2: WHEN using RL facade THEN developers SHALL call env.step(agent_id, intent) and receive (Effect, ObservationDelta) tuple