Examples
Overview

Examples

Complete working examples demonstrating Mantis SDK tracing with different frameworks.

Available Examples

ExampleFrameworkFeatures
Reasoning AgentDSPyChain-of-thought, signatures, modules
Task PlannerAnthropicTool use, async, multi-turn
Research AssistantGoogle ADKMulti-tool, sessions

Common Patterns

All examples follow these patterns:

1. Initialize Tracing First

from dotenv import load_dotenv
load_dotenv()
 
# Initialize BEFORE importing framework
import mantisdk.tracing as tracing
tracing.init(service_name="my-agent", instrument_default=False)
tracing.instrument(names=["framework_name"])
 
# NOW import framework
import framework

2. Setup Function

def setup_tracing(trace_to_console: bool = False):
    from mantisdk.tracing.exporters.insight import is_insight_configured
 
    exporters = []
    if is_insight_configured():
        exporters.append(tracing.insight_exporter())
        print("[Tracing] Insight exporter configured")
 
    if trace_to_console:
        from opentelemetry.sdk.trace.export import ConsoleSpanExporter
        exporters.append(ConsoleSpanExporter())
 
    tracing.init(
        service_name="my-agent",
        exporters=exporters if exporters else None,
        instrument_default=False,
    )
    tracing.instrument(names=["framework_name"])

3. Clean Shutdown

if __name__ == "__main__":
    try:
        main()
    finally:
        tracing.shutdown()

Running the Examples

Prerequisites

  1. Install Mantis SDK and the framework used by the example you want to run:
pip install mantisdk
  1. Create a .env file or export the same variables in your shell:
INSIGHT_HOST=https://insight.withmetis.ai
INSIGHT_PUBLIC_KEY=pk-lf-your-key
INSIGHT_SECRET_KEY=sk-lf-your-key
 
# Framework-specific keys
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=...

Install Dependencies

Each example page lists the framework dependencies it needs. Install the matching framework package, then copy the example into a local Python file:

pip install dspy-ai
python reasoning_agent.py

For the Anthropic and Google ADK examples, install those framework packages instead:

pip install anthropic
pip install google-adk

Copyable Examples

The full examples are included in this docs site: