Skip to content

feat: run FAQ generation on the Claude Platform instead of OpenRouter - #387

Merged
neuromechanist merged 5 commits into
feature/issue-360-epic-anthropic-platformfrom
feature/issue-386-faq-anthropic
Sep 17, 2026
Merged

neuromechanist merged 5 commits into
feature/issue-360-epic-anthropic-platformfrom
feature/issue-386-faq-anthropic

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Closes #386.

Problem

FAQ generation was the last server-side route to OpenRouter. src/knowledge/faq_summarizer.py built both of its agents with create_openrouter_llm, whose key defaults to the platform's own OPENROUTER_API_KEY. It is not dead code: src/api/scheduler.py:240 calls summarize_threads from the automated sync schedule, and src/cli/sync.py:861 exposes it from the CLI.

That contradicted .env.example, which said OpenRouter "is only reached when a caller brings their own OpenRouter key ... or a community sets its own openrouter_api_key_env_var". FAQ generation was a fourth case, and the one that kept a platform-side OpenRouter key mandatory rather than optional.

Change

Both agents now use create_anthropic_llm, on the configured path and the no-config fallback. Thinking is off for both: the evaluation agent depends on temperature: 0.0 for deterministic scoring, and temperature is only forwarded when thinking is off; neither role needs reasoning tokens across thousands of calls.

src/assistants/eeglab/config.yaml is the only community with a faq_generation block. Its evaluation agent moves from qwen/qwen3-235b-a22b-2507 on DeepInfra/FP8 to claude-haiku-4-5. Its summary agent stays on Haiku rather than moving up to Sonnet 5, because claude-sonnet-5 rejects temperature, so promoting it would silently discard the 0.0/0.1 split the two roles are built around.

AgentConfig.provider is now inert; the Claude Platform has no routing layer. It still loads so no config.yaml breaks, and _warn_if_provider_ignored logs when one is set. A community that chose FP8 quantization for cost reasons should hear that it stopped applying, not find out from a bill.

The same-model warning was inverted by the migration. It fired whenever both agents named the same model and advised "use a faster/cheaper model for evaluation_agent" -- but with two offered models, Haiku for both is the cheapest valid configuration, so the warning would fire on the recommended setup. It now warns only when the evaluation agent, the one making thousands of calls, uses the expensive model.

Also fixed: summary_model_name is normalized before being stored, so a config still carrying a legacy id records the id that was actually billed and that src/metrics/cost.py prices; and two docstrings that predate the migration (default_model said "OpenRouter format" with an anthropic/claude-3.5-sonnet example, default_model_provider did not say it was OpenRouter-only).

Cost

The evaluation agent moves from a quantized open model to claude-haiku-4-5 at $1.00 / $5.00 per 1M tokens, and it is the agent that scores every thread. Haiku is the floor among offered models, so there is no cheaper option available; the quality_threshold: 0.7 still keeps roughly 85% of threads away from the summary agent. Flagging it explicitly because it is a real increase on the highest-volume call in the pipeline, not a neutral substitution.

Tests

8 new tests, no new mocks.

  • test_shipped_faq_configs_name_offered_claude_models walks the registry rather than hardcoding community names, so a community added later cannot reintroduce an unservable model. Verified load-bearing: reverting only eeglab/config.yaml makes it fail with ValueError: Model 'qwen/qwen3-235b-a22b-2507' is not available.
  • test_summarizer_does_not_reach_for_the_openrouter_factory asserts against the module source, because the import is function-local and there is no module attribute to inspect.
  • Two caplog tests for _warn_if_provider_ignored, calling the real function.
  • Four tests for the corrected role warning, including that a stale provider still loads.

tests/test_integration/test_mailman_e2e.py had its patch target repointed. Verified that target is load-bearing: aiming it back at create_openrouter_llm fails 2 of 4 tests (assert 0 == 1).

uv run pytest tests/ -q -m "not llm and not integration and not network and not slow"
2090 passed, 13 skipped, 1 failed

The one failure is the pre-existing test_version_shows_version (Rich ANSI codes), which fails on the base branch too. ruff check and ruff format --check clean.

Pre-existing issue, not fixed here

The two test_mailman_e2e.py tests that exercise summarization drive MagicMock LLMs whose .invoke() returns canned content. That conflicts with the project's no-mocks rule, but it predates this PR and rewriting them into real paid llm-marked tests is a separate decision. This PR only repoints their patch target so they keep testing the pipeline they were written for.

FAQ generation was the last server-side route to OpenRouter. It ran from the
sync scheduler (src/api/scheduler.py:240) with no caller and no BYOK key, so
the platform needed its own OPENROUTER_API_KEY for the feature to work at
all, which contradicted .env.example's claim that OpenRouter is only reached
via a caller's key or a community's openrouter_api_key_env_var.

