Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
refactor(providers): use native adaptive thinking from the langchaingo fork
Sergey Kozyrenkob8b90f834995
diff --git a/backend/docs/llms_how_to.md b/backend/docs/llms_how_to.mdindex b3fe1798..ed2e02db 100644--- a/backend/docs/llms_how_to.md+++ b/backend/docs/llms_how_to.md@@ -176,7 +176,7 @@ llm.GenerateContent(ctx, messages,)```-> **Adaptive thinking is the exception — do NOT set temperature for it.** Claude Opus 4.7/4.8 (and the 4.6 series when run in adaptive mode) use `thinking.type=adaptive` + `output_config.effort` and **reject every sampling parameter** (`temperature`/`top_p`/`top_k`) with HTTP 400. PentAGI handles this in `pkg/providers/anthropic/adaptive_thinking.go` and `pkg/providers/bedrock/adaptive_thinking.go`, which rewrite the request to adaptive form and strip those params for adaptive(-only) models. A model's capability is declared in its provider `models.yml` via `reasoning.mode` (`adaptive` = budget or adaptive; `adaptive-only` = adaptive required, budget returns 400); the per-agent `ReasoningConfig.Mode`/`Effort` then selects the mode at call time.+> **Adaptive thinking is the exception — do NOT set temperature for it.** Claude Opus 4.7/4.8 (and the 4.6 series when run in adaptive mode) use `thinking.type=adaptive` + `output_config.effort` and **reject every sampling parameter** (`temperature`/`top_p`/`top_k`) with HTTP 400. The forked langchaingo handles this natively: `llms.WithAdaptiveReasoning(effort)` makes the anthropic and bedrock clients emit the adaptive request shape and omit those sampling params. A model's capability is declared in its provider `models.yml` via `reasoning.mode` (`adaptive` = budget or adaptive; `adaptive-only` = adaptive required, budget returns 400); the per-agent `ReasoningConfig.Mode`/`Effort` then selects the mode at call time (PentAGI's `PrepareAdaptiveCallOptions` appends `WithAdaptiveReasoning`).#### 1.3 Interleaved Thinking with Toolsdiff --git a/backend/go.mod b/backend/go.modindex 5e4ec29b..d091d3b7 100644--- a/backend/go.mod+++ b/backend/go.mod@@ -52,7 +52,7 @@ require (github.com/vektah/gqlparser/v2 v2.5.19github.com/vxcontrol/cloud v0.9.0github.com/vxcontrol/graphiti-go-client v0.9.0- github.com/vxcontrol/langchaingo v0.1.14-update.5+ github.com/vxcontrol/langchaingo v0.1.14-update.6github.com/wasilibs/go-re2 v1.10.0github.com/xeipuuv/gojsonschema v1.2.0go.opentelemetry.io/otel v1.39.0@@ -128,7 +128,6 @@ require (github.com/felixge/httpsnoop v1.0.4 // indirectgithub.com/gabriel-vasile/mimetype v1.4.9 // indirectgithub.com/gage-technologies/mistral-go v1.1.0 // indirect- github.com/ghodss/yaml v1.0.0 // indirectgithub.com/gin-contrib/sse v0.1.0 // indirectgithub.com/go-jose/go-jose/v4 v4.1.4 // indirectgithub.com/go-logr/logr v1.4.3 // indirect@@ -233,7 +232,6 @@ require (google.golang.org/genproto/googleapis/api v0.0.0-20251202230838-ff82c1b0f217 // indirectgoogle.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirectgoogle.golang.org/protobuf v1.36.10 // indirect- gopkg.in/yaml.v2 v2.4.0 // indirectgotest.tools/v3 v3.5.1 // indirectnhooyr.io/websocket v1.8.7 // indirect)diff --git a/backend/go.sum b/backend/go.sumindex 4dbc2979..582cc75f 100644--- a/backend/go.sum+++ b/backend/go.sum@@ -220,7 +220,6 @@ github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvgithub.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=github.com/gage-technologies/mistral-go v1.1.0 h1:POv1wM9jA/9OBXGV2YdPi9Y/h09+MjCbUF+9hRYlVUI=github.com/gage-technologies/mistral-go v1.1.0/go.mod h1:tF++Xt7U975GcLlzhrjSQb8l/x+PrriO9QEdsgm9l28=-github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=github.com/gin-contrib/cors v1.7.2 h1:oLDHxdg8W/XDoN/8zamqk/Drgt4oVZDvaV0YmvVICQw=github.com/gin-contrib/cors v1.7.2/go.mod h1:SUJVARKgQ40dmrzgXEVxj2m7Ig1v1qIboQkPDTQ9t2E=@@ -631,8 +630,8 @@ github.com/vxcontrol/cloud v0.9.0 h1:p7xYTgUctbY8w6YfhugNzvfi3/0EQoZGumMe67keAnggithub.com/vxcontrol/cloud v0.9.0/go.mod h1:AeiQFqiMgJJAXy6FYXtDS2a3P/PMB56iiBNY2vGrZhQ=github.com/vxcontrol/graphiti-go-client v0.9.0 h1:3GxpFmQoHmz/d7/9tyEqD8+S99v2cuqG1UEmrbAFrLU=github.com/vxcontrol/graphiti-go-client v0.9.0/go.mod h1:6UHL5uqAKp4KAdziva4qgcAxFtBzU05Hm/BAo4NkAuo=-github.com/vxcontrol/langchaingo v0.1.14-update.5 h1:QIib3znyGg/YnRSRB3ZMxwwfRE2vy+xZ2gDH6zwj9fk=-github.com/vxcontrol/langchaingo v0.1.14-update.5/go.mod h1:fJal4XqJsYXRFTbAPJpwcJdztea9+1174fSDYacgctU=+github.com/vxcontrol/langchaingo v0.1.15-0.20260621133759-91d8dfdd9c89 h1:voo1O4CrwWnWxiHDbkpSugMMZtzB3nDda10Ligesz5k=+github.com/vxcontrol/langchaingo v0.1.15-0.20260621133759-91d8dfdd9c89/go.mod h1:fJal4XqJsYXRFTbAPJpwcJdztea9+1174fSDYacgctU=github.com/wasilibs/go-re2 v1.10.0 h1:vQZEBYZOCA9jdBMmrO4+CvqyCj0x4OomXTJ4a5/urQ0=github.com/wasilibs/go-re2 v1.10.0/go.mod h1:k+5XqO2bCJS+QpGOnqugyfwC04nw0jaglmjrrkG8U6o=github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 h1:OvLBa8SqJnZ6P+mjlzc2K7PM22rRUPE1x32G9DTPrC4=diff --git a/backend/pkg/providers/anthropic/adaptive_thinking.go b/backend/pkg/providers/anthropic/adaptive_thinking.godeleted file mode 100644index b3887f60..00000000--- a/backend/pkg/providers/anthropic/adaptive_thinking.go+++ /dev/null@@ -1,78 +0,0 @@-package anthropic--import (- "bytes"- "encoding/json"- "fmt"- "io"- "net/http"- "strconv"-- "pentagi/pkg/providers/pconfig"-)--// adaptiveThinkingTransport rewrites the outgoing Anthropic Messages request body-// to use adaptive thinking when the call context carries an effort (set by-// pconfig.PrepareAdaptiveCallOptions). langchaingo only emits budget thinking, but-// Claude Opus 4.7/4.8 only support thinking.type=adaptive and reject sampling params.-type adaptiveThinkingTransport struct {- base http.RoundTripper-}--func (t *adaptiveThinkingTransport) RoundTrip(req *http.Request) (*http.Response, error) {- effort, ok := pconfig.AdaptiveEffortFromContext(req.Context())- if !ok || req.Body == nil {- return t.base.RoundTrip(req)- }-- body, err := io.ReadAll(req.Body)- _ = req.Body.Close()- if err != nil {- return nil, fmt.Errorf("read Anthropic request body: %w", err)- }-- updatedBody, err := rewriteAdaptiveThinkingBody(body, effort)- if err != nil {- return nil, err- }-- clone := req.Clone(req.Context())- clone.Body = io.NopCloser(bytes.NewReader(updatedBody))- clone.ContentLength = int64(len(updatedBody))- clone.Header.Set("Content-Length", strconv.Itoa(len(updatedBody)))- clone.GetBody = func() (io.ReadCloser, error) {- return io.NopCloser(bytes.NewReader(updatedBody)), nil- }-- return t.base.RoundTrip(clone)-}--func rewriteAdaptiveThinkingBody(body []byte, effort string) ([]byte, error) {- // langchaingo emits budget-based Anthropic thinking; adaptive thinking expects- // thinking.type=adaptive plus a top-level output_config.effort. In the Anthropic- // Messages API thinking and the sampling params live at the top level (unlike the- // Bedrock Converse body).- var payload map[string]any- if err := json.Unmarshal(body, &payload); err != nil {- return nil, fmt.Errorf("decode Anthropic request body: %w", err)- }-- thinking, ok := payload["thinking"].(map[string]any)- if !ok {- return body, nil- }-- thinking["type"] = "adaptive"- // Opus 4.7/4.8 default thinking.display to "omitted" (empty reasoning text);- // force "summarized" so reasoning stays visible in the UI.- thinking["display"] = "summarized"- delete(thinking, "budget_tokens")- payload["output_config"] = map[string]any{"effort": effort}-- // Adaptive Claude models reject sampling params (Opus 4.7+ return 400). langchaingo's- // Messages payload only serializes temperature/top_p, so those are the only keys to strip.- delete(payload, "temperature")- delete(payload, "top_p")-- return json.Marshal(payload)-}diff --git a/backend/pkg/providers/anthropic/adaptive_thinking_test.go b/backend/pkg/providers/anthropic/adaptive_thinking_test.godeleted file mode 100644index a95b43a5..00000000--- a/backend/pkg/providers/anthropic/adaptive_thinking_test.go+++ /dev/null@@ -1,106 +0,0 @@-package anthropic--import (- "context"- "encoding/json"- "io"- "net/http"- "net/http/httptest"- "sync"- "testing"-- "pentagi/pkg/config"- "pentagi/pkg/providers/pconfig"- "pentagi/pkg/providers/provider"-- "github.com/stretchr/testify/assert"- "github.com/stretchr/testify/require"-)--func TestRewriteAdaptiveThinkingBody(t *testing.T) {- body := []byte(`{- "model": "claude-opus-4-8",- "max_tokens": 16000,- "temperature": 1.0,- "top_p": 0.95,- "thinking": {"type": "enabled", "budget_tokens": 4096},- "messages": []- }`)-- updatedBody, err := rewriteAdaptiveThinkingBody(body, "xhigh")- require.NoError(t, err)-- var payload map[string]any- require.NoError(t, json.Unmarshal(updatedBody, &payload))-- thinking := payload["thinking"].(map[string]any)- assert.Equal(t, "adaptive", thinking["type"])- assert.Equal(t, "summarized", thinking["display"])- assert.NotContains(t, thinking, "budget_tokens")-- outputConfig := payload["output_config"].(map[string]any)- assert.Equal(t, "xhigh", outputConfig["effort"])-- // Opus 4.7+ reject sampling params (top-level in the Anthropic Messages API).- assert.NotContains(t, payload, "temperature")- assert.NotContains(t, payload, "top_p")- assert.NotContains(t, payload, "top_k")-}--func TestRewriteAdaptiveThinkingBodyWithoutThinking(t *testing.T) {- body := []byte(`{"model":"claude-opus-4-6","max_tokens":1024}`)-- updatedBody, err := rewriteAdaptiveThinkingBody(body, "high")- require.NoError(t, err)- assert.JSONEq(t, string(body), string(updatedBody))-}--// TestAdaptiveThinkingRoundTrip verifies the full local chain (adaptive-only model-// -> prepareCallOptions -> ctx -> langchaingo -> RoundTripper rewrite) by capturing-// the request that actually hits the wire, without needing a real API call.-func TestAdaptiveThinkingRoundTrip(t *testing.T) {- var (- mu sync.Mutex- captured []byte- )- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- body, _ := io.ReadAll(r.Body)- mu.Lock()- captured = body- mu.Unlock()- w.Header().Set("Content-Type", "application/json")- _, _ = w.Write([]byte(`{"id":"msg_1","type":"message","role":"assistant","model":"claude-opus-4-8","content":[{"type":"text","text":"ok"}],"stop_reason":"end_turn","usage":{"input_tokens":1,"output_tokens":1}}`))- }))- defer server.Close()-- // simple -> claude-opus-4-8 (adaptive-only in models.yml) with temperature set,- // so the backstop must force adaptive and the rewrite must strip temperature.- providerConfig, err := BuildProviderConfig([]byte("simple:\n model: claude-opus-4-8\n temperature: 1.0\n n: 1\n max_tokens: 1000\n"))- require.NoError(t, err)-- cfg := &config.Config{AnthropicAPIKey: "test-key", AnthropicServerURL: server.URL}- prov, err := New(cfg, provider.DefaultProviderNameAnthropic, providerConfig)- require.NoError(t, err)-- // The response is a stub; we only assert on the captured request body.- _, _ = prov.Call(context.Background(), pconfig.OptionsTypeSimple, "hi")-- mu.Lock()- body := captured- mu.Unlock()- require.NotEmpty(t, body, "no request reached the server")-- var payload map[string]any- require.NoError(t, json.Unmarshal(body, &payload))-- thinking, ok := payload["thinking"].(map[string]any)- require.True(t, ok, "request must carry a thinking block")- assert.Equal(t, "adaptive", thinking["type"])- assert.Equal(t, "summarized", thinking["display"])- assert.NotContains(t, payload, "temperature", "sampling params must be stripped for adaptive models")- if oc, ok := payload["output_config"].(map[string]any); ok {- assert.Equal(t, "high", oc["effort"])- } else {- t.Error("request must carry output_config.effort")- }-}diff --git a/backend/pkg/providers/anthropic/anthropic.go b/backend/pkg/providers/anthropic/anthropic.goindex 87ae9fc1..8bda8f7f 100644--- a/backend/pkg/providers/anthropic/anthropic.go+++ b/backend/pkg/providers/anthropic/anthropic.go@@ -3,7 +3,6 @@ package anthropicimport ("context""embed"- "net/http""pentagi/pkg/config""pentagi/pkg/providers/pconfig"@@ -75,12 +74,6 @@ func New(return nil, err}- base := httpClient.Transport- if base == nil {- base = http.DefaultTransport- }- httpClient.Transport = &adaptiveThinkingTransport{base: base}-models, err := DefaultModels()if err != nil {return nil, errdiff --git a/backend/pkg/providers/bedrock/adaptive_thinking.go b/backend/pkg/providers/bedrock/adaptive_thinking.godeleted file mode 100644index cb28b21c..00000000--- a/backend/pkg/providers/bedrock/adaptive_thinking.go+++ /dev/null@@ -1,98 +0,0 @@-package bedrock--import (- "bytes"- "context"- "encoding/json"- "fmt"- "io"- "strconv"-- "pentagi/pkg/providers/pconfig"-- "github.com/aws/smithy-go/middleware"- smithyhttp "github.com/aws/smithy-go/transport/http"-)--func addAdaptiveThinkingMiddleware(stack *middleware.Stack) error {- return stack.Build.Add(middleware.BuildMiddlewareFunc(- "PentAGIBedrockAdaptiveThinking",- func(ctx context.Context, in middleware.BuildInput, next middleware.BuildHandler) (- middleware.BuildOutput,- middleware.Metadata,- error,- ) {- effort, ok := pconfig.AdaptiveEffortFromContext(ctx)- if !ok {- return next.HandleBuild(ctx, in)- }-- req, ok := in.Request.(*smithyhttp.Request)- if !ok || req.GetStream() == nil {- return next.HandleBuild(ctx, in)- }-- body, err := io.ReadAll(req.GetStream())- if err != nil {- return middleware.BuildOutput{}, middleware.Metadata{}, fmt.Errorf("read Bedrock request body: %w", err)- }-- updatedBody, err := rewriteAdaptiveThinkingBody(body, effort)- if err != nil {- return middleware.BuildOutput{}, middleware.Metadata{}, err- }-- updatedReq, err := req.SetStream(bytes.NewReader(updatedBody))- if err != nil {- return middleware.BuildOutput{}, middleware.Metadata{}, fmt.Errorf("replace Bedrock request body: %w", err)- }- updatedReq.ContentLength = int64(len(updatedBody))- updatedReq.Header.Set("Content-Length", strconv.Itoa(len(updatedBody)))- in.Request = updatedReq-- return next.HandleBuild(ctx, in)- },- ), middleware.After)-}--func rewriteAdaptiveThinkingBody(body []byte, effort string) ([]byte, error) {- // langchaingo currently emits budget-based Anthropic thinking for Bedrock;- // Claude adaptive thinking expects thinking.type=adaptive plus output_config.effort.- var payload map[string]any- if err := json.Unmarshal(body, &payload); err != nil {- return nil, fmt.Errorf("decode Bedrock request body: %w", err)- }-- fields, ok := payload["additionalModelRequestFields"].(map[string]any)- if !ok {- return body, nil- }-- thinking, ok := fields["thinking"].(map[string]any)- if !ok {- return body, nil- }-- thinking["type"] = "adaptive"- // Opus 4.7/4.8 default thinking.display to "omitted" (empty reasoning text);- // force "summarized" so reasoning stays visible in the UI.- thinking["display"] = "summarized"- delete(thinking, "budget_tokens")- fields["output_config"] = map[string]any{- "effort": effort,- }-- // Adaptive Claude models reject sampling params (Opus 4.7+ return 400 for any- // temperature/top_p/top_k); drop them from the Converse inferenceConfig.- if inferenceConfig, ok := payload["inferenceConfig"].(map[string]any); ok {- delete(inferenceConfig, "temperature")- delete(inferenceConfig, "topP")- }-- updatedBody, err := json.Marshal(payload)- if err != nil {- return nil, fmt.Errorf("encode Bedrock request body: %w", err)- }-- return updatedBody, nil-}diff --git a/backend/pkg/providers/bedrock/adaptive_thinking_test.go b/backend/pkg/providers/bedrock/adaptive_thinking_test.godeleted file mode 100644index 9e1245ee..00000000--- a/backend/pkg/providers/bedrock/adaptive_thinking_test.go+++ /dev/null@@ -1,113 +0,0 @@-package bedrock--import (- "context"- "encoding/json"- "testing"-- "pentagi/pkg/config"- "pentagi/pkg/providers/pconfig"-- "github.com/stretchr/testify/assert"- "github.com/stretchr/testify/require"- "github.com/vxcontrol/langchaingo/llms"-)--func TestRewriteAdaptiveThinkingBody(t *testing.T) {- body := []byte(`{- "additionalModelRequestFields": {- "thinking": {- "type": "enabled",- "budget_tokens": 4096- }- },- "inferenceConfig": {- "maxTokens": 16384- }- }`)-- updatedBody, err := rewriteAdaptiveThinkingBody(body, "xhigh")- require.NoError(t, err)-- var payload map[string]any- require.NoError(t, json.Unmarshal(updatedBody, &payload))-- fields := payload["additionalModelRequestFields"].(map[string]any)- thinking := fields["thinking"].(map[string]any)- outputConfig := fields["output_config"].(map[string]any)-- assert.Equal(t, "adaptive", thinking["type"])- assert.NotContains(t, thinking, "budget_tokens")- assert.Equal(t, "xhigh", outputConfig["effort"])- assert.Equal(t, map[string]any{"maxTokens": float64(16384)}, payload["inferenceConfig"])-}--func TestRewriteAdaptiveThinkingBodyWithoutThinking(t *testing.T) {- body := []byte(`{"inferenceConfig":{"maxTokens":1024}}`)-- updatedBody, err := rewriteAdaptiveThinkingBody(body, "high")- require.NoError(t, err)- assert.JSONEq(t, string(body), string(updatedBody))-}--func TestRewriteAdaptiveThinkingBodyStripsSamplingAndSetsDisplay(t *testing.T) {- body := []byte(`{- "additionalModelRequestFields": {- "thinking": {"type": "enabled", "budget_tokens": 4096}- },- "inferenceConfig": {- "maxTokens": 16384,- "temperature": 1.0,- "topP": 0.95- }- }`)-- updatedBody, err := rewriteAdaptiveThinkingBody(body, "high")- require.NoError(t, err)-- var payload map[string]any- require.NoError(t, json.Unmarshal(updatedBody, &payload))-- thinking := payload["additionalModelRequestFields"].(map[string]any)["thinking"].(map[string]any)- assert.Equal(t, "adaptive", thinking["type"])- assert.Equal(t, "summarized", thinking["display"])-- // Opus 4.7+ reject sampling params; only maxTokens must survive in inferenceConfig.- assert.Equal(t, map[string]any{"maxTokens": float64(16384)}, payload["inferenceConfig"])-}--// TestBackstopForcesAdaptiveForAdaptiveOnlyModel verifies that an adaptive-only-// model (from models.yml) forces adaptive thinking via PrepareAdaptiveCallOptions-// even when the agent config carries no reasoning block.-func TestBackstopForcesAdaptiveForAdaptiveOnlyModel(t *testing.T) {- models, err := DefaultModels(&config.Config{})- require.NoError(t, err)-- pc, err := BuildProviderConfig([]byte("simple:\n model: us.anthropic.claude-opus-4-8\n temperature: 1.0\n n: 1\n max_tokens: 4000\n"))- require.NoError(t, err)-- assert.True(t, pc.UsesAdaptiveThinking(models, pconfig.OptionsTypeSimple),- "adaptive-only model must force adaptive even without an agent reasoning block")-- ctx, options := pc.PrepareAdaptiveCallOptions(context.Background(), models, pconfig.OptionsTypeSimple, nil)- effort, ok := pconfig.AdaptiveEffortFromContext(ctx)- assert.True(t, ok, "effort must be installed in context for the middleware")- assert.Equal(t, string(llms.ReasoningHigh), effort)- assert.NotEmpty(t, options, "WithReasoning must be appended so langchaingo emits a thinking block")-}--func TestBackstopLeavesNonReasoningModelUntouched(t *testing.T) {- models, err := DefaultModels(&config.Config{})- require.NoError(t, err)-- // gpt-oss has no adaptive-only descriptor; with no agent reasoning block it must not force adaptive.- pc, err := BuildProviderConfig([]byte("simple:\n model: openai.gpt-oss-120b-1:0\n temperature: 0.5\n n: 1\n max_tokens: 4000\n"))- require.NoError(t, err)-- assert.False(t, pc.UsesAdaptiveThinking(models, pconfig.OptionsTypeSimple))-- ctx, options := pc.PrepareAdaptiveCallOptions(context.Background(), models, pconfig.OptionsTypeSimple, nil)- _, ok := pconfig.AdaptiveEffortFromContext(ctx)- assert.False(t, ok, "no adaptive effort should be set for a non-adaptive model")- assert.Empty(t, options)-}diff --git a/backend/pkg/providers/bedrock/bedrock.go b/backend/pkg/providers/bedrock/bedrock.goindex 37427121..cc217de6 100644--- a/backend/pkg/providers/bedrock/bedrock.go+++ b/backend/pkg/providers/bedrock/bedrock.go@@ -20,7 +20,6 @@ import ("github.com/aws/aws-sdk-go-v2/credentials""github.com/aws/aws-sdk-go-v2/service/bedrockruntime"smithybearer "github.com/aws/smithy-go/auth/bearer"- "github.com/aws/smithy-go/middleware""github.com/invopop/jsonschema""github.com/vxcontrol/langchaingo/llms""github.com/vxcontrol/langchaingo/llms/bedrock"@@ -135,9 +134,6 @@ func New() (provider.Provider, error) {opts := []func(*bconfig.LoadOptions) error{bconfig.WithRegion(cfg.BedrockRegion),- bconfig.WithAPIOptions([]func(*middleware.Stack) error{- addAdaptiveThinkingMiddleware,- }),}// Choose authentication strategy based on configurationdiff --git a/backend/pkg/providers/pconfig/config.go b/backend/pkg/providers/pconfig/config.goindex 0f8e0e08..ce722c40 100644--- a/backend/pkg/providers/pconfig/config.go+++ b/backend/pkg/providers/pconfig/config.go@@ -716,9 +716,8 @@ func (ac *AgentConfig) BuildOptions() []llms.CallOption {if _, ok := ac.raw["reasoning"]; ok && !ac.Reasoning.IsZero() {switch ac.Reasoning.EffectiveMode() {case ReasoningModeAdaptive:- // Adaptive thinking is applied per-call by the provider that supports it- // (Bedrock rewrites the Converse body in prepareCallOptions); no generic- // CallOption is emitted here.+ // Adaptive thinking is applied per-call by PrepareAdaptiveCallOptions+ // (it appends llms.WithAdaptiveReasoning); no CallOption is emitted here.case ReasoningModeBudget:if ac.Reasoning.MaxTokens > 0 && ac.Reasoning.MaxTokens <= 32000 {options = append(options, llms.WithReasoning(llms.ReasoningNone, ac.Reasoning.MaxTokens))@@ -970,27 +969,6 @@ func (pc *ProviderConfig) GetPriceInfoForType(optType ProviderOptionsType) *Pricreturn nil}-// Adaptive thinking is requested as a budget thinking block (via WithReasoning),-// which the bedrock/anthropic transport interceptors rewrite to-// thinking.type=adaptive + output_config.effort. The chosen effort travels to the-// interceptor on the request context.-type adaptiveEffortContextKey struct{}--// WithAdaptiveEffort threads the adaptive-thinking effort onto ctx. Empty effort-// defaults to "high" (the API rejects an empty effort).-func WithAdaptiveEffort(ctx context.Context, effort string) context.Context {- if effort == "" {- effort = string(llms.ReasoningHigh)- }-- return context.WithValue(ctx, adaptiveEffortContextKey{}, effort)-}--func AdaptiveEffortFromContext(ctx context.Context) (string, bool) {- effort, ok := ctx.Value(adaptiveEffortContextKey{}).(string)- return effort, ok && effort != ""-}-func (pc *ProviderConfig) modelReasoningMode(models ModelsConfig, opt ProviderOptionsType) ModelReasoningMode {agentConfig := pc.AgentConfigForType(opt)if agentConfig == nil || agentConfig.Model == "" {@@ -1027,9 +1005,10 @@ func (pc *ProviderConfig) UsesAdaptiveThinking(models ModelsConfig, opt Providerreturn ok && reasoning.EffectiveMode() == ReasoningModeAdaptive}-// PrepareAdaptiveCallOptions threads the effort onto ctx and appends the budget-// thinking CallOption that the interceptor rewrites to adaptive form. No-op for-// non-adaptive calls.+// PrepareAdaptiveCallOptions appends the adaptive-thinking CallOption for agents+// that require it. No-op for non-adaptive calls. The langchaingo provider emits+// thinking.type=adaptive + output_config.effort and omits sampling params; an+// empty effort defaults to "high" there.func (pc *ProviderConfig) PrepareAdaptiveCallOptions(ctx context.Context,models ModelsConfig,@@ -1041,8 +1020,7 @@ func (pc *ProviderConfig) PrepareAdaptiveCallOptions(}reasoning, _ := pc.reasoningConfigForType(opt)- ctx = WithAdaptiveEffort(ctx, string(reasoning.Effort))- options = append(options, llms.WithReasoning(llms.ReasoningHigh, 0))+ options = append(options, llms.WithAdaptiveReasoning(reasoning.Effort))return ctx, options}