Integrations

Agent frameworks

Drop-in wrappers for Claude Agent SDK, Vercel AI SDK, Mastra, LangChain, LangGraph, OpenAI Agents SDK, Google ADK.

If your agent is built on top of a framework rather than calling an LLM provider directly, use the framework-specific wrapper. Each one is a single function that returns an instrumented copy — every model call, tool call, and sub-agent dispatch is captured automatically.

Claude Agent SDK

import { Polarity, wrapClaudeAgentSDK } from "@polarityinc/polarity";
import * as claudeSDK from "@anthropic-ai/claude-agent-sdk";
 
const plr = new Polarity();
plr.initTracing();
 
const instrumented = wrapClaudeAgentSDK(claudeSDK, { keystone: plr });
 
await instrumented.run({
  prompt: "Refactor src/index.ts",
  allowedTools: ["Read", "Edit", "Bash"],
});

Captures: model calls, tool calls (Read/Edit/Bash/etc.), sub-agent dispatches, file edits.

Vercel AI SDK

TypeScript-only. There is no Python equivalent — for Python projects use auto-instrument or wrap the underlying provider client directly.
import { Polarity, wrapAISDK } from "@polarityinc/polarity";
import * as ai from "ai";
 
const plr = new Polarity();
plr.initTracing();
 
const instrumented = wrapAISDK(ai, { keystone: plr });
 
await instrumented.generateText({ model, prompt: "Hello" });

Captures: generateText, streamText, generateObject, streamObject, and tool calls.

Mastra

TypeScript-only. There is no Python equivalent today.
import { wrapMastraAgent } from "@polarityinc/polarity";
import { Agent } from "@mastra/core";
 
const agent = new Agent({ ... });
const instrumented = wrapMastraAgent(agent, { keystone: plr });

LangChain

LangChain ships its own callback system. Polarity hooks in via a callback manager:

import { ChatAnthropic } from "@langchain/anthropic";
 
const llm = plr.wrap(new ChatAnthropic({}), {
  langchainCallbackManager: true,
});

LangGraph

LangGraph uses LangChain's tracing under the hood, so the callback hook above covers it. For node-level visibility, wrap each node's LLM separately and use traced("node_name", ...) around the node function — every node becomes its own span with full parent/child structure.

OpenAI Agents SDK (Python)

from polarity import auto_instrument
 
auto_instrument()    # patches openai-agents at import time
 
from openai import OpenAI
from openai.agents import Agent
# Existing code — now traced.

See Auto-Instrument.

Google ADK / Google GenAI

import { wrapGoogleGenAI } from "@polarityinc/polarity";
import { GoogleGenerativeAI } from "@google/genai";
 
const genai = wrapGoogleGenAI(new GoogleGenerativeAI(apiKey), { keystone: plr });

Works with both Gemini (consumer API) and Vertex AI.

LiveKit

LiveKit Agents emit OpenInference-compatible OTel spans. Set the OTLP endpoint and you're done — see OpenTelemetry.

Picking the right wrapper

StackUse
Claude Agent SDKwrapClaudeAgentSDK
Vercel AI SDKwrapAISDK
MastrawrapMastraAgent
LangChain (JS or Py)plr.wrap(client, { langchainCallbackManager: true })
LangGraphLangChain hook + traced() per node
OpenAI Agents SDKautoInstrument()
Google ADK / GenAIwrapGoogleGenAI
Raw provider SDKplr.wrap(client) — see Tracing
Anything OTelPoint OTLP at https://api.plr.sh/otel/v1/traces — see OTel

Every wrapper here is opt-in and idempotent. None of them change the call signature of the framework they wrap — they just intercept the events for tracing.