Client Configuration

This page documents how to configure the memory-service-langchain package when connecting to Memory Service.

Configuration Approaches

The package supports two configuration styles:

Pass all connection settings directly to the constructor:

from memory_service_langchain import (
    MemoryServiceCheckpointSaver,
    MemoryServiceHistoryMiddleware,
    MemoryServiceResponseRecordingManager,
    MemoryServiceProxy,
)

checkpointer = MemoryServiceCheckpointSaver(
    base_url="http://memory-service:8082",
    api_key="my-agent-key",
)

history = MemoryServiceHistoryMiddleware(
    base_url="http://memory-service:8082",
    api_key="my-agent-key",
)

recording_manager = MemoryServiceResponseRecordingManager(
    base_url="http://memory-service:8082",
    api_key="my-agent-key",
    grpc_target="memory-service:8082",
)

proxy = MemoryServiceProxy(
    base_url="http://memory-service:8082",
    api_key="my-agent-key",
)

This approach keeps your code self-contained and testable — no hidden dependencies on the process environment.

Use the from_env() class method to read configuration from MEMORY_SERVICE_* environment variables:

checkpointer = MemoryServiceCheckpointSaver.from_env()
history = MemoryServiceHistoryMiddleware.from_env()
recording_manager = MemoryServiceResponseRecordingManager.from_env()
proxy = MemoryServiceProxy.from_env()

You can override individual settings while reading the rest from the environment:

checkpointer = MemoryServiceCheckpointSaver.from_env(
    base_url="http://custom-host:9090",
)

Environment Variable Reference

VariableDescriptionDefault
MEMORY_SERVICE_URLBase URL for REST API callshttp://localhost:8082
MEMORY_SERVICE_UNIX_SOCKETAbsolute path to a Unix domain socket (overrides URL for transport)(none)
MEMORY_SERVICE_API_KEYAPI key sent in the x-api-key header for agent authentication(none — must be set)
MEMORY_SERVICE_GRPC_TARGETExplicit gRPC target (e.g. host:port or unix:///path)Derived from MEMORY_SERVICE_URL
MEMORY_SERVICE_GRPC_PORTOverride the gRPC port when deriving from the base URLInferred from URL scheme (443 for HTTPS, 80 for HTTP)
MEMORY_SERVICE_GRPC_TIMEOUT_SECONDSTimeout for gRPC calls30
MEMORY_SERVICE_GRPC_REPLAY_TIMEOUT_SECONDSTimeout for gRPC replay calls (disabled if unset)(none)
MEMORY_SERVICE_GRPC_MAX_REDIRECTSMaximum number of gRPC redirects to follow3

Unix Domain Sockets

When MEMORY_SERVICE_UNIX_SOCKET is set (or unix_socket= is passed), REST calls use the socket transport and the logical base URL becomes http://localhost. gRPC derives a unix:///... target automatically.

See Unix Domain Sockets for a full walkthrough.

Authorization

All classes support an authorization_getter parameter — a callable that returns a Bearer <token> string for each request. This is typically wired up via install_fastapi_authorization_middleware(app), which reads the Authorization header from incoming requests and forwards it to Memory Service calls automatically.

See Getting Started for setup details.