Story System - Story Manager¶
File: cogs/story/manager.py
The StoryManager is the central orchestrator of the story system. It implements the layered AI agent architecture and coordinates all other components to drive the narrative forward.
StoryManager Class¶
__init__(self, bot, cog, system_prompt_manager)¶
Initializes the manager and its dependencies.
- Dependencies:
StoryDB&CharacterDB: For all database interactions.StoryPromptEngine: To build prompts for the AI agents.StoryStateManager: To apply state updates from the AI's plan.MemoryManager: To potentially inject long-term memories into the context.LanguageManager: For localization.
async process_story_message(self, message: discord.Message)¶
This is the main entry point for the story generation pipeline, called every time a user sends a message in a story channel.
- Process (Layered AI Agent Pipeline):
- GM Agent Call: It first calls the
StoryPromptEngineto build a comprehensive prompt for the "Director" (GM) agent. This prompt includes the world state, character details, recent events, and the user's latest message. - Plan Generation: It sends this prompt to the LLM, instructing it to return a structured
GMActionPlanJSON object. This plan dictates the next story beat. - Plan Execution: The manager parses the
GMActionPlan.- If the plan's
action_typeisNARRATE, it sends the narration content directly to the channel. - If the
action_typeisDIALOGUE, it proceeds to the next layer.
- If the plan's
- Actor Agent Calls: For a
DIALOGUEaction, the manager iterates through thedialogue_contextlist provided in the GM's plan. For each character scheduled to speak:- It calls the
StoryPromptEngineagain to build a specific prompt for that "Actor" (Character) agent. This prompt includes the character's personality and the Director's specific instructions (motivation, emotional state). - It sends this prompt to the LLM, instructing it to return a
CharacterActionJSON object containing the character's speech, actions, and thoughts. - The character's response is sent to the channel. The state (location, time) from this action becomes the authoritative state for the next actor in the sequence.
- It calls the
- State Update: After the plan is fully executed, it uses the final authoritative state (from the last actor's action) to update the
StoryInstancevia theStoryStateManager. It also updates any player-NPC relationships defined in the GM's plan. - Event Recording: The entire sequence of events is recorded as a single
Eventin the world's history. - Summary & Outline Generation: It maintains a message counter. After a certain number of messages (e.g., 20), it automatically triggers
_generate_and_save_summaryto create a summary of recent events. After a certain number of summaries (e.g., 10), it triggers_generate_and_save_outlineto create a higher-level plot outline. These are then fed back into the GM's context in future turns.
- GM Agent Call: It first calls the
Other Key Methods¶
start_story(...): Initializes a newStoryInstancein the database and callsgenerate_first_sceneto kick off the narrative.generate_first_scene(...): A special method that calls the GM agent with a prompt specifically designed to generate the opening narration for the story.add_intervention(...): Stores an out-of-character instruction from a user, which will be injected with high priority into the next GM prompt.