Overview
Every conversation in Conversimple follows a predictable lifecycle with distinct phases. Understanding this lifecycle helps you build robust agents that handle all stages gracefully.Lifecycle Phases
Phase Details
1. Initializing
What happens:- Agent connects to Conversimple platform via WebSocket
- Tools are registered with the platform
- Agent enters ready state
- Validates authentication
- Registers your tool definitions
- Prepares for incoming conversations
2. Connecting
What happens:- User initiates WebRTC connection from browser
- Platform creates conversation session
- Your agent receives
conversation_startedevent
- Establishes WebRTC connection with user
- Sets up audio processing
- Connects to AI services
- Notifies your agent
3. Active
What happens:- User speaks, audio is processed
- AI generates responses
- Tools are called as needed
- Bidirectional audio streaming
- Speaking to the AI
- Listening to responses
- Pausing (silence)
- Interrupting AI mid-response
- Audio streaming and buffering
- Turn-taking and interruptions
- AI service communication
- Tool call routing
4. Processing
What happens:- Temporary state while tool executes or AI generates response
- May occur multiple times during active phase
- Audio input may be paused during tool execution
- Keep tool execution fast (under 3 seconds when possible)
- Use async tools for I/O operations
- Return partial results for long operations
- Provide progress updates if possible
5. Ending
What happens:- User or system initiates conversation termination
- Platform begins cleanup process
- Final messages exchanged
- User hangs up or closes browser
- User says goodbye (AI ends conversation)
- Timeout due to inactivity
- System error requiring termination
- Agent calls
stop()method
6. Ended
What happens:- All resources cleaned up
- Conversation data finalized
- Metrics recorded
- Connection fully terminated
- Closes WebRTC connection
- Stops audio processing
- Disconnects AI services
- Records analytics
Event Callbacks
Your agent can respond to lifecycle events:State Management
Conversation-Specific State
Each conversation should have isolated state:Persistent State
For data that needs to survive across conversations:Handling Edge Cases
Premature Disconnection
User disconnects unexpectedly:Multiple Conversations
Handle multiple simultaneous conversations:Timeout Handling
Detect and handle inactive conversations:Next Steps
Error Handling
Handle lifecycle errors gracefully
State Management
Advanced state management patterns