Agent Lifecycle
Understanding the complete lifecycle of agents from creation to deletion.
Lifecycle Overview
Every agent goes through distinct phases. Understanding these phases helps you build reliable integrations and handle edge cases gracefully.
Created
An agent is created via the REST API. At this point, the agent exists in the database but isn't doing anything yet. It's waiting for a client to connect.
- Query agent details via REST
- Update agent configuration
- Delete the agent
- Connect via WebSocket
- Send messages to agent
- Receive responses
- Join voice calls
- Store the agent ID securely
- Note the
expiresAtif using TTL - Connect promptly to start interacting
ttlSeconds when creating, the agent will automatically expire and be deleted after that duration, even if never connected.Connected
A WebSocket connection is established between your client and the agent. The agent is now ready to receive events and respond. Multiple clients can connect to the same agent simultaneously.
Requirements
- Send messages and events
- Receive agent responses
- Monitor agent status
- Join voice calls (HUMA-0.1)
- Disconnect gracefully
- Change agent type
- Transfer to another user
- Handle connection errors
- Implement reconnection logic
- Listen for status changes
- Track expiration time
Possible Connection Errors
MISSING_AGENT_IDNo agent ID providedUNAUTHORIZEDInvalid or missing API keyAGENT_NOT_FOUNDAgent doesn't existAGENT_EXPIREDTTL has elapsedActive (Processing)
The agent is actively processing events and responding. During this phase, the agent cycles through different processing states as it works on your requests.
- Send additional events (queued)
- Receive status updates
- Receive tool call requests
- Send tool results back
- Interrupt with new context
- Change agent configuration mid-processing
- Cancel already-executed actions
- Show status indicators to users
- Handle tool calls promptly
- Implement cancellation for long tools
- Update your UI based on status
Voice Calls (HUMA-0.1 Only)
HUMA-0.1 agents can join Daily.co voice calls for real-time spoken interaction. This is a sub-phase within the Active state - the agent must be connected before joining a call.
Room Events
room_joinedJoined successfullyroom_leftLeft the callparticipant_joinedUser joinedAudio Events
transcriptUser speech textspeakAgent speech textvad_startVoice detectedtranscriber_fatal_error, the speech recognition has failed permanently. The agent will disconnect from the call. You should notify the user and optionally reconnect.Ended
The agent's lifecycle ends either through explicit deletion, expiration, or cleanup. Once ended, the agent cannot be recovered.
You call DELETE /api/agents/:id. Best practice: disconnect clients first.
The ttlSeconds has elapsed. Clients receive AGENT_EXPIRED.
Inactive agents may be cleaned up by the system. Configure retention policies as needed.
Expiration Sequence
If in a voice call, the agent leaves the call automatically
All connected clients receive an AGENT_EXPIRED error
All WebSocket connections are terminated
The agent is permanently deleted from the database
- Create a new agent
- Handle the expiration gracefully in UI
- Reconnect to the agent
- Recover agent data
- Extend the TTL after expiration
Best Practices
Connection Management
- Always handle connection errors and implement reconnection logic
- Check
expiresAtbefore connecting - Gracefully handle disconnections in your UI
Time-Limited Agents
- Choose TTL that covers your expected session plus buffer time
- Consider creating a new agent before expiration for seamless handoff
- Use TTL for temporary sessions that auto-cleanup
Voice Calls
- Always send
leave-daily-roombefore disconnecting - Handle transcriber errors by notifying users
- Monitor participant events to show who's in the call
Resource Cleanup
- Delete agents when no longer needed
- Track agent creation in long-running apps
- Prefer TTL for temporary/ephemeral sessions