Myelin

LangChain

The SDK's LangChain integration provides a callback handler that captures tool calls and a toolkit that gives agents direct access to memory tools.

Installation

pip install myelin-sdk[langchain]

Requires langchain-core >= 0.3.0.

Session-based usage

Start a session yourself and pass the callback handler to your agent. Tool calls are captured automatically — no code changes to your agent.

from myelin_sdk import MyelinSession

async with MyelinSession.create(
    "handle support ticket",
    api_key="mk_live_...",
) as session:
    handler = session.langchain_handler()

    result = await agent.ainvoke(
        {"input": "Reset password for user 42"},
        config={"callbacks": [handler]},
    )

The session auto-finishes when the async with block exits. Check session.matched_workflow_id to see if a workflow was matched.

Autonomous usage

Use MyelinToolkit when you want the agent to manage memory on its own. The toolkit provides three tools — search, record, and finish — plus a linked callback handler.

from myelin_sdk.integrations.langchain import MyelinToolkit
from langchain.agents import create_react_agent

async with MyelinToolkit(api_key="mk_live_...") as tk:
    agent = create_react_agent(llm, tk.tools)

    result = await agent.ainvoke(
        {"input": "Deploy staging environment"},
        config={"callbacks": [tk.handler]},
    )

The agent decides when to call search, record, and finish. The handler captures all other tool calls in between. The toolkit auto-finishes any open session on exit.

When to use which

  • Session-based — You control when sessions start and end. Best for pipelines where you know the task up front.
  • Autonomous — The agent controls memory. Best for open-ended agents that handle varied tasks and decide what to search for.

Next steps