Skip to content

Traigent Quick Reference Guide

Everything you need to run and adapt examples quickly.

Common commands

# Install from repo root (includes example deps)
pip install "traigent[recommended]"

# Auto-mocks when ANTHROPIC_API_KEY is unset
python examples/core/simple-prompt/run.py

# With real LLMs
export ANTHROPIC_API_KEY="your-key" # pragma: allowlist secret
export OPENAI_API_KEY="your-key" # pragma: allowlist secret
python examples/core/multi-objective-tradeoff/run_openai_backend_smart.py

Core optimize pattern

import traigent

@traigent.optimize(
    eval_dataset="examples/datasets/simple-prompt/evaluation_set.jsonl",
    configuration_space={"model": ["claude-haiku-4-5-20251001"], "temperature": [0.0, 0.7]},
    objectives=["accuracy"],
)
def summarize(text: str) -> str:
    cfg = traigent.get_config()
    return f"Summary | model={cfg['model']}"  # call your LLM here

Optimization routing

  • Omit routing settings for the default smart optimizer and portal sync.
  • algorithm="grid" / "random" runs local search and still syncs results when authenticated.
  • Smart algorithms such as bayesian, tpe, optuna_tpe, nsga2, and cmaes are cloud-only and hard-error if unavailable.
  • offline=True is the zero Traigent backend egress path and does not sync to the portal.
  • Result provenance: result.source is cloud_brain, local_fallback, explicit_local, or offline.
  • Mock: call traigent.testing.enable_mock_mode_for_quickstart() in local tutorial code.

Quick knobs

  • Constrain cost: smaller max_trials, cheaper models, constraints={"cost_per_call": "<0.01"}.
  • Faster runs: discrete search spaces, early_stopping=True, sensible trial_concurrency.
  • Safer outputs: use safety-guardrails example as a template.

Directory cheat sheet

examples/
|- core/              # Start here (mockable)
|- advanced/          # Deep dives and patterns
|- integrations/      # CI/CD and partner workflows
|- datasets/          # Shared evaluation data
`- gallery/           # Browser gallery and inline demo assets

Troubleshooting highlights

  • ModuleNotFoundError: traigent -> pip install "traigent[recommended]".
  • API key not found -> call traigent.testing.enable_mock_mode_for_quickstart() in local tutorial code or export keys.
  • Slow runs -> lower max_trials or narrow the configuration space.
  • Empty results -> verify dataset paths in eval_dataset.

Need more? See Start Here, Examples Guide, or Troubleshooting.