Agent memory
Use Agent Memory when your agent needs to remember information about returning callers – preferences, past bookings, or verification status – across separate conversations. Without it, every call starts from scratch.
How it works
Agent Memory is a key-value store attached to a user identifier (such as a phone number). Persist small, structured data between conversations so your agent can:
- Skip repeated questions for returning callers
- Greet callers by name or reference past interactions
- Resume interrupted conversations where the caller left off
- Track handoff history and resolution status
Memory is read at the start of each turn and cached for that turn. It is written at the end of a conversation – not on every turn.
You can:
- Read memory using
conv.memory.get("key") - Write memory by setting
conv.state["key"] = value(if the key is listed instate_keys)
Configuration
Enable Agent Memory
Agent Memory is configured by PolyAI, not self-served. Contact your PolyAI representative to enable it for your project. They will apply a configuration equivalent to the example below on your behalf:
Use the field table below to decide what to request – which state_keys to persist, whether you need analytics, and any identifiers to exclude.
Only include keys you explicitly need in state_keys. Memory is persisted at the end of the conversation, so only values set during the call are saved.
Using memory in functions
Reading memory
Use conv.memory.get("key") in any function to retrieve a previously stored value:
Writing memory
Set values in conv.state – they are persisted to memory at the end of the conversation if the key is listed in state_keys:
Only keys listed in state_keys in your config are persisted. Setting conv.state["key"] = value for a key not in state_keys will not save it to memory.
Full example: returning caller
Repeat caller analytics
When analytics_enabled is set to true, Agent Memory automatically tracks five metrics for each returning caller:
These metrics appear in your dashboards and can be used to track repeat caller patterns and resolution rates.
Repeat caller metrics reference the first interaction in the retention window, not the most recent — chaining calls would allow identification beyond the retention period.
Memory behavior
Timing
- Memory is fetched once per turn from the memory service and cached. Multiple
conv.memory.get()calls in the same turn do not trigger additional lookups. - Memory is written at the end of the conversation (after the end function executes). Values set in
conv.stateduring a function on turn 1 are not available throughconv.memoryon turn 2 of the same call.
Persistence
Each write acts as a patch – it updates or adds specific keys without removing existing ones. If conversation 1 writes {"cheese_type": "gouda"} and conversation 2 writes {"booking_day": "Friday"}, the next lookup returns both fields.
Expiry
All memory identifiers and fields expire at the end of your contracted retention period (for GDPR compliance). Retention periods vary by customer agreement – check your contract for specifics, or speak to your PolyAI representative. Once expired, data is automatically deleted and no longer accessible.
Identifiers
The current supported identifier is the caller’s phone number. This is set automatically – you do not need to configure it.
Additional identifiers (email, account ID) and cross-channel linking are planned.
Compliance
Before going live with Agent Memory, inform your clients so they can update privacy notices and confirm compliance with applicable data protection laws.
Key compliance considerations:
- Agent Memory is not intended for automated decision-making that significantly impacts end users
- Do not store sensitive PII in a single field – separate fields allow independent expiry
- Custom memory fields cannot be used to build caller profiles
- Timestamps stored in memory should be rounded to the hour to prevent linking calls across the retention window
- All data expires at the end of your contracted retention period
If your use case goes beyond analytics, call recovery, or personalisation, raise a request with your legal team before proceeding.
FAQ
Can I store nested JSON?
Values are stored as JSON-encoded strings. You can store structured data in a single field, but it is recommended to keep fields flat so they can expire independently – especially for anything containing PII.
Can I check if any memory exists?
Yes. Use Python’s in operator:
Can I prevent accidental overwrites?
Not natively – the latest write always wins. Guard against overwrites in your code:
When are memory writes committed?
Memory is persisted at the end of the conversation, after the end function executes. Values set in conv.state during a function are not available in conv.memory until the next call.
Does memory work across channels?
Currently, memory is scoped by phone number. Support for linking identifiers across channels (voice, SMS, webchat) is planned for future releases.
How do I get all stored memory fields?
Use the fields() method:
What read patterns does conv.memory support?
conv.memory is read-only and behaves like a mapping. Use whichever pattern is clearest for your case:
Writes go through conv.state for keys configured in state_keys; assigning directly to conv.memory is not supported.

