feat(runtime): surface and recover from model refusals
Claude Fable 5 safety classifiers decline requests with HTTP 200 + stop_reason=refusal and empty content. The Anthropic stream parser never read stop_reason, so a refused turn looked like a successful empty response — the UI showed nothing and the agent appeared hung. - llm: ChatEvent carries StopReason/StopCategory on EventDone; StopReasonRefusal constant - anthropic: parse stop_reason + stop_details.category from message_delta (streaming) and the message (non-streaming); WARN log on refusal - runtime Run + RunTurn: on refusal, retry the turn once on FallbackModel (refusals are model-specific; Opus-tier has no bio/cyber classifiers), discarding any partial output; without a fallback (or if the fallback also refuses) synthesize a visible 'model declined this request' message with the policy category instead of silent emptiness
This commit is contained in:
1 parent
3064a0da14
commit
d5e8abf492
6 files changed
+320
-18
No files matched your search
@@ -135,8 +135,23 @@ type ChatEvent struct {
|
||||
ToolCall *ToolCall
|
||||
Usage *Usage
|
||||
Error error
|
||||
// StopReason carries the provider's terminal stop reason on EventDone
|
||||
// ("end_turn", "tool_use", "max_tokens", "refusal", ...). Empty when
|
||||
// the provider doesn't report one. StopReasonRefusal is the value the
|
||||
// runtime branches on: Claude Fable 5 safety classifiers decline a
|
||||
// request with HTTP 200 + stop_reason=refusal and empty content —
|
||||
// without surfacing it the turn looks like a silent empty success.
|
||||
StopReason string
|
||||
// StopCategory is the refusal policy category from stop_details
|
||||
// ("cyber", "bio", "reasoning_extraction"); informational only and
|
||||
// may be empty even on a refusal.
|
||||
StopCategory string
|
||||
}
|
||||
|
||||
// StopReasonRefusal is the StopReason value for safety-classifier and
|
||||
// model-initiated refusals (Claude Fable 5+).
|
||||
const StopReasonRefusal = "refusal"
|
||||
|
||||
// ModelInfo describes an available model.
|
||||
type ModelInfo struct {
|
||||
ID string
|
||||
|
||||
Reference in new issue
Block a user