Example: Context history with ApplicationStorage
This example answers an inbound call and uses ApplicationStorage to persist a small “memory” per caller across calls, then injects it into the next Deepgram Voice Agent session via agent.context.messages.
For a full breakdown of session setup, media bridging, barge-in, and event handling, see Example: Answering an incoming call.
⬇️ Jump to the Full VoxEngine scenario.
Prerequisites
- Set up an inbound entrypoint for the caller:
- PSTN number: https://voximplant.com/docs/getting-started/basic-concepts/phone-numbers
- WhatsApp: https://voximplant.com/docs/guides/integrations/whatsapp
- SIP user / SIP registration: https://voximplant.com/docs/guides/calls/sip
- Voximplant user: https://voximplant.com/docs/getting-started/basic-concepts/users (see also https://voximplant.com/docs/guides/calls/scenarios#how-to-call-a-voximplant-user)
- Create a routing rule that points the destination (number / WhatsApp / SIP username) to this scenario: https://voximplant.com/docs/getting-started/basic-concepts/routing-rules
- Store your Deepgram API key secret value in Voximplant
ApplicationStorageunderDEEPGRAM_API_KEY.
How cross-call history works
1) Pick a user identity and storage key
The example uses the inbound caller ID (call.callerid()) as a simple “user identity”, and stores history under a key like dgva_history:+15550123456.
Caller ID is not always a stable user ID
Caller ID can be missing, blocked, spoofed, or shared (for example, a PBX).
2) Load stored history and pass it to Deepgram
On call start, the scenario reads the stored JSON array from ApplicationStorage and passes it directly to the agent:
SETTINGS_OPTIONS.agent.context.messages: prior turns to preload into the session
3) Append new turns and persist on hangup
During the call, Deepgram emits Deepgram.VoiceAgentEvents.History events containing history items suitable for context.messages. The example appends those items to a rollingHistory array, trims it to a max size, and then saves it back to ApplicationStorage when the call ends.
Keep history small
ApplicationStorage values are size-limited (up to 2000 characters per key), so store only what you need (for example last 10–20 items) and enforce a TTL to avoid unbounded growth. See https://voximplant.com/docs/references/voxengine/applicationstorage#put.
Notes
See the VoxEngine API Reference for more details.