Examples
Complete working examples demonstrating Mantis SDK tracing with different frameworks.
Available Examples
| Example | Framework | Features |
|---|---|---|
| Reasoning Agent | DSPy | Chain-of-thought, signatures, modules |
| Task Planner | Anthropic | Tool use, async, multi-turn |
| Research Assistant | Google ADK | Multi-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 framework2. 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
- Install Mantis SDK and the framework used by the example you want to run:
pip install mantisdk- Create a
.envfile 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.pyFor the Anthropic and Google ADK examples, install those framework packages instead:
pip install anthropic
pip install google-adkCopyable Examples
The full examples are included in this docs site: