Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content
Build with MuBit

LLM Provider Support

Which LLM client libraries mubit.learn auto-instruments, and what each integration captures.

mubit.learn.init() patches your existing LLM client classes in place — no wrapper code required. The table below lists the libraries that are auto-instrumented today.

ProviderPythonNode.js
OpenAIopenaiopenai
Anthropicanthropic@anthropic-ai/sdk
Google Geminigoogle-generativeai@google/generative-ai
LiteLLMlitellm
Vercel AI SDKai (via @mubit-ai/ai-sdk middleware)

What gets patched is concrete: the constructor of the provider's client class. Subsequent calls to .messages.create(), .chat.completions.create(), etc. flow through MuBit before and after the network call.

What auto-instrumentation captures

For every wrapped call:

  • Pre-call: relevant lessons retrieved from MuBit and injected into the system message (or as a synthetic system message if none exists).
  • The call itself: sent to the provider unchanged.
  • Post-call: the request, response, model name, latency, and token usage are recorded as a trace in the active session.

On session end (or auto_reflect=True), reflect() runs and extracts new lessons from the session's traces.

Verifying instrumentation

import anthropic, mubit.learn
mubit.learn.init(api_key="mbt_...", agent_id="my-agent")
client = anthropic.Anthropic()
print(client._mubit_learn_wrapped)  # True

A wrapped client carries _mubit_learn_wrapped = True. If False, the patch didn't take — usually because mubit.learn.init() was called after the client was constructed. Patch first, instantiate second.

Turning instrumentation off

There is no per-call opt-out today. To stop capturing entirely, call mubit.learn.uninstrument() — it restores the original LLM client behavior so subsequent calls flow straight to the provider:

import mubit.learn
 
mubit.learn.uninstrument()  # global — restores unpatched client behavior
resp = anthropic.Anthropic().messages.create(...)  # not captured

If you only need a few calls recorded (raw HTTP, an unsupported library, or a utility call you want logged on your terms), skip init()-style auto-instrumentation for those and capture them explicitly:

import mubit.learn
 
mubit.learn.capture(
    messages=[{"role": "user", "content": "estimate cost"}],
    response=resp_text,
    model="claude-3-5-sonnet",
)
ℹ️Note

A scoped per-call bypass context manager is not available yet. If you need system-utility calls (cost estimates, eval pipelines, retries) excluded from evidence without disabling instrumentation globally, open a feature request against mubit-sdk.

Provider-specific notes

OpenAI

  • Both sync (OpenAI) and async (AsyncOpenAI) clients are patched.
  • Streaming responses are captured incrementally; the full assembled output is recorded.
  • Tool/function call traces include the tool name and arguments.

Anthropic

  • Both sync (Anthropic) and async (AsyncAnthropic) clients are patched.
  • messages.create is wrapped; the deprecated completions.create is not.
  • Tool-use blocks are captured as part of the response trace.

Google Gemini

  • The google-generativeai client is patched on first import after init().
  • Multi-turn ChatSession instances inherit instrumentation from their parent client.

LiteLLM (Python only)

  • LiteLLM's unified completion() and acompletion() calls are patched.
  • The provider-specific client behind LiteLLM is not double-wrapped.

Vercel AI SDK (Node only)

  • Use mubitMemoryMiddleware from @mubit-ai/ai-sdk with wrapLanguageModel() rather than learn.init(). The Node learn API auto-instruments the lower-level provider SDKs but not the AI SDK abstraction.
  • Full example: see Framework integrations → Vercel AI SDK.

Adding a provider

Open an issue or a PR against mubit-sdk with the client class name and the call surface that should be wrapped (constructor + the methods that hit the network). Most providers take less than 50 lines of patch code; the existing per-provider patches (mubit/learn/_openai_learn.py, mubit/learn/_anthropic_learn.py) are the reference pattern to follow.