API ReferenceOverview

API Reference

Complete API documentation for TraceCraft.

Modules

Quick Reference

Core Classes

from tracecraft import (
    TraceCraftRuntime,
    TraceCraftConfig,
    AgentRun,
    Step,
    StepType,
)
 
# Create runtime
runtime = TraceCraftRuntime(config=TraceCraftConfig())
 
# Create run
with runtime.run("my_run"):
    # Your code here
    pass

Decorators

from tracecraft import (
    trace_agent,
    trace_tool,
    trace_llm,
    trace_retrieval,
    step,
)
 
@trace_agent(name="agent")
async def agent(input: str) -> str:
    pass
 
@trace_tool(name="tool")
def tool(input: str) -> str:
    pass
 
@trace_llm(name="llm", model="gpt-4", provider="openai")
async def llm(prompt: str) -> str:
    pass
 
@trace_retrieval(name="retrieval")
async def retrieval(query: str) -> list[str]:
    pass

Exporters

from tracecraft.exporters import (
    ConsoleExporter,
    JSONLExporter,
    OTLPExporter,
    MLflowExporter,
    HTMLExporter,
)
 
# Use with init
tracecraft.init(
    exporters=[
        ConsoleExporter(),
        JSONLExporter(filepath="traces.jsonl"),
        OTLPExporter(endpoint="http://localhost:4317"),
    ]
)

Processors

from tracecraft.processors.redaction import RedactionProcessor, RedactionMode
from tracecraft.processors.sampling import SamplingProcessor
from tracecraft.processors.enrichment import EnrichmentProcessor
 
# PII redaction
redaction = RedactionProcessor(mode=RedactionMode.MASK)
 
# Sampling
sampling = SamplingProcessor(rate=0.1)
 
# Enrichment
enrichment = EnrichmentProcessor(
    static_attributes={"version": "1.0.0"}
)

Adapters

# LangChain
from tracecraft.adapters.langchain import TraceCraftCallbackHandler
handler = TraceCraftCallbackHandler()
 
# LlamaIndex
from tracecraft.adapters.llamaindex import TraceCraftSpanHandler
handler = TraceCraftSpanHandler()
 
# PydanticAI
from tracecraft.adapters.pydantic_ai import TraceCraftSpanProcessor
processor = TraceCraftSpanProcessor()
 
# Claude SDK
from tracecraft.adapters.claude_sdk import ClaudeTraceCraftr
tracer = ClaudeTraceCraftr(runtime=runtime)

Auto-Generated Documentation

The following pages contain auto-generated API documentation from source code docstrings:

Type Hints

TraceCraft is fully typed. Import types for static analysis:

from typing import TYPE_CHECKING
 
if TYPE_CHECKING:
    from tracecraft.core.runtime import TALRuntime
    from tracecraft.core.models import AgentRun, Step
    from tracecraft.core.config import TraceCraftConfig

Next Steps

Explore specific API modules:

  1. Core API
  2. Decorators API
  3. Exporters API
  4. Processors API
  5. Adapters API
  6. Configuration API