fix(devin): honor Claude mid-conversation effort directives when selecting model variants

- Override the translated top-level placeholder thinking level with thinking.ClaudeEffortDirective in DevinExecutor for Claude-sourced requests.
- Preserve model suffix precedence and disabled thinking handling when resolving the Devin upstream chat model UID.

Closes: #7235
This commit is contained in:
Luis Pater
2026-11-04 02:46:26 +08:00
parent fb30a9e8bb
commit 061ffe6fbc
2 changed files with 64 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
package executor
import (
"context"
"testing"
"github.com/router-for-me/CLIProxyAPI/v8/internal/config"
"github.com/router-for-me/CLIProxyAPI/v8/internal/runtime/executor/helps"
cliproxyauth "github.com/router-for-me/CLIProxyAPI/v8/sdk/cliproxy/auth"
cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v8/sdk/cliproxy/executor"
sdktranslator "github.com/router-for-me/CLIProxyAPI/v8/sdk/translator"
)
func TestDevinExecutorUsesClaudeEffortDirective(t *testing.T) {
const model = "devin/claude-opus-5-5"
const topLevelOnly = `{"model":"` + model + `","max_tokens":1024,"thinking":{"type":"adaptive"},"output_config":{"effort":"low"},` +
`"messages":[{"role":"user","content":"hi"}]}`
const withDirectives = `{"model":"` + model + `","max_tokens":1024,"thinking":{"type":"adaptive"},"output_config":{"effort":"low"},` +
`"messages":[{"role":"system","content":[],"output_config":{"effort":"medium"}},{"role":"user","content":"first"},` +
`{"role":"assistant","content":"ok"},{"role":"system","content":[],"output_config":{"effort":"high"}},{"role":"user","content":"hi"}]}`
const disabledWithDirective = `{"model":"` + model + `","max_tokens":1024,"thinking":{"type":"disabled"},` +
`"messages":[{"role":"system","content":[],"output_config":{"effort":"high"}},{"role":"user","content":"hi"}]}`
wantLow := helps.ResolveDevinChatModelUID(model, "low", 0)
wantMedium := helps.ResolveDevinChatModelUID(model, "medium", 0)
wantNone := helps.ResolveDevinChatModelUID(model, "none", 0)
wantHigh := helps.ResolveDevinChatModelUID(model, "high", 0)
if wantLow == wantHigh || wantNone == wantHigh || wantMedium == wantHigh {
t.Fatalf("fixture model does not separate low %q, medium %q, none %q and high %q", wantLow, wantMedium, wantNone, wantHigh)
}
exec := NewDevinExecutor(&config.Config{})
auth := &cliproxyauth.Auth{ID: "devin-effort-directive", Provider: "devin", Attributes: map[string]string{"api_key": "test-key"}}
opts := cliproxyexecutor.Options{SourceFormat: sdktranslator.FormatClaude}
for _, tc := range []struct {
name string
model string
payload string
want string
}{
{name: "top-level effort only", model: model, payload: topLevelOnly, want: wantLow},
{name: "last directive wins over the top-level placeholder", model: model, payload: withDirectives, want: wantHigh},
{name: "model suffix wins over directive", model: model + "(medium)", payload: withDirectives, want: wantMedium},
{name: "disabled thinking keeps a historical directive from selecting a variant", model: model, payload: disabledWithDirective, want: wantNone},
} {
t.Run(tc.name, func(t *testing.T) {
req := cliproxyexecutor.Request{Model: tc.model, Payload: []byte(tc.payload)}
_, chatModelUID, _, err := exec.prepareDevinHTTPRequest(context.Background(), auth, req, opts)
if err != nil {
t.Fatalf("prepareDevinHTTPRequest: %v", err)
}
if chatModelUID != tc.want {
t.Fatalf("chat model uid = %q, want %q", chatModelUID, tc.want)
}
})
}
}

View File

@@ -415,6 +415,13 @@ func (e *DevinExecutor) prepareDevinHTTPRequest(ctx context.Context, auth *clipr
payload = translated.Body
}
systemPrompt, prompts, tools, temp, maxTokens, sessionID, cascadeID, thinkingLevel, budgetTokens := parseInteractionsPayload(payload, opts.OriginalRequest)
// Translation drops Claude effort directives and keeps only the top-level
// effort, which directive-sending clients pin to a cache placeholder.
if opts.SourceFormat == sdktranslator.FormatClaude {
if directive := thinking.ClaudeEffortDirective(req.Payload); directive != "" {
thinkingLevel = directive
}
}
// Devin cannot fetch a remote uri or take audio, video or documents. A user turn left
// with nothing else to send is refused here, before any upstream call.
prompts, errTurns := helps.CheckDevinUserTurns(prompts)