- faq_summarizer builds both agents with create_anthropic_llm, on the
  configured and the fallback path. Thinking is off for both: scoring needs
  the temperature determinism it would displace, and neither agent needs
  reasoning tokens across thousands of calls.
- eeglab's evaluation agent moves from qwen/qwen3-235b-a22b-2507 on
  DeepInfra/FP8 to claude-haiku-4-5, the cheapest offered model. Its summary
  agent stays on Haiku rather than moving up to Sonnet 5, because Sonnet
  rejects `temperature` and would silently discard the 0.0/0.1 split the two
  roles are built around.
- AgentConfig.provider is now inert. It still loads, so no config.yaml
  breaks, and _warn_if_provider_ignored logs when one is set rather than
  dropping a deliberate cost choice in silence.
- The same-model warning was inverted: with two offered models, Haiku for
  both agents is the cheapest valid setup, so warning on any repeat would
  fire on the recommended config. It now warns only when the evaluation
  agent, the one making thousands of calls, uses the expensive model.
- summary_model_name is normalized before it is stored, so a config still
  carrying a legacy id records the id that was billed and that
  src/metrics/cost.py prices.
- Fixes two stale docstrings that predate the migration: default_model
  ("OpenRouter format", anthropic/claude-3.5-sonnet example) and
  default_model_provider.

Cost note: the evaluation agent moves from a quantized open model to Haiku
at $1.00/$5.00 per 1M tokens, on the thread-scoring calls. Haiku is the
floor among offered models, so there is no cheaper option; the
quality_threshold of 0.7 still keeps ~85% of threads away from the summary
agent.

Tested: 8 new tests. The registry-wide model check fails against the
pre-migration eeglab config (ValueError on the Qwen id), and the repointed
e2e patch target fails if aimed back at create_openrouter_llm, so both are
load-bearing. Full unit suite 2090 passed, 1 pre-existing Rich-ANSI failure.

Closes #386.
The offered models, their aliases, the sampling rule and normalize_model
now live in src/core/services/anthropic_models.py, which imports nothing
third-party. Config validation has to resolve a model id to judge a
community's choice, and it runs on CLI-only installs where langchain (and
therefore anthropic_llm) is not installed.

anthropic_llm re-exports the tables, so the server-side callers that have
always imported them from there keep working; the split is a packaging
detail, not something every router and agent should know about.

Also logs, at debug, when a configured temperature is dropped and which of
the two reasons applied: the model accepts only its default, or extended
thinking is on. It was silently discarded before. Debug rather than
warning because it is on the per-request path.

Tested: new tests for accepts_temperature over every alias and offered
model, that the re-exports are the same objects rather than copies, and
that the drop reason is reported. Full offline suite passes.
validate_agent_roles compared agent.model against the literal string
"claude-sonnet-5", so a community that wrote a legacy id such as
anthropic/claude-sonnet-4.5 got no warning while still being billed for
Sonnet on every thread it scored. It now normalizes first, and names both
ids in the message so a maintainer recognizes the config line.

Two checks added alongside it:

- A model that resolves to nothing at all now warns, instead of being
  discovered when FAQ generation fails.
- An explicitly configured temperature on a model that only accepts its
  default now warns that the value is dropped rather than sent. Only an
  explicit temperature counts; the field's own default is not a choice the
  community made. The same is logged once per sync run, next to the
  existing provider-ignored warning, since that is where an operator looks.

All of these warn rather than raise: this schema backs the whole community,
and a questionable FAQ setting should not stop the assistant from serving.

Tested: new tests for the alias case, the unresolvable case, temperature on
and behind aliases of both models, and that the field default stays silent.
Also asserts CommunityConfig still imports with the server extra absent.
faq_summarizer carried its own four rate constants, left at pre-migration
OpenRouter prices (Haiku 0.25/1.25, Sonnet 3.00/15.00) while the platform
now bills 1.00/5.00 and 2.00/10.00. Both the estimate shown before a sync
and the total reported after it were wrong, and the per-thread total was
charged at Sonnet rates no matter which model actually ran.

Now sourced from src/metrics/cost.py, the same table the API and CLI report
from, so there is one place to update when a rate changes. Two accounting
fixes fall out of it:

- The scoring call is counted. It runs on every thread and is most of a
  run's cost, but only summarized threads were being charged for.
- Each call is priced at the model that ran it, tracked through both the
  configured-agent and fallback paths.

Estimates stay approximate in two stated directions: input tokens are
derived from the thread's character count rather than counted, and fixed
prompt overhead is not counted at all. The returned keys are unchanged, so
the sync CLI's cost display keeps working.

Tested: estimates derived from the pricing table rather than restated,
that the two strategies are the models the platform offers, and that a real
summarize_threads run charges for scoring alone and for both calls.
@neuromechanist
neuromechanist merged commit 0676926 into feature/issue-360-epic-anthropic-platform Sep 17, 2026
3 of 4 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-386-faq-anthropic branch September 17, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant