- Newest
- Most votes
- Most comments
Yes, it is possible to enable reasoning with an inline agent using Claude 3.7 Sonnet and Claude 4 models (both Opus 4 and Sonnet 4), but there are some issues with your current implementation.
The main problem in your code is the structure of the reasoning configuration. For Claude models, the reasoning configuration should be specified under a "thinking" key rather than "reasoning_config". Also, the configuration should be placed in the additionalModelRequestFields parameter.
Here's how you should modify your code:
response = bedrock_agent_runtime.invoke_inline_agent( sessionId=session_id, inputText=input_text, enableTrace=enable_trace, endSession=end_session, streamingConfigurations=streaming_configurations, bedrockModelConfigurations=bedrock_model_configurations, prompt_override_configuration={ 'promptConfigurations': [{ "additionalModelRequestFields": { "thinking": { "type": "enabled", "budget_tokens": 2000 } }, "inferenceConfiguration": { "stopSequences": ["</answer>"], "maximumLength": 8000, "temperature": 1, # "topK": 500, # "topP": 1 }, "parserMode": "DEFAULT", "promptCreationMode": "DEFAULT", "promptState": "ENABLED", "promptType": "ORCHESTRATION", }] }, )
A few important considerations:
-
When using reasoning with Claude models, you need to set a budget for the maximum number of tokens that Claude can use for its internal reasoning process.
-
For Claude 3.7 Sonnet, you must set the temperature to 1 when reasoning is enabled, which you've already done correctly.
-
Extended thinking is supported specifically for Claude Opus 4, Claude Sonnet 4, and Claude 3.7 Sonnet models.
-
When reasoning is enabled, the API response will include thinking content blocks followed by text content blocks.
-
Note that enabling reasoning may increase latency due to the additional processing required for the reasoning process.
Make sure you're using one of the supported model IDs:
- Claude Opus 4:
anthropic.claude-opus-4-20250514-v1:0 - Claude Sonnet 4:
anthropic.claude-sonnet-4-20250514-v1:0 - Claude 3.7 Sonnet:
anthropic.claude-3-7-sonnet-20250219-v1:0
Sources
Configure response generation for reasoning models and considerations - Amazon Bedrock
Introducing Claude 4 in Amazon Bedrock, the most powerful models for coding from Anthropic | AWS News Blog
Use Anthropic Claude 3.7 Sonnet's reasoning capability on Amazon Bedrock - Amazon Bedrock
Extended thinking - Amazon Bedrock
answered a year ago
Relevant content
asked 8 months ago
- AWS OFFICIALUpdated 6 months ago
