Skip to main content

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
Duration: Less than a second Your agent:
Platform actions:
  • 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_started event
Duration: 1-2 seconds Your agent:
Platform actions:
  • 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
Duration: Varies (typically 2-30 minutes) Audio flow:
Your agent during active phase:
User actions:
  • Speaking to the AI
  • Listening to responses
  • Pausing (silence)
  • Interrupting AI mid-response
Platform manages:
  • 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
Duration: Varies by tool complexity Your agent:
Best practices:
  • 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
Duration: Less than a second Termination triggers:
  • User hangs up or closes browser
  • User says goodbye (AI ends conversation)
  • Timeout due to inactivity
  • System error requiring termination
  • Agent calls stop() method
Your agent:

6. Ended

What happens:
  • All resources cleaned up
  • Conversation data finalized
  • Metrics recorded
  • Connection fully terminated
Duration: Instantaneous Platform cleanup:
  • Closes WebRTC connection
  • Stops audio processing
  • Disconnects AI services
  • Records analytics
Your agent cleanup:

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