AI System API Reference¶
This section provides complete API documentation for all AI-related modules and classes in Yendoria.
AI Manager¶
AI Manager Hub - Central coordination system for all AI components.
This module provides the main coordination point for all AI systems, managing the lifecycle of AI entities, system registration, and cross-system communication through events.
- class yendoria.systems.ai_manager.AIManager(component_manager, config_manager=None)[source]¶
Bases:
object
Central AI management hub that coordinates all AI systems.
The AIManager serves as the main interface for AI operations, handling entity lifecycle, system coordination, and event distribution.
- register_ai_entity(entity_id, archetype=None, faction=None)[source]¶
Register an entity as AI-controlled.
- class yendoria.systems.ai_manager.AISystemRegistry[source]¶
Bases:
object
Registry for AI subsystems and their capabilities.
- yendoria.systems.ai_manager.get_ai_manager()[source]¶
Get the AI manager singleton instance.
- Return type:
AI Behavior Systems¶
AI Behavior Interface¶
AI Behavior System Interface - Common interface for all AI behavior systems.
This module defines the interface that all AI behavior systems must implement, ensuring consistency and interchangeability between different AI implementations.
- class yendoria.systems.ai_behavior_interface.AIBehaviorSystemInterface(component_manager)[source]¶
Bases:
ABC
Abstract base class for all AI behavior systems.
This interface ensures that all AI behavior implementations provide the same basic functionality for integration with the AI Manager and Game Engine.
- abstract property name: str¶
Get the name of this AI behavior system.
- Returns:
Human-readable name of the system
Basic AI Behavior System¶
Basic AI Behavior System - Lightweight AI implementation for simple entities.
This module provides essential AI behaviors with minimal overhead and component requirements. Use this for basic NPCs, background entities, or when performance is more important than AI sophistication.
- class yendoria.systems.ai_behavior_basic.BasicAIBehaviorSystem(component_manager)[source]¶
Bases:
AIBehaviorSystemInterface
Basic AI behavior system optimized for performance and simplicity.
This system provides: - Timer-based action selection - Simple random behavior choices - Minimal component requirements (only BehaviorTreeComponent) - Low computational overhead - Basic event handling
Use this system for: - Background NPCs that need minimal AI - Entities where performance is critical - Simple creatures or ambient life - Placeholder AI during development
Advanced AI Behavior System¶
Advanced AI Behavior System - Implements sophisticated AI behaviors.
This module provides comprehensive AI behaviors including personality-driven decisions, memory-based learning, motivation systems, and complex behavior trees. Use this for entities that need rich, nuanced AI behavior.
- class yendoria.systems.ai_behavior_advanced.AdvancedAIBehaviorSystem(component_manager)[source]¶
Bases:
AIBehaviorSystemInterface
Advanced AI behavior system that implements sophisticated decision-making.
This system provides: - Personality-driven behavior decisions - Memory-based learning and adaptation - Complex motivation and need systems - Full behavior tree processing - Social interaction modeling - Faction-aware behavior
Use this system for important NPCs, boss enemies, or any entity that needs rich, believable AI behavior.
- class yendoria.systems.ai_behavior_advanced.BehaviorContext(entity_id, personality, motivation, memory, delta_time)[source]¶
Bases:
object
Context object to reduce parameter passing in behavior tree functions.
-
memory:
MemoryComponent
¶
-
motivation:
MotivationComponent
¶
-
personality:
PersonalityComponent
¶
-
memory:
AI Components¶
AI-specific components for the Entity Component System.
This module provides components specifically designed for AI systems, including faction membership, personality traits, memory, and behavior trees.
- class yendoria.components.ai_components.AIState(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
AI behavior states.
- COMBAT = 'combat'¶
- FLEE = 'flee'¶
- IDLE = 'idle'¶
- INVESTIGATE = 'investigate'¶
- PATROL = 'patrol'¶
- PURSUE = 'pursue'¶
- RITUAL = 'ritual'¶
- SOCIAL = 'social'¶
- class yendoria.components.ai_components.BehaviorTreeComponent(tree_config=None, *, tree_data=None)[source]¶
Bases:
Component
Component that holds an AI entity’s behavior tree configuration.
Used by the Agent Behavior System for decision-making.
- class yendoria.components.ai_components.FactionComponent(faction_id, rank='member', loyalty=1.0, config=None)[source]¶
Bases:
Component
Component that marks an entity as belonging to a specific faction.
This is used by the Faction AI Manager to coordinate group behavior.
- class yendoria.components.ai_components.FactionConfig(name=None, description=None, relations=<factory>, territory=<factory>)[source]¶
Bases:
object
Configuration for faction-specific attributes.
- class yendoria.components.ai_components.KnowledgeComponent[source]¶
Bases:
Component
Component that stores structured knowledge about the world.
Used for faction intelligence, map knowledge, and strategic planning.
- class yendoria.components.ai_components.Memory(content, timestamp, importance, reliability, associated_entity=None, location=None, fade_rate=0.01, episodic_memories=None)[source]¶
Bases:
object
A single memory stored by an AI agent.
- class yendoria.components.ai_components.MemoryComponent(max_memories=100)[source]¶
Bases:
Component
Component that stores an AI entity’s memories and knowledge.
Used by the Memory & Knowledge System for learning and rumor propagation.
- forget_old_memories(current_time)[source]¶
Remove memories that have faded below relevance threshold.
- Return type:
- class yendoria.components.ai_components.MotivationComponent[source]¶
Bases:
Component
Component that defines an AI entity’s current motivations and goals.
Used by Utility AI systems to evaluate and prioritize actions.
- class yendoria.components.ai_components.PersonalityComponent(traits=None)[source]¶
Bases:
Component
Component that defines an AI entity’s personality traits.
These traits influence decision-making in behavior trees and utility AI.
- class yendoria.components.ai_components.ReputationComponent[source]¶
Bases:
Component
Component that tracks an entity’s reputation with various factions and individuals.
Used by the Reputation Engine and Faction AI Manager.
- get_individual_reputation(entity_id)[source]¶
Get reputation with a specific individual.
- Return type:
- modify_faction_reputation(faction_id, delta)[source]¶
Modify reputation with a faction by a delta amount.
- Return type:
AI Events¶
AI-specific events for the event system.
This module extends the core event system with events specifically for AI systems, including faction events, behavior changes, and memory/learning events.
- class yendoria.components.ai_events.AIEvent(event_type, data, cancellable=False, source='ai_system', priority=0)[source]¶
Bases:
GameEvent
AI-specific event class with additional functionality.
Extends the base GameEvent with AI-specific metadata and helpers.
- class yendoria.components.ai_events.AIEventType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
AI-specific events that can be emitted and handled.
- AI_STATE_CHANGED = 'ai_state_changed'¶
- BATTLE_OUTCOME = 'battle_outcome'¶
- BEHAVIOR_NODE_FAILED = 'behavior_node_failed'¶
- BEHAVIOR_TREE_COMPLETED = 'behavior_tree_completed'¶
- BEHAVIOR_TREE_STARTED = 'behavior_tree_started'¶
- CONFLICT_RESOLVED = 'conflict_resolved'¶
- CONFLICT_STARTED = 'conflict_started'¶
- CORRUPTION_SPREAD = 'corruption_spread'¶
- DYNAMIC_QUEST_GENERATED = 'dynamic_quest_generated'¶
- ENTITY_RECOGNIZED = 'entity_recognized'¶
- ENTITY_SPAWNED = 'entity_spawned'¶
- FACTION_ALLIANCE_FORMED = 'faction_alliance_formed'¶
- FACTION_BETRAYAL = 'faction_betrayal'¶
- FACTION_LEADER_CHANGED = 'faction_leader_changed'¶
- FACTION_PEACE_DECLARED = 'faction_peace_declared'¶
- FACTION_QUEST_OFFERED = 'faction_quest_offered'¶
- FACTION_RELATIONSHIP_CHANGED = 'faction_relationship_changed'¶
- FACTION_RELATION_CHANGED = 'faction_relationship_changed'¶
- FACTION_TERRITORY_GAINED = 'faction_territory_gained'¶
- FACTION_TERRITORY_LOST = 'faction_territory_lost'¶
- FACTION_WAR_DECLARED = 'faction_war_declared'¶
- KNOWLEDGE_UPDATED = 'knowledge_updated'¶
- MEMORY_CREATED = 'memory_created'¶
- MEMORY_FORGOTTEN = 'memory_forgotten'¶
- PLAYER_BETRAYED_FACTION = 'player_betrayed_faction'¶
- PLAYER_FACTION_DISCOVERED = 'player_faction_discovered'¶
- PLAYER_HELPED_FACTION = 'player_helped_faction'¶
- PLAYER_REPUTATION_THRESHOLD = 'player_reputation_threshold'¶
- PLAYER_WITNESSED_CRIME = 'player_witnessed_crime'¶
- QUEST_OBJECTIVE_UPDATED = 'quest_objective_updated'¶
- REPUTATION_CHANGED = 'reputation_changed'¶
- RITUAL_PERFORMED = 'ritual_performed'¶
- RUMOR_SPREAD = 'rumor_spread'¶
- SHRINE_ACTIVATED = 'shrine_activated'¶
- SHRINE_CORRUPTED = 'shrine_corrupted'¶
- SIEGE_ENDED = 'siege_ended'¶
- SIEGE_STARTED = 'siege_started'¶
- TITLE_GAINED = 'title_gained'¶
- TITLE_LOST = 'title_lost'¶
- TURN_STARTED = 'turn_started'¶
- ZONE_CONTROL_CHANGED = 'zone_control_changed'¶
- yendoria.components.ai_events.create_ai_state_changed_event(entity_id, old_state, new_state)[source]¶
Create an AI state changed event.
- Return type:
- yendoria.components.ai_events.create_conflict_started_event(faction_a, faction_b, conflict_type, cause, location=None)[source]¶
Create a conflict started event.
- Return type:
- yendoria.components.ai_events.create_dynamic_quest_generated_event(quest_id, quest_type, faction_id, trigger_event, requirements)[source]¶
Create a dynamic quest generated event.
- Return type:
- yendoria.components.ai_events.create_entity_spawned_event(entity_id, entity_type, location, faction_id)[source]¶
Create an entity spawned event.
- Return type:
- yendoria.components.ai_events.create_faction_relation_changed_event(faction_a, faction_b, old_relationship, new_relationship, reason='unknown')[source]¶
Create a faction relationship changed event (compatibility alias).
- Return type:
- yendoria.components.ai_events.create_faction_relationship_changed_event(faction_a, faction_b, old_relationship, new_relationship, reason='unknown')[source]¶
Create a faction relationship changed event.
- Return type:
- yendoria.components.ai_events.create_memory_created_event(entity_id, memory_content, importance, location=None)[source]¶
Create a memory created event.
- Return type:
- yendoria.components.ai_events.create_player_reputation_threshold_event(faction_id, old_threshold, new_threshold, reputation_value)[source]¶
Create a player reputation threshold event.
- Return type:
- yendoria.components.ai_events.create_reputation_changed_event(entity_id, target_id, target_type, old_reputation, new_reputation)[source]¶
Create a reputation changed event.
- Return type:
- yendoria.components.ai_events.create_turn_started_event(turn_number, active_entities)[source]¶
Create a turn started event.
- Return type:
- yendoria.components.ai_events.create_zone_control_changed_event(zone_id, old_controller, new_controller, method='conquest')[source]¶
Create a zone control changed event.
- Return type:
- yendoria.components.ai_events.log_faction_events(event)[source]¶
Example handler that logs faction-related events.
- Return type:
AI Engine Integration¶
AI Engine Integration - Bridge between GameEngine and AI systems.
This module provides the integration layer between the main game engine and the AI system, handling initialization, updates, and event bridging.
- class yendoria.systems.ai_engine_integration.AIEngineIntegration(game_event_bus)[source]¶
Bases:
object
Integration layer between GameEngine and AI systems.
This class handles: - AI system initialization and lifecycle - Event bridging between game events and AI events - Entity registration with AI systems - AI update coordination
- yendoria.systems.ai_engine_integration.get_ai_integration()[source]¶
Get the AI integration singleton instance.
- Return type:
Error Handling & Monitoring¶
AI System Error Handling Utilities.
This module provides common error handling patterns and utilities for AI system operations, including context managers and decorators.
- exception yendoria.systems.ai_error_handling.AIComponentError[source]¶
Bases:
AISystemError
Raised when there’s an issue with AI components.
- exception yendoria.systems.ai_error_handling.AIConfigurationError[source]¶
Bases:
AISystemError
Raised when there’s an issue with AI configuration.
- exception yendoria.systems.ai_error_handling.AIEntityNotFoundError[source]¶
Bases:
AISystemError
Raised when an AI entity is not found.
- class yendoria.systems.ai_error_handling.AIOperationMetrics[source]¶
Bases:
object
Simple metrics collection for AI operations.
- exception yendoria.systems.ai_error_handling.AISystemError[source]¶
Bases:
Exception
Base exception for AI system errors.
- yendoria.systems.ai_error_handling.ai_error_handler(operation_name)[source]¶
Decorator for AI operations with consistent error handling.
- yendoria.systems.ai_error_handling.ai_operation_context(operation_name)[source]¶
Context manager for AI operations with consistent error handling.
- yendoria.systems.ai_error_handling.ensure_ai_component(component_manager, entity_id, component_type)[source]¶
Ensure an entity has a specific AI component.
- Parameters:
- Return type:
- Returns:
The component instance
- Raises:
AIComponentError – If the component is missing
- yendoria.systems.ai_error_handling.get_ai_metrics()[source]¶
Get the global AI metrics instance.
- Return type:
- yendoria.systems.ai_error_handling.handle_ai_errors(operation_name, default_return=None, reraise=False)[source]¶
Decorator for AI operations with consistent error handling.
- yendoria.systems.ai_error_handling.safe_ai_operation(func, *args, operation_name='AI operation', default_return=None, **kwargs)[source]¶
Safely execute an AI operation with error handling.
- Parameters:
- Return type:
Configuration Management¶
Configuration management system for AI components.
This module provides hot-reloadable configuration management for AI systems, allowing behavior to be modified without code changes and supporting modding.
- class yendoria.systems.config_manager.ConfigWatcher(config_manager)[source]¶
Bases:
FileSystemEventHandler
Watches configuration files for changes and triggers reloads.
- yendoria.systems.config_manager.get_behavior_tree_config()[source]¶
Get behavior tree configurations.
- yendoria.systems.config_manager.get_quest_template_config()[source]¶
Get quest template configurations.
- yendoria.systems.config_manager.initialize_config_manager(config_root='config')[source]¶
Initialize the configuration manager singleton.
- Parameters:
config_root (
str
) – Root directory for configuration files- Return type:
- Returns:
The configuration manager instance
- yendoria.systems.config_manager.load_archetype_config()[source]¶
Load the archetype configuration. DEPRECATED: Use get_archetype_config() instead.
- yendoria.systems.config_manager.load_behavior_tree_config()[source]¶
Load the behavior tree configuration. DEPRECATED: Use get_behavior_tree_config() instead.