Use ChangeGraph
ChangeGraph provider router, in-repo Mastra-compatible runtime, packed context, and investigation workflows.
LLM providers
Core rule: deterministic code finds the evidence. Mastra agents and workflows explain a packed digest. They must never invent causality, files, or PRs, or change scorer ranks.
Orchestration is the in-repo Mastra-compatible runtime (src/lib/agents/mastra-runtime, package name @mastra/core). Agent.generate throws; model HTTP lives in src/lib/llm/providers.ts. AgentConfig.model is a string or a function that returns a string, not { url, id, apiKey }. Public APIs stay explain() and runInvestigation() so UI/MCP callers do not change.
Investigation always goes through workflows explain_incident and investigate_incident on that runtime. Configure at least one provider. Missing keys fail closed as not_configured.
Context packing SoT: Agent context packing. OSS catalog: Open source tools. Workflows run on the in-repo runtime; provider HTTP is the ChangeGraph router in src/lib/llm/providers.ts.
Configure a provider
Set one or more keys (see product .env.example):
| Env | Provider | Mastra model id example |
|---|---|---|
OPENAI_API_KEY | OpenAI (OPENAI_MODEL, default gpt-4o-mini) | openai/gpt-4o-mini |
ANTHROPIC_API_KEY | Anthropic (ANTHROPIC_MODEL) | anthropic/claude-3-5-haiku-latest |
XAI_API_KEY | xAI / Grok (XAI_MODEL) | xai/grok-2-latest |
GROQ_API_KEY | Groq (GROQ_MODEL, default llama-3.3-70b-versatile) | groq/llama-3.3-70b-versatile |
FIREWORKS_API_KEY | Fireworks (FIREWORKS_MODEL) | fireworks-ai/accounts/fireworks/models/gpt-oss-20b |
LLM_DEFAULT_PROVIDER | openai / anthropic / xai / groq / fireworks / compat | first configured key if unset |
LLM_MASTRA_MODEL | Full Mastra provider/model override | groq/llama-3.3-70b-versatile |
Pipeline (explain_incident workflow):
- Build the evidence package (scorer ranks frozen)
- Redact secrets, then pack compact JSON (caps on stacks, logs, paths, timeline)
- Optional Headroom compress (see below)
- Resolve a model id string and call the ChangeGraph provider router (
src/lib/llm/providers.ts) - Call the explain agent
- Validate structured output (drop invented PRs/files; copy ranks/scores from the package; soften absolute causation)
- Persist summary status:
ok|not_configured|error
Without a provider, the UI shows a configure an LLM provider state (not_configured). Scoring and evidence remain deterministic.
Headroom
Optional post-pack compress after redaction. The packer works without it. Packer + explain/investigate work without Headroom. If the proxy is down, the packed prompt is used (fallback: true).
| Variable | Role |
|---|---|
HEADROOM_URL | Proxy base (alias HEADROOM_BASE_URL). Unset = packer only |
HEADROOM_API_KEY | Optional bearer |
HEADROOM_TIMEOUT_MS | Default 2500 |
Upstream: github.com/headroomlabs-ai/headroom. Catalog: Open source tools.
Adding OpenAI-compatible providers
Any OpenAI-style /chat/completions endpoint:
LLM_COMPAT_BASE_URL=https://api.together.xyz/v1
LLM_COMPAT_API_KEY=...
LLM_COMPAT_MODEL=meta-llama/Llama-3.3-70B-Instruct-Turbo
LLM_DEFAULT_PROVIDER=compat
AgentConfig.model is a provider/model string or a function that returns one. The runtime does not accept an object model (url, id, apiKey). OpenAI-compatible vendors use the LLM_COMPAT_* settings above. Do not add a new core domain type per vendor.
What never goes to the model
- Integration secrets / tokens
- Raw webhook payloads with credentials
- Pretty-printed full evidence dumps (the packer sends a budgeted digest)
- Scorer internals beyond the packaged breakdown fields
Investigation workflows
| Capability | Role |
|---|---|
explain_incident | One-shot Mastra workflow over the packed package |
investigate_incident | Multi-step read-only Mastra workflow (on by default): load context → expand (capped tools) → pack → explain → validate |
Neither path may change deterministic scores. Set INVESTIGATION_AGENT_ENABLED=0 only to opt out of the multi-step workflow.
Failure modes
- Missing keys →
not_configured(configure a provider; not a success skip) - Provider error →
errorwith a safe message; UI still shows evidence - Hallucinated citations → stripped by validation
- Headroom down → packed prompt is used (
fallback: true). Explain/investigate do not depend on Headroom.
Engineering SoT: repo docs/MASTRA_AGENTS.md, docs/AGENT_CONTEXT.md, and docs/INTEGRATIONS_OSS.md. Checklist: repo docs/SECURITY.md.