Repository navigation
feat: route turns to a quick or an analysis model and hand over a compact summary (E8.1, E8.2) - #686
Conversation
Both or neither, each resolved through normalize_model, and an execute_code client tool is required. NEMAR sets haiku and sonnet. start_analysis is a reserved client tool name. Tested: config tests.
wants_analysis, the tier type, the quick-turn prompt section and the summary limit live in src/agents/model_routing.py. A quick turn binds start_analysis in place of execute_code and get_full_output. Tested: tests/test_agents.
stream_handover emits summarizing, summarized and started, seeds a new analysis session with the summary and the reader's message, and streams the analysis run on it. Tested with the router wiring in the next commit.
…E8.1, E8.2) ChatSession.mode, a tier threaded through _configured_default, _select_model, _route_request and create_community_assistant, a quick-turn prompt section, start_analysis turned into a handover by the stream layer, mode on done, and /chat/resume on the session's tier. Tested: tests/test_api/test_model_routing.py with the model stand-in.
Documents the handover events in docs/community-widget.md, the keys in yaml_registry.md and the changelog. The LLM tests skip without an Anthropic key and were not run here.
…h is sticky Bare run(s), spectrum, filter and fit matched ordinary BIDS and NEMAR vocabulary and moved the reader to the analysis model for the rest of the conversation. Tested: unit tests incl. negatives for the reported phrases.
…er a yield A first-message start_analysis released the session and re-claimed it after the nested run sent its session event; a handover claimed its new session only after the same event. Both now claim first and pass the claim on (turn_claimed). Tested: claims are None on every session after each handover path, follow-ups succeed, and the claim is held when the analysis run starts.
…e turn A summarizer error after the summarizing event ended the stream. It now retries a provider failure that can clear, and falls back to the tail (not the head) of the reader's last three messages, logged and flagged degraded on the event. The summary is framed as background context and fenced from the reader's message. Tested: unit and stream-level tests with a failing summarizer.
The quick run and the summary are logged as <request id>:quick, priced at the quick model, so done.request_id names one row. The summary's tokens are counted and it runs under the request's LangFuse config. Tested: rows per handover path read from the real metrics database.
Tier was written three times (model_routing, assistants/community, client_tools); all now import it from src.core.config.community. The quick-mode instruction merge is computed before the constructor call. Tested: routing and config tests.
… widget against the handover stream The widget set a 'writing' label for it and no tool_start or tool_end followed. Adds frontend/test-widget-handover-events.js (handover events ignored, second session event adopted, next message on the new session), wired into Frontend Tests. Tested: bun test passes, API tests pass.
…call and kill-switch cases Replaces a check that was always true with index comparisons, simplifies the redundant tool-binding assertion. Tested: API routing tests pass.
Review round 1: outcomesPushed to this branch (7 commits). Tested:
|
…it to run nothing (LLM test, not run: no key)
… AsyncGenerator; document degraded (tested)
|
Review round 2 outcomes (all pushed to this branch):
Tests: |
Preview Deployment
This preview will be updated automatically when you push new commits. |
Summary
NEMAR answers most turns on Haiku, and only code, plots and analysis need Sonnet.
Switching models inside one server session risks the thinking checks in #522, so a handover compacts the chat into a NEW session.
E8.1 routing
quick_modelandanalysis_model(NEMAR:haiku,sonnet): both or neither, each resolved throughnormalize_model, and anexecute_codeclient tool is required.start_analysisis a reserved client tool name.src/agents/model_routing.py:wants_analysis, the tier type, the quick-turn prompt section, the summary prompt and the word limit,tier_for_turn./chatand/chat/resume, when the community has both keys, the request declaresexecute_codeand names nomodel. Communities without the keys behave exactly as before (notieris passed, nomodeondone).ChatSession.mode(quickdefault,analysis), sticky. A tier is threaded down to_configured_default(never passed asrequested_model, which is a 403 on OpenRouter without BYOK).execute_codeandget_full_output, plusstart_analysis, a reserved client tool that reuses the parked-client-call mechanism. The stream layer turns that parked call into a handover instead of atool_request. Its prompt section rides oncreate_community_assistant'sadditional_instructions./chat/resumealways uses the session's tier.E8.2 handover
handovereventssummarizing,summarized(messages,words,summary),started(session_id,model), then the analysis run on a new session seeded with oneHumanMessage(summary plus the reader's message), through the normal path so itssessionevent anddone.session_idcarry the new id.donecarriesmode.limit_words)._stream_chat_response's docstring anddocs/community-widget.md. Handover logic is insrc/api/handover.pyandsrc/agents/model_routing.py.Out of scope as briefed: the widget card (E8.3), per-model cost (E8.4), the non-streamed
/chatpath, plan tools.Closes #670
Closes #674
Commands run
uv run pytest tests/test_core/test_config/test_community.py tests/test_agents/test_model_routing.py tests/test_api -q: passed (2002 passed with the embed hygiene test, 1 skipped)uv run pytest tests -q -m "not llm"(outside the paths above): 3413 passed, 1 failed (tests/test_tools/test_hed_suggest.py::test_real_program_suggests_a_schema_tag, a real-program tool test this change does not touch)uv run pytest tests/test_integration/test_model_routing_llm.py -m llm -v: 3 skipped, noANTHROPIC_API_KEYin this environment, so the real-model tests did not run hereuv run ruff check . && uv run ruff format --check .: passed