This document explains how to use the new AI-powered agent conversation system in the Chirper Simulation, which integrates the @chirper/agent package with all its plugins.
The agent service provides sophisticated AI-powered conversations between simulation agents using:
- Action Plugin: Dice-based action resolution with success/failure outcomes
- Memory Plugin: Persistent memory formation and recall
- Mood Plugin: Sims-style needs and mood system
- Relationship Plugin: Dynamic relationship tracking between agents
- Alliance Plugin: Group formation and betrayal mechanics
Agent Store (Source of Truth)
↓
ConversationService (New Service)
↓
@chirper/agent (AgentService + All Plugins)
↓
Phaser Bridge (Visual Updates)
import { initializeConversationService } from './services/agent';
// Initialize with your OpenAI API key
initializeConversationService('your-openai-api-key');import { conversationService } from './services/agent';
// Start conversation between two agents
const result = await conversationService.startConversation('agent_0', 'agent_12');
console.log(`Conversation ended: ${result.reason}`);// Listen to speech events
conversationService.on('speech', (event) => {
console.log(`${event.data.agentName}: "${event.data.content}"`);
});
// Listen to action events
conversationService.on('action', (event) => {
console.log(`${event.data.agentName} ${event.data.action} - ${event.data.success ? 'SUCCESS' : 'FAILURE'}`);
});Agents can attempt actions with dice rolls:
<action>
<emoji>🏃</emoji>
<description>Running toward the exit</description>
<difficulty>12</difficulty>
</action>- Difficulty: 1-20 scale (1=very easy, 20=very hard)
- Dice Roll: d20 against difficulty
- Outcomes: LLM-generated contextual results
Agents form memories of significant interactions:
- Conversation Memories: Summaries of interactions
- Action Memories: Important successes/failures
- Relationship Memories: Changes in feelings toward others
- Decay System: Memories fade over time but important ones persist
Sims-style needs that affect behavior:
- Energy: Physical tiredness
- Hunger: Need for food
- Social: Need for interaction
- Hygiene: Personal cleanliness
- Comfort: Physical comfort
- Fun: Entertainment needs
- Bladder: Bathroom needs
- Environment: Satisfaction with surroundings
Dynamic relationships between agents:
- Scale: -100 (hostile) to +100 (loyal)
- Action-Based: Relationships change based on actions
- Bidirectional: Each agent has feelings about every other agent
- Context-Aware: Considers roles (prisoner vs guard)
Group dynamics and partnerships:
- Alliance Types: Temporary, permanent, secret, conditional
- Loyalty Tracking: 0-100 loyalty scale
- Betrayal Mechanics: Agents can betray alliances
- Group Actions: Coordinated activities between allies
The service uses the existing agent store as the single source of truth:
// Agent data is automatically synced
const agentData = getAgentData('agent_0');
console.log(agentData.memories); // Updated by MemoryPluginVisual updates happen automatically via the Phaser bridge:
- Speech Bubbles: Automatically displayed for agent speech
- Action Results: Shown as temporary speech bubbles
- Position Updates: Agent movements reflected in game
- Emoji Updates: Mood and action indicators
Use the ConversationManager component for control:
import { ConversationManager } from './components/ConversationManager';
function App() {
return (
<div>
<ConversationManager />
{/* Your other components */}
</div>
);
}startConversation(agent1Id, agent2Id, ...additionalAgents): Start a conversationisAgentInConversation(agentId): Check if agent is busygetActiveConversations(): Get list of active conversationsstopAllConversations(): Force stop all conversations
'speech': Agent spoke something'action': Agent attempted an action'move': Agent moved position'agent_updated': Agent properties changed'started': Conversation began'ended': Conversation completed
// Start a random conversation
const result = await startRandomConversation();
// Initialize with API key
initializeConversationService('sk-...');const conversationService = new ConversationService({
maxMessages: 6, // Messages per conversation
debug: true, // Enable debug logging
conversationCooldown: 20000 // 20 second cooldown
});Each plugin can be configured when creating the AgentService:
// Example: Custom mood settings
.use(new MoodPlugin({
decayRate: 1.0,
criticalThreshold: 20,
enableUrgentBehaviors: true
}))Agents are typed as any for flexibility, but typically contain:
{
id: string;
name: string;
role: 'prisoner' | 'guard';
personality: string;
position: { x: number; y: number };
// Plugin-specific fields (initialized automatically)
memories: Memory[];
relationships: Map<string, number>;
mood: MoodState;
alliances: Alliance[];
}- Collision Detection: Agents collide in Phaser
- Service Check: Verify agents aren't busy
- Conversation Start: Create AgentService with plugins
- LLM Generation: Agents take turns speaking
- Plugin Processing: Actions, memories, relationships updated
- Visual Updates: Speech bubbles, positions updated in Phaser
- Natural Ending: Conversation concludes based on content
- Memory Formation: Agents remember the interaction
-
"Cannot find module '@chirper/agent'"
- Ensure the agent package is properly installed
- Check import paths are correct
-
"OpenAI API key not provided"
- Initialize the service with a valid API key
- Check environment variables
-
"Agents already in conversation"
- Check if agents are busy before starting
- Wait for conversations to complete
Enable debug logging to see detailed conversation flow:
const conversationService = new ConversationService({
debug: true
});- Always Initialize: Set up the API key before starting conversations
- Check Availability: Verify agents aren't busy before starting
- Handle Errors: Wrap conversation starts in try-catch blocks
- Monitor Events: Listen to events for real-time updates
- Respect Cooldowns: Don't spam conversation starts
- Type Safety: Use TypeScript interfaces for better development experience
- Custom Plugins: Add simulation-specific plugins
- Conversation Templates: Pre-defined conversation scenarios
- Advanced AI Models: Support for different LLM providers
- Conversation Analytics: Detailed conversation statistics
- Save/Load: Persist agent states between sessions
For issues or questions:
- Check the console for debug messages
- Verify API key configuration
- Ensure all dependencies are installed
- Review the agent store data structure
- Test with simple two-agent conversations first