Repository navigation
LLM-backed query decomposition + read-then-write turn completion before search_nodes/update_node - #1688
Conversation
…ule (closes #1637) E4B reliably fails "Mark the $500 invoice as paid": it hand-writes a multi-word search_nodes query ("$500 invoice due next Friday") that title-matching (SQL LIKE, whole-string substring) never finds against the actual title "Invoice for $500 due next Friday" — and even a successful search can be followed by the model stopping before the matching update_node call. Adds resolve_query, a new agent tool whose handler makes its own scoped nested inference call (mirrors the existing single-shot pattern in agent_loop::maybe_summarize_history): it looks up the target type's real schema fields via NodeService::get_schema_node (deterministic, not the semantically-truncated schema summary in the main prompt), asks a narrow prompt to resolve ambiguous values (amounts, relative dates, paraphrased identifiers) against those fields, and returns ready-to-use search_nodes query/filters. GraphToolExecutor gains a SharedChatInferenceEngine handle (same shared-RwLock pattern as SharedEmbeddingService) wired at both replace_engine call sites in local_agent_service.rs. agent_guidance.rs: replaces the "ONE WORD ONLY" query-phrasing workaround (documented in the issue as verified ineffective — the model produced the same wrong query regardless of prompt wording) with an instruction to call resolve_query first for ambiguous update targets. Also adds a read-then-write turn-completion rule: a successful search for a write instruction must continue to update_node/update_task_status in the same turn, not stop. Verified via 9 new Rust unit tests, including a real-schema + stub-engine integration test exercising the full resolve_query path (schema lookup, prompt construction, nested generate() call, JSON parsing with prose/markdown-fence tolerance, empty-result fallback on unparseable output). Live aichat-matrix run against gemma-4-e4b-q4km could not be completed in this environment: even after freeing two other long-running sessions, available memory stayed too low for sysinfo's memory-fit to grant more than the 4096-token floor, short of the ~6600 tokens the 14-tool prompt needs — a pre-existing environment constraint, not something this change introduces. Re-running the matrix on a less memory-constrained machine is a follow-up. Co-Authored-By: Claude <[email protected]>
Discovered via a substitute Gemma 4 E2B smoke-test of resolve_query (the actual target model, E4B, requires more context than this machine's available memory could grant): after resolve_query resolved "Mark the $500 invoice as paid" into filters-only output, the model built a follow-up search_nodes call with filters but no query field at all — search_nodes required query, so the call hard-errored with "missing field `query`" instead of finding the invoice. query="" already means "skip the title filter" per its own documentation; there's no reason a filters-only call must also remember to echo back an empty string for it. Defaults SearchNodesParams.query via #[serde(default)] and drops "query" from the tool's JSON schema `required` list. Updates the three tests that asserted the old hard-required behavior to assert the new default instead. Co-Authored-By: Claude <[email protected]>
Code Review SummaryReview Type: Initial Review This PR adds Requirements CheckOriginal scope (issue #1637, Half A):
Half B (read-then-write):
Overall: the acceptance criteria that are code/architecture questions are fully met; the criteria that are empirical model-behavior claims rest on an unverifiable (from this review's vantage point) live eval report. That's a reasonable trust boundary given the task description explicitly calls this out as evaluated at face value. Code Review Findings🟡 Important:
|
malibio
left a comment
There was a problem hiding this comment.
Review recommendation: APPROVE (see full review above). Note: could not submit a formal --approve review — GitHub blocks self-approval since the PR author and this gh session are the same account (malibio).
…, isolate a test's failure path Reviewer found two issues in PR #1688: 1. (Important) SharedChatInferenceEngine's doc comments claimed it mirrors SharedEmbeddingService's live-swap semantics (updated in place via a shared lock as a background loader finishes). It doesn't: both construction sites (build_noop_service, replace_engine) build a brand new Arc<RwLock<..>> every time rather than writing into an existing one, because the daemon already rebuilds the whole GraphToolExecutor on every model load/switch. The lock was doing nothing but adding a misleading doc comment and an unnecessary .await. Simplified the type to a plain Option<Arc<dyn ChatInferenceEngine>> and fixed the comments at both construction sites to describe what's actually true. 2. (Suggestion) resolve_query_without_inference_engine_returns_error used test_executor(), which has node_service: None too — since exec_resolve_query checks node_service()? first, the test couldn't fail for the reason its name claimed. Moved it into the resolve_query_integration submodule with a real node_service (reusing the existing make_test_service fixture) and inference_engine: None, isolating the intended failure path. Skipped: a suggested one-line comment on the injection-containment of resolve_query's prompt interpolation — folded that note into the SharedChatInferenceEngine doc comment instead of adding a separate one, since I was already touching that block. Co-Authored-By: Claude <[email protected]>
Addressed review feedback✅ Addressed (2/2 non-verification findings):
⏭️ Folded in rather than separately addressed: the suggested one-line comment on Verification: Re-Review DecisionDecision: NO RE-REVIEW NEEDED Rationale: Both changes are narrow, low-risk simplifications directly matching the reviewer's own suggested fix (drop the |
Closes #1637
Summary
E4B reliably failed "Mark the $500 invoice as paid": it hand-wrote a multi-word
search_nodesquery ("$500 invoice due next Friday") that title-matching (SQLLIKE, whole-string substring) never found against the actual title"Invoice for $500 due next Friday"— and even a successful search could be followed by the model stopping before the matchingupdate_nodecall.Half A — query decomposition: adds
resolve_query, a new agent tool whose handler makes its own scoped nested inference call (mirrors the existing single-shot pattern inagent_loop::maybe_summarize_history). It looks up the target type's real schema fields viaNodeService::get_schema_node(deterministic, not the semantically-truncated schema summary in the main prompt), asks a narrow prompt to resolve ambiguous values (amounts, relative dates, paraphrased identifiers) against those fields, and returns ready-to-usesearch_nodesquery/filters.GraphToolExecutorgains aSharedChatInferenceEnginehandle (same shared-RwLockpattern asSharedEmbeddingService), wired at bothreplace_enginecall sites inlocal_agent_service.rs.agent_guidance.rsreplaces the "ONE WORD ONLY" query-phrasing workaround (documented in the issue as verified ineffective — the model produced the same wrong query regardless of prompt wording) with an instruction to callresolve_queryfirst for ambiguous update targets.Half B — read-then-write completion: adds a rule that a successful search for a write instruction must continue to
update_node/update_task_statusin the same turn, not stop.Follow-up fix (found via live eval):
resolve_queryreturningfilters-only output sometimes led the model to omitqueryentirely from the follow-upsearch_nodescall — which used to hard-error sincequerywas a required field. Fixed by defaultingqueryto""(matching its existing "skip title filter" semantics) and updating the JSON schema + 3 tests accordingly.Verification
resolve_query: tool registration, schema validation, param parsing, and a real-schema + stub-engine integration test exercising the full path (schema lookup → prompt construction → nestedgenerate()call → JSON parsing with prose/markdown-fence tolerance → empty-result fallback on unparseable output).search_nodesquery-optional relaxation.agent_guidance.rs.aichat-matrixrun againstgemma-4-e4b-q4km: 12/12 scenarios passing, up from the 11/12 baseline (PR Collapse execute_query into search_nodes as one agent query tool (closes #1640) #1687). Scenario 6 now callsresolve_query → search_nodes → update_node— confirming both halves of this issue land together, with no regression on the other 11 scenarios.bun run test:allandbun run quality:fixclean.Notes
nlp-engine'scompute_effective_n_ctx) — unrelated to this change, just a precondition for running the eval itself.