Skip to content

Walkthrough - 8 Runnable Examples

Step through Traigent's features with 8 progressive examples. All run in mock mode with cost approval pre-set for local dry runs - no provider API keys, no provider spend.

Setup

The bundled walkthrough/mock/* scripts self-select mock behavior for local demos. For your own tutorial code, prefer the in-code helper:

from traigent.testing import enable_mock_mode_for_quickstart

enable_mock_mode_for_quickstart()

For a genuinely free dry run outside the bundled scripts, combine mock mode with cost_approved=True in code or TRAIGENT_COST_APPROVED=true in the shell. Mock mode intercepts LiteLLM and LangChain calls only; raw openai.chat.completions.create(...) and anthropic.messages.create(...) calls can still hit real provider APIs.

The legacy TRAIGENT_MOCK_LLM=true env var remains available outside production for shell fixtures and backwards compatibility, but direct user-set activation emits DeprecationWarning.

Steps

# Run What you'll learn
1 python walkthrough/mock/01_tuning_qa.py Basic model + temperature optimization
2 python walkthrough/mock/02_zero_code_change.py Seamless mode — zero code changes to existing code
3 python walkthrough/mock/03_parameter_mode.py Explicit config access via traigent.get_config()
4 python walkthrough/mock/04_multi_objective.py Balance accuracy, cost, and latency
5 python walkthrough/mock/05_rag_parallel.py RAG optimization with parallel evaluation
6 python walkthrough/mock/06_custom_evaluator.py Define your own success metrics
7 python walkthrough/mock/07_multi_provider.py Compare OpenAI, Anthropic, Google in one run
8 python walkthrough/mock/08_privacy_modes.py Portal-backed routing vs offline=True zero-egress runs

What to expect

Each script prints trial results to the console. In mock mode the SDK intercepts the LLM call layer with canned/deterministic responses; the walkthrough scripts themselves use a helper called get_mock_accuracy to produce illustrative accuracy numbers (the helper is example-only, not part of the SDK runtime).

When you switch to real LLMs (do not call the helper, unset the legacy TRAIGENT_MOCK_LLM env var if present, set your API keys, and run the walkthrough/real/* scripts), your custom evaluator or the built-in LocalEvaluator accuracy calculator scores the real LLM outputs end-to-end — the SDK does not fabricate evaluator scores in either mode.

Note: The inert mock=... / mock_mode_config=... parameters (and MockModeOptions) were removed and now raise TypeError. Mock mode is activated by traigent.testing.enable_mock_mode_for_quickstart() in local code. The legacy TRAIGENT_MOCK_LLM=true env var remains for shell fixtures and emits DeprecationWarning when users set it directly.

Optional Extras

These are not part of the core 8-step path, but they complement it:

  • python walkthrough/mock/09_rag_multi_objective.py
  • python walkthrough/demo/rag_agent.py (requires OPENAI_API_KEY)
  • python walkthrough/demo/optimize_rag.py

Browse source

Browse source in the repository: walkthrough/mock/.