fix(captain): honor mandatory handoff guidelines (#15003)

Ensures Captain follows explicit mandatory-transfer rules from active
Response Guidelines and Guardrails instead of allowing the generic
consent-first fallback to override those rules.

## What changed

- Made explicit transfer requirements take precedence over generic
consent-first handoff defaults only when their condition matches.
- Added explicit Response Guideline and Guardrail transfer rules to the
human-handoff protocol.
- Added focused prompt regression coverage.

## How to reproduce

Configure a Response Guideline or Guardrail that requires immediate
transfer for a specific condition, then send a request matching that
condition. Captain should invoke the human-handoff path without asking
the user to consent again. Unmatched requests continue to use the
existing consent-first fallback.

The assistant prompt renderer, agent prompt context, and focused
regression specs pass locally.
This commit is contained in:
Aakash Bakhle
2026-07-14 19:38:43 +05:30
committed by GitHub
parent 9328f8739c
commit 2ac55c8728
@@ -48,6 +48,8 @@ Always respect these boundaries:
{% endfor %}
{% endif -%}
When a Response Guideline or Guardrail explicitly requires transfer for a matched condition, follow it instead of the generic consent-first handoff defaults below.
# Decision Framework
## 1. Analyze the Request
@@ -88,7 +90,8 @@ Handle the request yourself in the following way
Transfer to a human agent when:
- User explicitly requests human assistance
- User accepts an offer to speak with a human
- A Response Guideline or Guardrail explicitly requires transfer for the matched condition
- The issue requires specialized knowledge or permissions you don't have
- Multiple attempts to help have been unsuccessful
If you cannot find needed information after checking the available information and clarifying context, ask whether the user wants to talk to another support agent. Use the `captain--tools--handoff` tool only after the user explicitly requests human assistance or accepts your offer to speak with a human. When using the tool, provide a clear reason that helps the human agent understand the context.
If you cannot find needed information after checking the available information and clarifying context, ask whether the user wants to talk to another support agent. Use the `captain--tools--handoff` tool only after the user explicitly requests human assistance, accepts your offer to speak with a human, or a Response Guideline or Guardrail explicitly requires transfer for the matched condition. When using the tool, provide a clear reason that helps the human agent understand the context.