loadMemory retrieval tool when needed.
Wiring
ConfigurelongTermMemory(...) on Agent.builder() to attach a memory service to the agent. Runner reads that service from the VeADK Java agent. If you did not already define a custom tool named loadMemory, VeADK Java automatically injects the official loadMemory tool so the model can retrieve past memories before answering.
Turn on autoSaveSession(true) when the agent should write new session content back to long-term memory. VeADK Java adds the session-saving callback and writes new user messages into the configured memory service.
Mem0 Memory
Mem0MemoryService is the managed long-term memory backend for Mem0. It extracts user messages from session events when saving, and loadMemory searches Mem0 by userId and query text when the model needs context.
Use a direct Mem0 API key:
DATABASE_MEM0_BASE_URL is not set, VeADK Java uses https://api.mem0.ai. If DATABASE_MEM0_REGION is not set, it uses cn-beijing.
Viking Memory
VikingMemoryService uses Volcengine Viking Memory as the long-term memory backend. It implements ADK Java’s BaseMemoryService, so it can be passed directly to Agent.builder().longTermMemory(...).
Async vs. Sync Writes
Mem0 usesASYNC write mode by default. A successful save means Mem0 accepted the request, but the new memory may not be immediately searchable. This is usually the lower-latency choice for chat flows.
Use synchronous mode when the next operation must depend on the memory that was just written:
Auto-save Policy
The default policy avoids saving after every single event. It saves when there is saveable content first, then skips later saves until the new-event or elapsed-time thresholds are reached. The defaults are10 new events and 60 seconds, and they can be overridden with environment variables:
autoSaveMemoryPolicy(...):
What to Store
Good long-term memory candidates:- Explicit, reusable user preferences such as language, format, or notification style.
- Confirmed long-lived facts such as project roles, common systems, or stable business constraints.
- Reusable task conclusions such as a default integration setting or a verified troubleshooting result.
- Passwords, tokens, SSH keys, API keys, or other credentials.
- Unmasked sensitive personal data, regulated data, or raw customer content.
- Temporary reasoning, raw tool output, one-off drafts, or unverified guesses.
- Complete chat transcripts. Long-term memory should store reusable facts, not act as a full session backup.
Notes
If expected memories are not retrieved, first check thatlongTermMemory(...) is configured, the same user ID is used, the session has been saved, and the current write mode allows the next turn to search newly written content. For Viking Memory, also confirm that the collection exists or that the configured credentials can manage collections.