Skip to main content
tos_context is a VeADK long-term memory backend that stores and retrieves memories with the ContextBucket capability of Volcengine TOS. Memory inference and retrieval run in the managed service, so you do not need to deploy a vector database or configure an embedding model. Each index maps to one ContextBucket. Within that bucket, every runtime user_id maps to an independent ContextSet. Use the same user_id across sessions when the application must recall a user’s existing memories.

When to use

  • You want a managed long-term memory service instead of operating a vector database;
  • You need to isolate memories by user_id;
  • You have a Volcengine account, ContextBucket service endpoints, and the required service permissions.

Prerequisites

  • VeADK 1.0.9 installed;
  • Your Volcengine account ID, the ContextBucket control endpoint, and the data endpoint for the target region;
  • AK/SK credentials that can access and create ContextBuckets and ContextSets and can write and search memories, or an IAM role with the same permissions for the AgentKit or VeFaaS runtime;
  • Network access to the configured control and data endpoints.
ContextBucket availability, control endpoints, and IAM permissions are provided by the TOS service and are separate from ordinary TOS Bucket permissions. If your account has not received ContextBucket enablement information, confirm the available regions, control endpoint, and least-privilege policy through your Volcengine service support channel before configuring this page.

Install the dependency

ContextBucket requires TOS SDK tos>=2.9.4b1. VeADK’s base dependencies also permit earlier TOS SDK releases, so upgrade the SDK separately in the VeADK environment:
The version constraint explicitly includes the 2.9.4b1 pre-release, so pip does not require a separate --pre option. If your package manager or lockfile policy rejects pre-release dependencies, allow this dependency with the tool’s corresponding setting and regenerate the lockfile. Verify the installed version with:

Configure credentials and endpoints

The following example supplies credentials through environment variables so that AK/SK values are not stored in code or configuration files:
Also set VOLCENGINE_SESSION_TOKEN when using temporary STS credentials. If AK and SK are not both provided, the backend uses the IAM role credentials of the AgentKit or VeFaaS runtime instead. Providing only AK or only SK does not form a valid credential pair.
The first initialization checks for and may create a ContextBucket. The first save or search for each user_id also checks for and may create a ContextSet. These operations create or access cloud resources and send session content to TOS. Before running the example, confirm that account permissions, costs, data processing, and retention policies meet your requirements.

Usage

The following example saves one session and then retrieves the same user’s long-term memory from a new session. Before running it, configure model credentials as described in Model configuration.
After a successful run, the second session can retrieve the peanut allergy saved by the same user_id in the first session. If the ContextBucket named support-memory does not exist, initialization creates it. The first save also creates a memory-enabled ContextSet for user-42.

Pass backend configuration explicitly

In addition to environment variables, you can use backend_config for non-secret connection settings. The backend must ultimately receive a valid index; set it on the outer LongTermMemory object and VeADK fills it into the backend configuration.

Parameters

LongTermMemory parameters

Backend configuration

TOSContextBucketConfig parameters

Save option

Pass infer=False to await memory.add_session_to_memory(session, infer=False) to control whether ContextBucket performs memory inference when saving content.

Environment variables

Failure behavior

Limitations

  • ContextBucket names must be 3–63 characters, contain only lowercase letters, digits, and hyphens, and must not start or end with a hyphen.
  • The minimum compatibility baseline, 2.9.4b1, is a pre-release TOS SDK version. Revalidate compatibility when upgrading the TOS SDK or VeADK.
  • An existing ContextSet must have the memory scene enabled; otherwise saves and searches fail.
  • Memories are strictly isolated by user_id. If the application changes a user’s user_id, new sessions cannot retrieve memories from the previous ContextSet.
  • This backend does not support get_user_profile(user_id); the method returns an empty string.
Last modified on September 19, 2026