Skip to main content

Synap memory integration for LiveKit Agents — preload long-term memory, record turns, expose Synap as LLM tools

Project description

synap-livekit-agents

Synap integration for LiveKit Agents — preload long-term memory before a realtime call, record every committed turn back to Synap, and expose Synap search/store as LLM-callable function tools.

Install

pip install synap-livekit-agents

Requires livekit-agents>=1.0, maximem-synap>=0.2.0.

Quickstart

from livekit.agents import Agent, AgentSession, ChatContext
from maximem_synap import MaximemSynapSDK
from synap_livekit_agents import (
    preload_synap_context,
    attach_synap_recording,
    synap_search_tool,
    synap_store_tool,
)

sdk = MaximemSynapSDK(api_key="sk-...")

async def entrypoint(ctx):
    chat_ctx = ChatContext()
    await preload_synap_context(
        chat_ctx, sdk, user_id="alice", customer_id="acme",
    )

    agent = Agent(
        instructions="You are a helpful assistant.",
        chat_ctx=chat_ctx,
        tools=[
            synap_search_tool(sdk, user_id="alice", customer_id="acme"),
            synap_store_tool(sdk, user_id="alice", customer_id="acme"),
        ],
    )
    session = AgentSession(...)
    conversation_id = attach_synap_recording(
        session, sdk, user_id="alice", customer_id="acme",
    )
    await session.start(agent=agent, room=ctx.room)

Scope

  • preload_synap_context(chat_ctx, sdk, *, user_id, ...) — async helper. Fetches user-scoped context from Synap and prepends a single system-role ChatMessage to the ChatContext so the agent starts with long-term memory in scope. Read failures degrade silently — a Synap blip must never prevent a call from starting.
  • attach_synap_recording(session, sdk, *, user_id, ...) — wires AgentSession.on("conversation_item_added", ...) to sdk.conversation.record_message(). Handles both user and assistant turns (dispatched on item.role). Returns the conversation_id used for this call (auto-generated per call when absent). Callbacks never raise — write failures are logged and swallowed, consistent with LiveKit's sync-event contract.
  • synap_search_tool(sdk, *, user_id, ...) / synap_store_tool(sdk, *, user_id, ...) — factories that return FunctionTool instances registerable via Agent(tools=[...]). The LLM can invoke synap_search(query) to retrieve formatted context, or synap_store(content, category) to write a new memory.

Error policy

  • Reads (preload_synap_context, synap_search_tool) degrade gracefully. SDK failures log at ERROR, return an empty / "no relevant memory" placeholder, and the call proceeds.
  • Writes (attach_synap_recording, synap_store_tool) surface SynapIntegrationError via wrap_sdk_errors_async. The recording callback catches+logs (can't bubble an exception out of a sync LiveKit event emission without tearing down the session); the store tool lets the SynapIntegrationError propagate to the LLM runtime so the model sees a tool failure.

Constructor args

All helpers accept:

  • sdk: a configured MaximemSynapSDK
  • user_id: required — Synap memory is user-scoped
  • customer_id: optional customer/org scope; empty string means customer-less
  • conversation_id (recording only): optional explicit id; auto-generated when absent
  • mode (read helpers only): "accurate" or "fast", passed through to sdk.fetch
  • max_results (read helpers only): cap per fetch

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

maximem_synap_livekit_agents-0.1.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

maximem_synap_livekit_agents-0.1.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file maximem_synap_livekit_agents-0.1.1.tar.gz.

File metadata

File hashes

Hashes for maximem_synap_livekit_agents-0.1.1.tar.gz
Algorithm Hash digest
SHA256 817be44947e8255b4427ab91b7db8395613cb8d0f7b3fe988a978fae302a3190
MD5 71b0e9b95d68bb9feab376224b84702c
BLAKE2b-256 8626a8af427f32e5fffb95d8a79f8cccde3fea0d3729ede1a0c90fc1283abc77

See more details on using hashes here.

File details

Details for the file maximem_synap_livekit_agents-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for maximem_synap_livekit_agents-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6e9216a1f33cc8c62bbe2b60d6d341a1b5ae134e7c28d58236b6ead343ecc3fd
MD5 48b6182b97bbc715644c641db773affe
BLAKE2b-256 2b6495fa3a7610fd8e24a1155ac94605cbea1e945562ecb0e9aa59e33997a47e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page