Skip to content

Hardened AI orchestration reliability and reduced non-converging edit loops#12

Open
AbhishekSinghDhadwal wants to merge 1 commit intomasterfrom
feature/agent-toolchain-fix
Open

Hardened AI orchestration reliability and reduced non-converging edit loops#12
AbhishekSinghDhadwal wants to merge 1 commit intomasterfrom
feature/agent-toolchain-fix

Conversation

@AbhishekSinghDhadwal
Copy link
Collaborator

@AbhishekSinghDhadwal AbhishekSinghDhadwal commented Feb 18, 2026

This PR hardens AI tool-calling reliability and loop termination behavior in CQL Studio with minimal runtime-focused changes (no API or settings schema changes). It also improves one-shot code-edit completion to reduce unnecessary post-edit self-correction loops.

What changed

1) Act-mode response contract hardening

  • Enforced explicit structured act responses with required next_action: "tool" | "final".
  • Added runtime validation for tool-call shape and conditional requirements.
  • Kept backward compatibility for legacy structured responses by inferring action.

Files:

  • src/app/services/ai.service.ts
  • src/app/services/ai-planning.service.ts

2) Deterministic tool-phase decoding

  • Added mode-specific generation options to reduce random behavior in tool orchestration:
    • Act+tools: lower temp/top_p
    • Plan+tools: constrained temp/top_p
    • Content-only path unchanged (more creative)

File:

  • src/app/services/ai.service.ts

3) Bounded continuation + no-progress safeguards

  • Added structured continuation outcome metadata (reason, progressDelta).
  • Added guardrails:
    • max continuation rounds
    • max no-progress rounds
  • Stop reason is explicit and user-visible.

Files:

  • src/app/services/ai-stream-response-handler.service.ts
  • src/app/components/cql-ide/tabs/ai-tab/ai-tab.component.ts

4) Tool execution resilience

  • Increased default tool timeout from 5s to 25s.
  • Added one retry for transient failures (timeout/network/429/5xx-like).
  • Kept no-retry behavior for validation failures.
  • Increased tool summary truncation limit to preserve more context for continuation.

File:

  • src/app/services/ai-tool-execution-manager.service.ts

5) Token-aware context compaction

  • Enforced approximate token budget in API message selection.
  • Preserves system messages and most recent relevant turns under budget.
  • Maintains deterministic behavior without adding semantic summarization complexity.

File:

  • src/app/services/conversation-manager.service.ts

6) One-shot edit loop reduction

  • insert_code / replace_code now validate non-empty code and return concise accepted metadata instead of verbose placeholder payloads.
  • UI edit application now ignores failed edit tool results.
  • Added explicit completion policy so simple “create/insert and done” requests finalize rather than entering unsolicited validation/refactor loops.

Files:

  • src/app/services/tools/insert-code.tool.ts
  • src/app/services/tools/replace-code.tool.ts
  • src/app/components/cql-ide/tabs/ai-tab/ai-tab.component.ts
  • src/app/services/ai.service.ts

Why

It was observed that there existed multiple tool chain orchestration issues like - flaky tool-call chaining, random loop continuation, and non-converging edit-repair cycles. These changes prioritize deterministic control flow, bounded retries/loops, and better completion behavior for common user intents.

Scope

  • Runtime reliability and orchestration only.
  • No public HTTP API changes.
  • No new user-facing settings.
  • No backend endpoint changes.

Sources I've referred to in order to implement these changes

NOTE - This is not a final fix, and is simply a step towards strengthening the application. Future fixes will further strengthen the tool calling chain and associated components, especially towards code completion.

- Enforced structured Act-mode contract with required next_action (tool|final), runtime validation, and legacy compatibility
- Added deterministic mode-specific decoding options for tool phases
- Added continuation metadata (reason/progressDelta) and bounded loop guardrails in AI tab (max rounds + no-progress cap + explicit stop reason)
- Improved tool execution resilience with longer timeout, one transient retry, and larger tool-result summary cap
- Added token-aware context compaction in conversation message selection
- Updated planning/act prompt guidance to require explicit next_action contract.
- Improved edit-tool behavior:
  - insert_code / replace_code now validate non-empty code and return concise accepted metadata
  - UI edit application skips failed tool results
  - Added completion policy to finalize one-shot create/insert requests instead of unsolicited fix loops
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments