Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.mutagent.io/llms.txt

Use this file to discover all available pages before exploring further.

Python Integrations

MutagenT provides first-class Python support for tracing AI applications. The Python ecosystem consists of a core tracing SDK and framework-specific adapters that automatically instrument your LLM calls.

Architecture

Requirements

Package Status

PackageVersionStatusDescription
mutagent-sdk0.1.1Available on PyPIFull Python SDK — prompts, datasets, evaluations, tracing
mutagent-anthropic0.1.0Coming soonAutomatic tracing for the Anthropic Python SDK
mutagent-openai0.1.0Coming soonAutomatic tracing for the OpenAI Python SDK
mutagent-langchain0.1.0Coming soonCallback handler for LangChain
mutagent-langgraph0.1.0Coming soonCallback handler for LangGraph workflows

Quick Setup

1

Install the SDK

pip install mutagent-sdk
The mutagent-sdk package includes the core tracing module (mutagent.tracing).
2

Install a framework adapter

The framework adapter packages are coming soon to PyPI. The install commands below will work once published.
pip install mutagent-anthropic
pip install mutagent-openai
pip install mutagent-langchain
pip install mutagent-langgraph
Each adapter auto-installs its framework dependency and tracing transport.
3

Initialize tracing

from mutagent.tracing import init_tracing

init_tracing(api_key="mt_xxxxxxxxxxxx")
Or set MUTAGENT_API_KEY in your environment and omit the argument.

Environment Variables

VariableDescriptionDefault
MUTAGENT_API_KEYYour MutagenT API keyRequired
MUTAGENT_SERVER_URLMutagenT API client endpoint (Python SDK client only)http://localhost:3003
The init_tracing function uses its own endpoint kwarg (defaulting to https://api.mutagent.io) and does not read MUTAGENT_SERVER_URL. Set endpoint explicitly when calling init_tracing for production.
import os
from mutagent.tracing import init_tracing

init_tracing(
    api_key=os.environ["MUTAGENT_API_KEY"],
    endpoint="https://api.mutagent.io",
)

Configuration Options

The init_tracing function accepts the following parameters:
ParameterTypeDefaultDescription
api_keystrRequiredMutagenT API key
endpointstrhttps://api.mutagent.ioAPI endpoint URL
environmentstr | NoneNoneEnvironment name (e.g., production, staging)
batch_sizeint10Number of spans to buffer before flushing
batch_interval_msint5000Flush interval in milliseconds
debugboolFalseEnable debug logging

Core SDK: Manual Spans

The mutagent.tracing module also exposes a low-level API for creating custom spans when you need fine-grained control:
from mutagent.tracing import (
    init_tracing,
    start_span,
    end_span,
    SpanOptions,
    SpanEndOptions,
    SpanKind,
    SpanStatus,
    SpanIO,
    SpanMetrics,
)

init_tracing(api_key="mt_xxxxxxxxxxxx")

# Start a span
span = start_span(SpanOptions(
    kind="chain",
    name="my-pipeline",
    input=SpanIO(text="input data"),
))

# Do work...

# End the span
if span:
    end_span(span, SpanEndOptions(
        status="ok",
        output=SpanIO(text="output result"),
        metrics=SpanMetrics(
            model="gpt-4",
            provider="openai",
            input_tokens=150,
            output_tokens=50,
            total_tokens=200,
        ),
    ))

Available Span Kinds

KindValueUse Case
LLM_CHATllm.chatChat completions
LLM_COMPLETIONllm.completionText completions
LLM_EMBEDDINGllm.embeddingEmbedding generation
CHAINchainSequential pipelines
AGENTagentAgent execution
GRAPHgraphGraph workflows
NODEnodeGraph nodes
EDGEedgeGraph edges
WORKFLOWworkflowMulti-step workflows
MIDDLEWAREmiddlewareMiddleware layers
TOOLtoolTool invocations
RETRIEVALretrievalRAG retrieval
RERANKrerankReranking operations
GUARDRAILguardrailSafety checks
CUSTOMcustomCustom operations

Shutdown

Always call shutdown_tracing() before your application exits to flush remaining spans:
import asyncio
from mutagent.tracing import shutdown_tracing

# At application shutdown (shutdown_tracing is async)
asyncio.run(shutdown_tracing())
The SDK registers an atexit handler that flushes remaining spans automatically. Calling shutdown_tracing() explicitly is recommended for long-running applications or serverless functions.

Framework Guides

Anthropic

wrap_anthropic(client) — zero-change tracing for Claude

OpenAI

MutagentOpenAI — drop-in OpenAI client replacement

LangChain

Callback handler for LangChain chains and agents

LangGraph

Callback handler for LangGraph workflows

TypeScript Equivalents

If you are using TypeScript/Node.js, see the TypeScript integration guides for the equivalent packages:
Python PackageTypeScript Equivalent
mutagent-sdk (tracing)@mutagent/sdk
mutagent-openai@mutagent/openai
mutagent-langchain@mutagent/langchain
mutagent-langgraph@mutagent/langgraph