feat(voice_worker): a short voice prompt and one judgement before each v2 answer
- compact_prompt: the v2 persona in a tenth of v1's words, answers as short as possible, the full tool guidance only on turns with a data tool. A greeting's reply prompt went from about 4,500 to 1,400 tokens on Strata. - intent_judge: the tool router judges whether the turn needs tools; the planner runs only when it does. prepare_intent runs the pick ahead on a partial transcript (worker message prepare), and the reply reuses it. - Without stream_browser the screen-share tools are not offered. - The time context carries the 12-hour form (10:37 was read as pm). - A <tool_call> block written as the reply is parsed as a call, not spoken. Evals (Qwen3.6 on Strata, EVAL_COMPACT_PROMPT=1 EVAL_INTENT_JUDGE=1): 221 passed, 4 failed (known failures); new evals/test_voice_reply_length.py (v2 answers 234 chars against v1's 416) and test_reply_language_default.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ Every distinct LLM call in Jarvis, what feeds it, what consumes it, and how it i
|
||||
- Redacted user query
|
||||
- Recent dialogue (last 5 minutes), including in-loop tool-call + tool-role messages from prior replies within the active conversation (tool carryover, `DialogueMemory.record_tool_turn` / `get_recent_turns_with_tools` in [src/jarvis/memory/conversation.py](src/jarvis/memory/conversation.py); per-prompt cap via `cfg.tool_carryover_max_turns` / `tool_carryover_per_entry_chars`; storage cap `_tool_turns_max_storage = 16`; cleared on `stop` signal AND on new-conversation entry; UNTRUSTED WEB EXTRACT fence markers preserved on truncation; both `content` and `tool_calls[*].function.arguments` scrubbed on write)
|
||||
- Unified system prompt from [src/jarvis/system_prompt.py](src/jarvis/system_prompt.py) + ASR note + tool-protocol guidance. Reply language is resolved by `reply_language_directive(lang, cfg.tts_engine)` where `lang = _resolve_output_language()` — the single source of truth that prefers the settings-web UI value (config JSON `output_language`) over the compose `OUTPUT_LANGUAGE` env, so changing the language in the settings page takes effect. An explicit lock wins (forces "reply only in `<language>`", also forbidding other scripts so small models stop leaking trailing CJK/Hanja); else a Piper/Chatterbox TTS forces English (English-only voices); else (multilingual TTS, no lock) the assistant replies in the user's own language. The v2 voice worker's brain (`src/voice_worker/brain.py`) runs with `tts_engine="melo"`, so v1's English-only Piper default never locks v2 voice or chat answers to English, and passes `default_language` (worker `--reply-language`, default `Korean`): with no lock, `default_language_directive()` makes replies come in that language unless the user explicitly asks for another one, and `build_system_prompt()` rewrites the persona's "in the user's language" clause to "in the reply language" (eval `evals/test_reply_language_default.py`). The directive is inserted near the FRONT of the guidance list so a small model gives it primacy, and the SAME resolved `lang` feeds `build_system_prompt()`, which rewrites the persona's "in the user's language" clause to the locked language so the persona cannot contradict the directive (previously the persona read the raw env while the directive read the config value, so a settings-UI change was honoured by one and ignored by the other). Gated in `_build_initial_system_message()` at [engine.py](src/jarvis/reply/engine.py).
|
||||
- **v2 compact prompt** (`compact_prompt=True`, the v2 brain): `build_voice_persona()` replaces the v1 persona (about 1.3k characters instead of 7.4k: no single-user long-term memory or on-screen browser rules, answers as short as possible), and of the size-specific components only the ASR note stays; the full tool guidance (`tool_guidance` + `tool_constraints`) is added only when a tool other than `stop`, `toolSearchTool` and `chatChannels` is allowed, else the one-line `COMPACT_ACTION_RULE`. Measured on Strata (Qwen3.6, 2026-11-12): a greeting's reply prompt went from about 4,500 to 1,350 tokens and its prompt read from 1.07 s to 0.36 s (Strata reads in 2,048-token steps). The v2 brain also turns `stream_browser` off. The `[Context: ...]` time carries the 12-hour form beside the 24-hour one (`10:37 (10:37 AM)`): with the short prompt Qwen3.6 read 10:37 as 오후 (pm) 4 of 4 times.
|
||||
- **Tool honesty rules**: `TOOL_HONESTY_RULES` inside the persona, plus `tool_honesty_reminder(allowed_tools)` appended after every context block (just before the closing reply-language lock) naming the turn's tools. Added after M0 (2026-11-10) caught models answering past an available tool.
|
||||
- **Operator instructions** (two sources, both framed "Additional instructions from the operator:" and appended near the end of the guidance list): the settings-UI `llm_instructions` config field, and every `*.md` file in `AGENTS_DIR` (default `/app/agents`, bind-mounted from `./agents`). The file-based set is read once per turn by `load_agent_instructions()` in [src/jarvis/system_prompt.py](src/jarvis/system_prompt.py) and concatenated in filename order, so dropping/editing a `.md` applies on the next reply with no rebuild/restart; fail-open to `""` when the folder is absent/empty/unreadable.
|
||||
- **Warm profile block** (query-agnostic User + Directives excerpt from the knowledge graph, composed by `build_warm_profile()` / `format_warm_profile_block()` in [src/jarvis/memory/graph_ops.py](src/jarvis/memory/graph_ops.py) at Step 3.5 of `reply()`; no LLM call, pure SQLite read; injected unconditionally so personalisation is the default; result cached in `DialogueMemory._hot_cache` under `DialogueMemory.WARM_PROFILE_CACHE_KEY` for the lifetime of the active conversation. Invalidated on `stop`, on new-conversation entry, AND on User/Directives graph mutations via the listener registered in [src/jarvis/daemon.py](src/jarvis/daemon.py) against `register_graph_mutation_listener` in [src/jarvis/memory/graph.py](src/jarvis/memory/graph.py); World-branch writes are ignored)
|
||||
@@ -95,7 +96,7 @@ Every distinct LLM call in Jarvis, what feeds it, what consumes it, and how it i
|
||||
## 7. Tool Router (pre-loop tool selection)
|
||||
|
||||
- **File**: [src/jarvis/tools/selection.py](src/jarvis/tools/selection.py) — `select_tools_with_llm()` (~line 331).
|
||||
- **Trigger**: once per reply, **at the very front of the flow before the planner (#12)**. Always runs — the router is the authoritative tool picker, and its narrowed catalogue is what the planner sees. When the planner later references tools, those names are unioned into the router's allow-list but never replace it; small models tend to default to `webSearch` where a dedicated tool like `getWeather` should win, and the router is tuned for that classification. `tool_selection_strategy == "llm"` is the default; other strategies (`all`, `keyword`, `embedding`) also run here.
|
||||
- **Trigger**: once per reply, **at the very front of the flow before the planner (#12)**. Always runs — the router is the authoritative tool picker, and its narrowed catalogue is what the planner sees. When the planner later references tools, those names are unioned into the router's allow-list but never replace it; small models tend to default to `webSearch` where a dedicated tool like `getWeather` should win, and the router is tuned for that classification. `tool_selection_strategy == "llm"` is the default; other strategies (`all`, `keyword`, `embedding`) also run here. **v2 brain** (`run_reply_engine(intent_judge=True)`): the router is the turn's judgement; the planner (#12) runs only when it picked a tool other than `stop`, `toolSearchTool` and `chatChannels`. `prepare_intent()` runs the same pick ahead on a partial transcript while the user is still talking, and the reply uses it (`prepared_tools`) without a router call of its own (planner.spec.md, "Intent judge (v2)"). Without `stream_browser` the screen-share tools (`controlBrowser`, `browseAndPlay`, `setBroadcast`) are not in the router's or the chat model's catalogue.
|
||||
- **Model / gating**: `resolve_tool_router_model(cfg)` chain — `tool_router_model → intent_judge_model → ollama_chat_model`.
|
||||
- **Inputs**: user query, tool catalogue (builtin + MCP with descriptions), optional narrow-down hint.
|
||||
- **System prompt**: inline (~lines 260-315). Teaches pick up-to-5 tools or `none`.
|
||||
@@ -156,7 +157,7 @@ Every distinct LLM call in Jarvis, what feeds it, what consumes it, and how it i
|
||||
## 12. Task-list Planner (pre-flight decomposition, gates the whole turn)
|
||||
|
||||
- **File**: [src/jarvis/reply/planner.py](src/jarvis/reply/planner.py) — `plan_query()`.
|
||||
- **Trigger**: once per reply, **after the tool router and before memory search**. Skipped when `cfg.planner_enabled = False`, when the query is shorter than `MIN_QUERY_CHARS` (4), or when no model / base URL is available.
|
||||
- **Trigger**: once per reply, **after the tool router and before memory search**. **v2 brain** (`intent_judge=True`): runs only on turns where the router picked a tool (not for `stop`, `toolSearchTool` or `chatChannels` alone), so a turn without tools has one LLM call before its answer. Skipped when `cfg.planner_enabled = False`, when the query is shorter than `MIN_QUERY_CHARS` (4), or when no model / base URL is available.
|
||||
- **Model / gating**: resolution chain `planner_model (override) → ollama_chat_model`. The planner tracks the chat model so upgrading the chat model (via setup wizard or config) automatically upgrades plan quality.
|
||||
- **Inputs**: user query, dialogue context, the live time/location line (`LIVE CONTEXT:`, so a location-dependent ask plans `searchMemory topic='where the user lives'` only when the location is unknown or disabled), **router-narrowed** tool catalogue (names + one-line descriptions + argument names, built by `planner_tool_catalog()`) — not the full 30+ list. When the carry-over guard from #7 fires, the previous turn's failed tool name is unioned into this catalogue before the planner sees it, so the planner can plan a re-call without `toolSearchTool` round-tripping. **No** memory context — the planner decides *whether* memory is needed.
|
||||
- **System prompt**: `_PROMPT_TEMPLATE` in `planner.py`. Teaches the `searchMemory topic='...'` directive for prior-conversation lookups, short imperative tool steps, angle-bracket entity placeholders, final synthesis step, same-language output, no numbering.
|
||||
@@ -204,7 +205,7 @@ Every distinct LLM call in Jarvis, what feeds it, what consumes it, and how it i
|
||||
| 4 | Memory digest | 0-N | auto by size | SMALL (uses chat model) |
|
||||
| 5 | Tool-result digest | 0-N | auto by size | SMALL (uses chat model) |
|
||||
| 6 | Max-turn digest | 0-1 | No | SMALL |
|
||||
| 7 | Tool router | 1 | always runs; planner picks unioned in | SMALL |
|
||||
| 7 | Tool router | 0-1 | always runs (v2: unless prepared on a partial); planner picks unioned in | SMALL |
|
||||
| 8 | Tool searcher | 0-3 | model-initiated | SMALL (reuses #7) |
|
||||
| 9 | Summariser | ~1/session | No (background) | LARGE |
|
||||
| 10 | Graph extraction | ~1/session | No (background) | LARGE |
|
||||
|
||||
Reference in New Issue
Block a user