AI Prompting Reference
Prompt templates, response formats, and API usage patterns for the Babylon AI game master system. For conceptual explanation, see AI Integration.
Base Prompt Template
System Prompt
SYSTEM_PROMPT = """You are the game master for a Marxist political simulation.
Your role is to:
- Analyze player actions through dialectical materialism
- Generate realistic consequences based on material conditions
- Maintain internal consistency with previous events
- Escalate or de-escalate contradictions appropriately
- Consider class interests and power relations in all outcomes"""
Core Principles
Ground all responses in material conditions
Maintain internal consistency
Consider class relations and power dynamics
Provide structured, parseable responses
Include both mechanical effects and narrative description
Keep track of historical continuity
Allow for emergence of new contradictions
Context Hierarchy
Include context elements in this priority order:
Category |
Elements |
|---|---|
Material Conditions |
Economic conditions, class relations, political power distribution |
Active Contradictions |
Current intensity, involved entities, historical development |
Recent Events |
Outcomes, affected parties, changes to material conditions |
Player Status |
Position, resources, relationships |
Response Format
Standard Response Structure
Request structured responses for reliable parsing:
IMMEDIATE EFFECTS:
- [Effect 1]
- [Effect 2]
CONTRADICTION CHANGES:
- [Contradiction ID]: [Change in intensity] because [reasoning]
NEW EVENTS:
- [Event description]
- Likelihood: [High/Medium/Low]
- Affected entities: [List]
NARRATIVE DESCRIPTION:
[2-3 sentences describing outcomes in narrative form]
Parsed Response Structure
class GameEffects:
immediate_effects: list[str]
new_contradictions: list[dict]
contradiction_changes: list[dict]
triggered_events: list[dict]
entity_effects: list[dict]
Specialized Prompts
Economic Action Prompt
def economic_action_prompt(action: str, state: GameState) -> str:
return f"""
The player has taken an economic action: {action}
Current Economic Indicators:
- Unemployment Rate: {state.unemployment}
- Class Inequality Index: {state.inequality}
- Industrial Capacity: {state.industry_capacity}
How do the following groups respond:
1. Working Class
2. Capitalist Class
3. State Apparatus
"""
Political Action Prompt
def political_action_prompt(action: str, state: GameState) -> str:
return f"""
The player has taken a political action: {action}
Current Political Landscape:
- Class Consciousness Level: {state.class_consciousness}
- State Legitimacy: {state.legitimacy}
- Opposition Strength: {state.opposition_power}
Analyze effects on:
1. Balance of class forces
2. State authority
3. Popular support
4. Potential for resistance
"""
Context Extraction
Data Processing
Extract relevant context from game objects:
def extract_relevant_context(objects: list) -> list[dict]:
context_elements = []
for obj in objects:
if isinstance(obj, Event):
context = {
'type': 'event',
'name': obj.name,
'description': obj.description,
'effects': [e.description for e in obj.effects],
'escalation_level': obj.escalation_level
}
elif isinstance(obj, Contradiction):
context = {
'type': 'contradiction',
'name': obj.name,
'description': obj.description,
'intensity': obj.intensity,
'involved_entities': [e.name for e in obj.entities]
}
context_elements.append(context)
return context_elements
API Integration
Claude API Usage
import anthropic
def generate_game_response(prompt: str) -> GameEffects:
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
temperature=0.7,
system=SYSTEM_PROMPT,
messages=[{"role": "user", "content": prompt}]
)
return parse_response(response.content[0].text)
API Parameters
Parameter |
Recommended |
Rationale |
|---|---|---|
|
|
Balance of capability and cost |
|
1024 |
Sufficient for structured responses |
|
0.7 |
Balance creativity with consistency |
Context window |
Up to 200k tokens |
Use ContextWindowManager to optimize |
Response Parsing
def parse_response(response: str) -> GameEffects:
game_effects = GameEffects(
immediate_effects=[],
new_contradictions=[],
contradiction_changes=[],
triggered_events=[],
entity_effects=[]
)
# Parse structured response sections
# Extract IMMEDIATE EFFECTS, CONTRADICTION CHANGES, etc.
return game_effects
Vector Database Integration
Query Flow
Convert user input to vector embedding
Query ChromaDB for top N similar entries
Build context from retrieved entries
Include in prompt alongside current state
Stored Content Types
Content Type |
Description |
|---|---|
Previous actions |
Historical player decisions and outcomes |
Entity descriptions |
Properties and relationships of game entities |
Historical events |
Past events and their consequences |
Contradiction patterns |
Common contradiction resolutions |
Best Practices
Consistency Management
Track all significant decisions and outcomes
Maintain a history of events and their consequences
Ensure new developments follow logically from established patterns
Context Building
Only include relevant information
Structure context hierarchically
Prioritize recent and directly related events
Error Handling
Have fallback options for unclear responses
Validate AI outputs against game constraints
Maintain game stability if AI service is unavailable
See Also
AI Integration - Conceptual explanation
Context Window API Reference - Context window management API
Configuration System - Configuration system
Architecture: The Embedded Trinity - System architecture