Make agent tool handling schema-driven and recoverable #72

Closed
opened 2026-08-29 17:40:10 +00:00 by hugo · 1 comment
Owner

Goal

Make DS4Server tool use reliable for local coding models through Rust-native executable schemas, precise failure feedback, and targeted loop recovery. Tool metadata must have one source of truth shared by prompt rendering and runtime validation.

Plan

  • Define each tool's name, description, parameter contract, validation, and execution behavior together in Rust; generate the model-visible schema from that contract instead of maintaining separate prompt-only JSON.
  • Validate required fields, primitive types, enums, numeric bounds, and cross-field rules before any side effect. Remove silent numeric/boolean coercion and resolve existing schema/runtime disagreements such as optional list.path and job-versus-pid lookup.
  • Return stable, precise failures containing the tool name, error code, field path, expected shape, and received type/value. Keep malformed transport syntax, unknown tools, policy denials, execution failures, and timeouts distinguishable.
  • Keep DeepSeek DSML and GLM tool syntax inside their Rust model adapters. Reduce the global prompt to transport rules and move invocation/recovery guidance into the owning tool descriptions or prompt sections.
  • Add a per-session exact-repeat detector over canonical tool name/arguments. Inject advisory reminders at escalating thresholds (initially 3, 5, and 8), count denied and failed calls, and reset after a direct user message. Do not rewrite calls or retry side effects automatically.
  • Add focused tests/evals for malformed syntax, missing/wrong arguments, enum/range violations, unknown tools, denied actions, execution errors, repeated calls, and successful model correction on the following step.

Boundaries

  • Rust only; no JavaScript runtime, workflow DSL, or external helper process.
  • This issue does not implement Ralph, subagents, or generic workflows.
  • Do not preserve current prompt or coercion behavior without evidence; retain only model-wire requirements demonstrated by DSML/GLM tests.

Acceptance criteria

  • Model-visible schemas and runtime validation are produced from the same Rust definitions.
  • Invalid arguments cannot reach tool bodies or cause side effects, and feedback identifies the exact tool and violation.
  • Existing schema/runtime disagreements and silent coercions are removed or explicitly justified by tests.
  • Tool-specific guidance covers failure recovery, shell exit handling, sandbox denial behavior, editing, and background jobs without duplicating a large global prompt.
  • Exact repeated calls trigger bounded, escalating notices without blocking legitimate execution.
  • DeepSeek V4 Flash and GLM tool-call parsing and correction paths have regression coverage.
  • cargo fmt --all -- --check, Clippy with -D warnings, make bundle, and cargo test --all-features pass.
## Goal Make DS4Server tool use reliable for local coding models through Rust-native executable schemas, precise failure feedback, and targeted loop recovery. Tool metadata must have one source of truth shared by prompt rendering and runtime validation. ## Plan - Define each tool's name, description, parameter contract, validation, and execution behavior together in Rust; generate the model-visible schema from that contract instead of maintaining separate prompt-only JSON. - Validate required fields, primitive types, enums, numeric bounds, and cross-field rules before any side effect. Remove silent numeric/boolean coercion and resolve existing schema/runtime disagreements such as optional `list.path` and job-versus-pid lookup. - Return stable, precise failures containing the tool name, error code, field path, expected shape, and received type/value. Keep malformed transport syntax, unknown tools, policy denials, execution failures, and timeouts distinguishable. - Keep DeepSeek DSML and GLM tool syntax inside their Rust model adapters. Reduce the global prompt to transport rules and move invocation/recovery guidance into the owning tool descriptions or prompt sections. - Add a per-session exact-repeat detector over canonical tool name/arguments. Inject advisory reminders at escalating thresholds (initially 3, 5, and 8), count denied and failed calls, and reset after a direct user message. Do not rewrite calls or retry side effects automatically. - Add focused tests/evals for malformed syntax, missing/wrong arguments, enum/range violations, unknown tools, denied actions, execution errors, repeated calls, and successful model correction on the following step. ## Boundaries - Rust only; no JavaScript runtime, workflow DSL, or external helper process. - This issue does not implement Ralph, subagents, or generic workflows. - Do not preserve current prompt or coercion behavior without evidence; retain only model-wire requirements demonstrated by DSML/GLM tests. ## Acceptance criteria - Model-visible schemas and runtime validation are produced from the same Rust definitions. - Invalid arguments cannot reach tool bodies or cause side effects, and feedback identifies the exact tool and violation. - Existing schema/runtime disagreements and silent coercions are removed or explicitly justified by tests. - Tool-specific guidance covers failure recovery, shell exit handling, sandbox denial behavior, editing, and background jobs without duplicating a large global prompt. - Exact repeated calls trigger bounded, escalating notices without blocking legitimate execution. - DeepSeek V4 Flash and GLM tool-call parsing and correction paths have regression coverage. - `cargo fmt --all -- --check`, Clippy with `-D warnings`, `make bundle`, and `cargo test --all-features` pass.
hugo added the enhancementcritical labels 2026-08-29 17:40:10 +00:00
Author
Owner

Implemented in f12aafc. Tool names, descriptions, parameter kinds/bounds/enums/cross-field rules, schema generation, and execution dispatch now share one Rust ToolSpec catalog, including the Dev Brain tools. Runtime validation runs before approval or execution, rejects undeclared/missing/wrong/quoted/out-of-range arguments without coercion, and returns stable tool/code/field/expected/received failures. list.path is optional and bash_status/bash_stop accept either job or pid. DeepSeek DSML and GLM adapters preserve declared integer/boolean primitives, malformed transport and unknown/denied/execution/timeout outcomes remain distinct, recovery guidance lives with each tool, and per-session canonical repeat notices fire at 3/5/8 and reset on direct user input. Added isolated coverage for schema/runtime agreement, no-side-effect invalid writes followed by a successful correction, parser typing and malformed syntax, every validation class, policy denial, real execution errors/timeouts, and canonical repeat/reset behavior. Verification: cargo fmt --all -- --check; cargo clippy --all-targets --all-features -- -D warnings; make bundle; cargo test --all-features (176 passed, 14 hardware/browser fixtures ignored).

Implemented in f12aafc. Tool names, descriptions, parameter kinds/bounds/enums/cross-field rules, schema generation, and execution dispatch now share one Rust ToolSpec catalog, including the Dev Brain tools. Runtime validation runs before approval or execution, rejects undeclared/missing/wrong/quoted/out-of-range arguments without coercion, and returns stable tool/code/field/expected/received failures. list.path is optional and bash_status/bash_stop accept either job or pid. DeepSeek DSML and GLM adapters preserve declared integer/boolean primitives, malformed transport and unknown/denied/execution/timeout outcomes remain distinct, recovery guidance lives with each tool, and per-session canonical repeat notices fire at 3/5/8 and reset on direct user input. Added isolated coverage for schema/runtime agreement, no-side-effect invalid writes followed by a successful correction, parser typing and malformed syntax, every validation class, policy denial, real execution errors/timeouts, and canonical repeat/reset behavior. Verification: cargo fmt --all -- --check; cargo clippy --all-targets --all-features -- -D warnings; make bundle; cargo test --all-features (176 passed, 14 hardware/browser fixtures ignored).
hugo closed this issue 2026-08-29 18:44:33 +00:00
Sign in to join this conversation.