Skip to main content

tencentdb-agent-memory-sdk-python

Python SDK for the TencentDB Agent Memory v2 API.

Provides synchronous (MemoryClient) and asynchronous (AsyncMemoryClient) clients.

Distribution name: tencentdb-agent-memory-sdk-python (PyPI / pip install) Import path: tencentdb_agent_memory (Python module)

Install

# From PyPI (after publish)
pip install tencentdb-agent-memory-sdk-python

# From local .whl
pip install ./tencentdb_agent_memory_sdk_python-0.1.0-py3-none-any.whl

Quick Start

from tencentdb_agent_memory import MemoryClient

client = MemoryClient(
    endpoint="http://127.0.0.1:8420",
    api_key="your-api-key",
    service_id="your-memory-space-id",
)

# L0: append a conversation
result = client.add_conversation(
    session_id="sess-1",
    messages=[
        {"role": "user", "content": "Hello"},
        {"role": "assistant", "content": "Hi!"},
    ],
)
print(result["accepted_ids"])

# L1: search structured memories
hits = client.search_atomic(query="user preferences", limit=5)
print(hits["items"])

# L1: update a memory note
client.update_atomic(id="note-xxx", content="updated content", background="context")

# L2: list scenario files
scenarios = client.list_scenarios(path_prefix="")
print(scenarios["entries"])

# L2: read a scenario file
file = client.read_scenario("工作.md")
print(file["content"])

# L2: update a scenario file (must already exist)
client.write_scenario("工作.md", "# Updated content", summary="new summary")

# L3: read core memory (persona)
core = client.read_core()
print(core["content"])

# L3: write core memory
client.write_core("# User Profile\n...")

# Offload v2: send tool pairs for server-side L1 async processing (fire-and-forget)
client.offload_ingest(
    session_id="agent_sess_123",
    tool_pairs=[
        {"tool_name": "search", "tool_call_id": "call_1", "params": {"q": "..."}, "result": "...", "timestamp": "..."},
    ],
)

# Offload v2: server-side context compaction (sync wait for result)
compacted = client.offload_compact(
    session_id="agent_sess_123",
    messages=[...],
    ratio=0.7,
    context_window=128000,
)
print(compacted["messages"], compacted["report"])

# Recover an archived tool result referenced by a compacted message
ref = client.offload_read_ref(
    session_id="agent_sess_123",
    result_ref="offload/agent_sess_123/refs/call_1.md",
    query="relevant section",
    max_tokens=800,
)
print(ref["content"], ref["truncated"])

# Read memory pipeline artifacts (e.g. persona.md, scene_blocks/*.md)
raw = client.read_file("scene_blocks/工作.md")

Async Usage

import asyncio
from tencentdb_agent_memory import AsyncMemoryClient

async def main():
    async with AsyncMemoryClient(
        endpoint="http://127.0.0.1:8420",
        api_key="your-api-key",
        service_id="your-memory-space-id",
    ) as client:
        result = await client.search_atomic(query="preferences")
        print(result["items"])

asyncio.run(main())

API Methods

Layer Method Endpoint
L0 add_conversation() POST /v2/conversation/add
L0 query_conversation() POST /v2/conversation/query
L0 search_conversation() POST /v2/conversation/search
L0 delete_conversation() POST /v2/conversation/delete
L1 update_atomic() POST /v2/atomic/update
L1 query_atomic() POST /v2/atomic/query
L1 search_atomic() POST /v2/atomic/search
L1 delete_atomic() POST /v2/atomic/delete
L2 list_scenarios() POST /v2/scenario/ls
L2 read_scenario() POST /v2/scenario/read
L2 write_scenario() POST /v2/scenario/write
L2 rm_scenario() POST /v2/scenario/rm
L3 read_core() POST /v2/core/read
L3 write_core() POST /v2/core/write
Offload offload_ingest() POST /v2/offload/ingest
Offload offload_compact() POST /v2/offload/compact
Offload offload_read_ref() POST /v2/offload/read-ref
Offload offload_query_mmd() POST /v2/offload/query-mmd

Error Handling

All non-zero code responses raise TDAMError:

from tencentdb_agent_memory import TDAMError

try:
    client.read_core()
except TDAMError as e:
    print(f"code={e.code} message={e.message} request_id={e.request_id}")

Build & Pack

# Build wheel
python -m build
# → dist/tencentdb_agent_memory_sdk_python-0.1.0-py3-none-any.whl

# Or just wheel
pip wheel . --no-deps -w dist/

Dependencies

  • httpx>=0.24.0 (HTTP client with async support)

License

MIT

Metadata

Release files for tencentdb-agent-memory-sdk-python 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for tencentdb-agent-memory-sdk-python 0.1.0
File Interpreter ABI Platform Actions
tencentdb_agent_memory_sdk_python-0.1.0-py3-none-any.whl Python 3 none any Details for tencentdb_agent_memory_sdk_python-0.1.0-py3-none-any.whl

Release files / tencentdb_agent_memory_sdk_python-0.1.0-py3-none-any.whl

Download URL tencentdb_agent_memory_sdk_python-0.1.0-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
419caf695f47c7d400c9b3c9d65423ab8cc37c33c3dc98944b4327c92a51c925
BLAKE2b-256 checksum
How to use checksums
e2c912f96282fd40b2c98e25dc5460ca83ed806dd4994adf2e74915e151364f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for tencentdb-agent-memory-sdk-python 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page