← Back to Pull requests

feat: upgrade built-in agent engine to multi-step tool calling & agent profiles (#398) #419

Closed
unknown closed this pull request without merging on Dec 01, 2026 11:25 UTC
View on GitHub
unknown unknown commented on Dec 01, 2026 03:29 UTC
Author

Part of #394
Closes #398

Summary


  • Lazy Vendor Seam (src/llm/aiVendor.js): Exports tool and stepCountIs from "ai" behind the dynamic import seam (src/llm/index.js), verified lazy by scripts/check-chunk-laziness.mjs.

  • Multi-Step Tool-Calling Runner (src/llm/agentRunner.js + src/llm/index.js): Adds runAgent(...) on LLMProvider, bridging canonical registry tools via vendor.tool / vendor.jsonSchema and vendor.stepCountIs(maxSteps) (capped 1–12, 60s total timeout, abortSignal).

  • - Fail-Closed Containment: Wraps untrusted tool outputs (every string leaf and non-identifier object key except a minimal safe structural/token allowlist, plus error.message) in <bookmark_data>...</bookmark_data> with delimiter/attribute neutralization and a 24k-char total payload cap, while delivering unwrapped step events to UI listeners.
    - Local-Model Non-Tool Fallback: When a provider/model rejects native tool calling (UnsupportedFunctionalityError or tool-unsupported errors), automatically falls back to a dynamic single-shot JSON schema generated from the active agent's resolved tool list and routes calls through the same PolicyGate.
  • Configurable Agent Profiles & WebMCP Policy Hook (src/tools/agentProfiles.js + src/hooks/useAgentConfig.js): Defines 4 built-in profiles (assistant, librarian, link-doctor, researcher with locked read_only policy) and persists profile & WebMCP toolset/policy overrides in local-only storage (extensionStorage.js, never .sync), re-sanitizing all fields on read as untrusted data.

  • Upgraded Agent Engine & App Wiring (src/hooks/useAgentEngine.js, src/hooks/useAppController.js, src/hooks/useWebMcpTools.js, src/components/BookmarkApp.jsx):

  • - Unifies provider/model override resolution (resolveEffectiveAgentLlm), enforces allowAutonomousDestructive: false, and adds live isProcessing, lastRun, and cancel().
    - Removes the legacy runPlanSteps, handlePersistReorderFromAgent, widenSearch, and REORDER_ACTIONS dispatch ladder from BookmarkApp.jsx (reducing BookmarkApp.jsx from 2,200 to 2,150 lines) while keeping src/llm/normalize.js and src/utils/smartViews.js compatibility intact.
    - Adds a compact accessible running/stop/reply banner in BookmarkApp.jsx and wires useAgentConfig's WebMCP toolsets/policy into useWebMcpTools.
  • Docs & Changeset: Updates DESIGN.md and adds .changeset/multi-step-agent-engine.md.
  • Verification


  • npx eslint --max-warnings=0 on all new/modified LLM, tool profile, hook, controller, and message modules: 0 errors, 0 warnings.

  • npm run ci </dev/null passed completely (check:version-policy, licenses:notices:check, format:check, lint, all 128 Vitest suites / 1,620+ tests, build:chrome with scripts/check-chunk-laziness.mjs, and build:storybook).

  • Explicit Claude Sonnet pre-push security review completed (APPROVED after fixing B1–B3 and NB1–NB5).
  • <!-- agent-bot-write: ghw_3a02ef514a4d8f5b session=210bdd5e08f0 bot=trueline-antigravity-agent[bot] conversation_id=e99b26b3-53f9-4d7f-8337-fb33257bb240 conversation_id_source=self-reported -->

    Diff: 395 lines (+296 / -99) across 4 files Reviewer: qwts Review duration: 476m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.48) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 395 lines diff across 4 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.358
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #419"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48.2% (MEDIUM) · Higher = larger blast radius
    48.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.8% · Safe to merge
    20.8%