gunn.policies package¶
Submodules¶
gunn.policies.observation module¶
Observation policies for partial observation and view filtering.
This module implements the ObservationPolicy interface that controls what agents can observe in the simulation world, including distance-based filtering, relationship constraints, and efficient observation delta generation using RFC6902 JSON Patch operations.
- class gunn.policies.observation.LatencyModel(*args, **kwargs)[ソース]¶
ベースクラス:
Protocol
Protocol for calculating observation delivery latency.
- class gunn.policies.observation.PolicyConfig(**data)[ソース]¶
ベースクラス:
BaseModel
Configuration for observation policies.
- パラメータ:
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class gunn.policies.observation.NoLatencyModel[ソース]¶
ベースクラス:
object
Default latency model with no delay.
- class gunn.policies.observation.DistanceLatencyModel(base_latency=0.01, distance_factor=0.001)[ソース]¶
ベースクラス:
object
Latency model based on spatial distance between agents.
- class gunn.policies.observation.ObservationPolicy(config)[ソース]¶
ベースクラス:
ABC
Abstract base class for observation policies.
Observation policies control what agents can see in the simulation world, including spatial filtering, relationship constraints, and field visibility.
- パラメータ:
config (PolicyConfig)
- set_latency_model(latency_model)[ソース]¶
Set the latency model for observation delivery.
- 戻り値の型:
- パラメータ:
latency_model (LatencyModel)
- Args:
latency_model: Latency model to use for calculating delays
- abstractmethod filter_world_state(world_state, agent_id)[ソース]¶
Generate agent's filtered view of the world state.
- 戻り値の型:
- パラメータ:
world_state (WorldState)
agent_id (str)
- Args:
world_state: Complete world state agent_id: Agent requesting the view
- Returns:
Filtered view containing only what the agent should see
- abstractmethod should_observe_event(effect, agent_id, world_state)[ソース]¶
Determine if an agent should observe a specific effect.
- 戻り値の型:
- パラメータ:
effect (Effect)
agent_id (str)
world_state (WorldState)
- Args:
effect: Effect that occurred agent_id: Agent to check observation for world_state: Current world state
- Returns:
True if agent should observe this effect
- class gunn.policies.observation.DefaultObservationPolicy(config)[ソース]¶
ベースクラス:
ObservationPolicy
Default observation policy with distance and relationship filtering.
This policy implements: - Distance-based spatial filtering - Relationship-based entity filtering - Field-level visibility controls - Stable path generation for JSON patches
- パラメータ:
config (PolicyConfig)
- filter_world_state(world_state, agent_id)[ソース]¶
Generate agent's filtered view with distance and relationship constraints.
- 戻り値の型:
- パラメータ:
world_state (WorldState)
agent_id (str)
- Args:
world_state: Complete world state agent_id: Agent requesting the view
- Returns:
Filtered view containing only observable entities and relationships
- should_observe_event(effect, agent_id, world_state)[ソース]¶
Determine if agent should observe an effect based on policy rules.
- 戻り値の型:
- パラメータ:
effect (Effect)
agent_id (str)
world_state (WorldState)
- Args:
effect: Effect that occurred agent_id: Agent to check observation for world_state: Current world state
- Returns:
True if agent should observe this effect
- class gunn.policies.observation.ConversationObservationPolicy(config)[ソース]¶
ベースクラス:
ObservationPolicy
Observation policy optimized for conversation scenarios.
This policy is designed for multi-agent conversations where agents should observe speaking events and participant changes, but may have limited spatial awareness.
- パラメータ:
config (PolicyConfig)
- filter_world_state(world_state, agent_id)[ソース]¶
Generate conversation-focused view of the world state.
- 戻り値の型:
- パラメータ:
world_state (WorldState)
agent_id (str)
- Args:
world_state: Complete world state agent_id: Agent requesting the view
- Returns:
View focused on conversation participants and recent messages
- should_observe_event(effect, agent_id, world_state)[ソース]¶
Determine if agent should observe conversation-related effects.
- 戻り値の型:
- パラメータ:
effect (Effect)
agent_id (str)
world_state (WorldState)
- Args:
effect: Effect that occurred agent_id: Agent to check observation for world_state: Current world state
- Returns:
True if agent should observe this conversation effect
- gunn.policies.observation.create_observation_policy(policy_type, config)[ソース]¶
Create an observation policy of the specified type.
- 戻り値の型:
- パラメータ:
policy_type (str)
config (PolicyConfig)
- Args:
policy_type: Type of policy to create ("default" or "conversation") config: Policy configuration
- Returns:
Configured observation policy instance
- Raises:
ValueError: If policy_type is not recognized
Module contents¶
Observation and validation policies for the Gunn simulation core.
- class gunn.policies.ConversationObservationPolicy(config)[ソース]¶
ベースクラス:
ObservationPolicy
Observation policy optimized for conversation scenarios.
This policy is designed for multi-agent conversations where agents should observe speaking events and participant changes, but may have limited spatial awareness.
- パラメータ:
config (PolicyConfig)
- filter_world_state(world_state, agent_id)[ソース]¶
Generate conversation-focused view of the world state.
- 戻り値の型:
- パラメータ:
world_state (WorldState)
agent_id (str)
- Args:
world_state: Complete world state agent_id: Agent requesting the view
- Returns:
View focused on conversation participants and recent messages
- should_observe_event(effect, agent_id, world_state)[ソース]¶
Determine if agent should observe conversation-related effects.
- 戻り値の型:
- パラメータ:
effect (Effect)
agent_id (str)
world_state (WorldState)
- Args:
effect: Effect that occurred agent_id: Agent to check observation for world_state: Current world state
- Returns:
True if agent should observe this conversation effect
- class gunn.policies.DefaultObservationPolicy(config)[ソース]¶
ベースクラス:
ObservationPolicy
Default observation policy with distance and relationship filtering.
This policy implements: - Distance-based spatial filtering - Relationship-based entity filtering - Field-level visibility controls - Stable path generation for JSON patches
- パラメータ:
config (PolicyConfig)
- filter_world_state(world_state, agent_id)[ソース]¶
Generate agent's filtered view with distance and relationship constraints.
- 戻り値の型:
- パラメータ:
world_state (WorldState)
agent_id (str)
- Args:
world_state: Complete world state agent_id: Agent requesting the view
- Returns:
Filtered view containing only observable entities and relationships
- should_observe_event(effect, agent_id, world_state)[ソース]¶
Determine if agent should observe an effect based on policy rules.
- 戻り値の型:
- パラメータ:
effect (Effect)
agent_id (str)
world_state (WorldState)
- Args:
effect: Effect that occurred agent_id: Agent to check observation for world_state: Current world state
- Returns:
True if agent should observe this effect
- class gunn.policies.DistanceLatencyModel(base_latency=0.01, distance_factor=0.001)[ソース]¶
ベースクラス:
object
Latency model based on spatial distance between agents.
- class gunn.policies.LatencyModel(*args, **kwargs)[ソース]¶
ベースクラス:
Protocol
Protocol for calculating observation delivery latency.
- class gunn.policies.ObservationPolicy(config)[ソース]¶
ベースクラス:
ABC
Abstract base class for observation policies.
Observation policies control what agents can see in the simulation world, including spatial filtering, relationship constraints, and field visibility.
- パラメータ:
config (PolicyConfig)
- calculate_observation_delta(old_view, new_view)[ソース]¶
Generate RFC6902 JSON Patch between two views.
- 戻り値の型:
- パラメータ:
- Args:
old_view: Previous view state new_view: New view state
- Returns:
ObservationDelta with JSON patch operations
- Raises:
ValueError: If views are for different agents
- abstractmethod filter_world_state(world_state, agent_id)[ソース]¶
Generate agent's filtered view of the world state.
- 戻り値の型:
- パラメータ:
world_state (WorldState)
agent_id (str)
- Args:
world_state: Complete world state agent_id: Agent requesting the view
- Returns:
Filtered view containing only what the agent should see
- set_latency_model(latency_model)[ソース]¶
Set the latency model for observation delivery.
- 戻り値の型:
- パラメータ:
latency_model (LatencyModel)
- Args:
latency_model: Latency model to use for calculating delays
- abstractmethod should_observe_event(effect, agent_id, world_state)[ソース]¶
Determine if an agent should observe a specific effect.
- 戻り値の型:
- パラメータ:
effect (Effect)
agent_id (str)
world_state (WorldState)
- Args:
effect: Effect that occurred agent_id: Agent to check observation for world_state: Current world state
- Returns:
True if agent should observe this effect
- class gunn.policies.PolicyConfig(**data)[ソース]¶
ベースクラス:
BaseModel
Configuration for observation policies.
- パラメータ:
- model_config: ClassVar[ConfigDict] = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- gunn.policies.create_observation_policy(policy_type, config)[ソース]¶
Create an observation policy of the specified type.
- 戻り値の型:
- パラメータ:
policy_type (str)
config (PolicyConfig)
- Args:
policy_type: Type of policy to create ("default" or "conversation") config: Policy configuration
- Returns:
Configured observation policy instance
- Raises:
ValueError: If policy_type is not recognized