Skip to content

feat(agent): optional notice on answers that bypassed the required-tool gate - #512

Open
walcz-de wants to merge 4 commits into
mudler:mainfrom
walcz-de:feat/required-tool-bypass-notice
Open

walcz-de wants to merge 4 commits into
mudler:mainfrom
walcz-de:feat/required-tool-bypass-notice

Conversation

@walcz-de

Copy link
Copy Markdown
Contributor

The required-tool gate (#495) lets an answer through after its attempt cap so a stubborn model cannot hang a turn. That is sensible, but the only trace is a log line (required-tool gate: bypass after max attempts, answer finalized ungated). Whoever receives the answer cannot tell a validated answer from one that skipped the required step — which defeats the purpose when the required tool is a fact or policy check.

We hit this in practice: with a fact-validation tool required, a local model twice ignored the nudge and both answers went out unmarked.

This adds an opt-in notice:

  • WithRequiredToolBypassNotice(text) and agent config field required_tool_bypass_notice (with form metadata next to the other required-tool fields).
  • When set, the text is appended to the answer exactly when it is finalized ungated:
  • No notice when the required tool passed, when the gate is off, or when the option is empty. Default is unchanged (log only).
  • The notice is never appended twice.

Tests

  • core/agent/required_tool_bypass_notice_test.go: bypass after the cap appends the notice (text, send_message, closing reply after stop) — red without the change; passed tool and empty option leave the answer untouched; helper does not double-append.
  • core/state/config_bypass_notice_test.go: JSON round-trip and form field.
  • go test ./core/agent/ (excluding the two model-backed Agent test containers) 74/74, ./core/state/ green, go vet clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PHcZ8CTpZEoK3qgroNnkB4

🤖 Generated with Claude Code

https://claude.ai/code/session_01PHcZ8CTpZEoK3qgroNnkB4

walcz-de and others added 4 commits September 28, 2026 12:43
The top-level job observable never receives progress entries; its outcome is
written by the job-result finalizer. MakeLastProgressCompletion therefore
logged "Observable completed without any progress" at error level on every
successful chat, which reads like a failure when diagnosing a stuck agent.
Mark such an observable completed (keeping an existing completion) and log at
debug level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PHcZ8CTpZEoK3qgroNnkB4
Signed-off-by: Stefan Walcz <stefan.walcz@walcz.de>
When the model calls the stop action, the tool callback rejects the call
(Approved=false). cogito reports any rejection as ErrToolCallCallbackInterrupted,
and the check after ExecuteTools only exempts ErrNoToolSelected and
ErrGoalNotAchieved, so the run finished with "interrupted via
ToolCallCallback" and the stop handling below (lastToolCallName == stop) was
never reached. Chat clients showed an error for an agent that simply stopped.

Mark the job as settled by the callback in the stop case, like send_message
already does, so the interrupt is not treated as a failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PHcZ8CTpZEoK3qgroNnkB4
Signed-off-by: Stefan Walcz <stefan.walcz@walcz.de>
When the model chooses the stop action in a job a user is waiting on (a chat
message, UserRole), the job finished with an empty response: stop only ends the
run, nothing produces the answer. Chat clients received nothing — before the
stop fix an "interrupted" error, after it an empty reply. Observed with local
models that pick stop when they decide the request is out of scope or that
they cannot do it ("no suitable template, so I will not draft"), instead of
saying so.

In a user job, a stop now leads to one closing request without tools: the
stop call is dropped from the conversation and the model is asked for its
final plain-text reply (the answer, or briefly why it cannot help). That reply
goes through the required-tool gate like any text finalization; if the model
stops again when asked to run the required tool, the answer it already gave
is kept (same as after the attempt cap). Autonomous runs (SystemRole) still
end silently on stop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PHcZ8CTpZEoK3qgroNnkB4
Signed-off-by: Stefan Walcz <stefan.walcz@walcz.de>
…ol gate

When the required-tool gate gives up after its attempt cap, the answer leaves the agent
ungated and only a warning is logged. The user receiving it cannot tell a validated answer
from one that skipped the required step (e.g. a fact-validation tool).

Add WithRequiredToolBypassNotice(text) and the agent config field
required_tool_bypass_notice (with form metadata). When set, the text is appended to the
answer exactly when it is finalized ungated -- on the send_message path and on the text
finalization path, which also covers the closing reply after a stop in a chat job. No
notice when the required tool passed, when the gate is off, or when the option is empty
(default: today's log-only behaviour).

Specs: bypass after the cap appends the notice (text, send_message, closing reply after
stop); passed tool and empty option leave the answer untouched; the notice is never
appended twice; config JSON round-trip and form field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PHcZ8CTpZEoK3qgroNnkB4
Signed-off-by: Stefan Walcz <stefan.walcz@walcz.de>
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