Frameworks
Six ways to instrument an agent, from bare Python to a fully patched framework runner. Pick the one that matches your stack — the install command pulls in the right extra, and the snippet is the minimal working integration.
The morse-ai package publishes with MHQ-541 — commands are final but not yet installable from
PyPI.
Python SDK (direct)
pip install morse-aiDirect instrumentation of any Python function via a context manager — no framework required.
import morse_ai
morse_ai.init() # reads MORSE_API_KEY from your environment
with morse_ai.run("my-agent") as r:
# your agent logic here
result = "Hello, world!"
r.record(success=True, outcome="completed", cost=0.04)LangChain
pip install morse-ai[langgraph] langchainAutomatic chain/agent tracing via a callback handler — no code inside the chain changes. If
langchain_core isn’t installed, MorseCallbackHandler is still importable but produces no
output (silent no-op).
import morse_ai
from morse_ai.adapters.langchain import MorseCallbackHandler
morse_ai.init() # reads MORSE_API_KEY from your environment
handler = MorseCallbackHandler(agent_name="my-agent")
# Add the callback to any LangChain chain or agent
chain = your_chain.with_config(callbacks=[handler])
chain.invoke({"input": "Hello, world!"})LangGraph
pip install morse-ai[langgraph] langgraphPer-node span capture plus automatic sub-agent topology from graph structure — uses the same
MorseCallbackHandler as LangChain. When both LangGraph and LangChain are importable, auto-detect
installs only the LangGraph adapter so a graph built on LangChain primitives doesn’t get duplicate
spans.
import morse_ai
from morse_ai.adapters.langchain import MorseCallbackHandler
morse_ai.init() # reads MORSE_API_KEY from your environment
handler = MorseCallbackHandler(agent_name="my-graph")
# Pass the callback when invoking your StateGraph
config = {"callbacks": [handler]}
result = your_graph.invoke({"messages": [...]}, config=config)OpenAI Agents
pip install morse-ai[openai_agents] openai-agentsRunner is patched automatically once you call install() — every agent run and handoff is
traced.
import morse_ai
from morse_ai.adapters.openai_agents import install
from agents import Agent, Runner
morse_ai.init() # reads MORSE_API_KEY from your environment
install() # patches Runner automatically — no further changes needed
agent = Agent(name="my-agent", instructions="You are a helpful assistant.")
result = Runner.run_sync(agent, "Hello, world!")Anthropic
pip install morse-ai[anthropic] anthropicWrap your client with wrap() — every messages.create call on the returned instance is traced,
including cache/token usage. No monkey-patching of the Anthropic class; only the wrapped instance
is instrumented, so an unwrapped client alongside it is unaffected.
import morse_ai
from morse_ai.adapters.anthropic import wrap
import anthropic
morse_ai.init() # reads MORSE_API_KEY from your environment
# Wrap your Anthropic client — every messages.create call is traced
client = wrap(anthropic.Anthropic())
with morse_ai.run("my-agent"):
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello, world!"}],
)wrap() is the explicit, recommended path. A module-level install() also exists (used by
zero-config auto-detect when you only set MORSE_API_KEY), but wrap() mirrors the TypeScript
SDK’s wrapAnthropic() and has no global state.
Claude Agent SDK
pip install morse-ai claude-agent-sdkclaude_agent_sdk.query is patched automatically once you call install() — existing code works
unchanged.
import morse_ai
from morse_ai.adapters.claude_agent_sdk import install
import claude_agent_sdk
morse_ai.init() # reads MORSE_API_KEY from your environment
install() # patches claude_agent_sdk.query automatically
# Your existing claude_agent_sdk code works unchanged
result = claude_agent_sdk.query("Hello, world!")Related
- Overview — auto-detect, adapter priority, and the silent-failure guarantee.
- Installation — create an API key and the minimal
init()call. - set_context() — attach cost-attribution dimensions to a trace.