Vertex AI Claude Adaptive Thinking

Use adaptive thinking with effort levels to control reasoning depth on Claude VertexAI.

Use adaptive thinking and an effort level to control Claude's reasoning on Vertex AI.

The source's claude-sonnet-4-6@20250514 ID is not the published Vertex AI model ID. Apply the correction below before running.

adaptive_thinking.py
"""
VertexAI Claude Adaptive Thinking
=================================

Cookbook example demonstrating adaptive thinking with output_config on VertexAI.

For Claude 4.6 VertexAI models, use adaptive thinking with the effort parameter
to control thinking depth. Valid effort values:
- "low": Most efficient, significant token savings
- "medium": Balanced approach with moderate savings
- "high": Default, high capability for complex reasoning
- "max": Absolute maximum capability (Opus 4.6 only)

Prerequisites:
- Set GOOGLE_CLOUD_PROJECT and CLOUD_ML_REGION environment variables
- Authenticate with: gcloud auth application-default login
"""

from agno.agent import Agent
from agno.models.vertexai.claude import Claude

# ---------------------------------------------------------------------------
# Create Agent with Adaptive Thinking
# ---------------------------------------------------------------------------

agent = Agent(
    model=Claude(
        id="claude-sonnet-4-6@20250514",
        max_tokens=4096,
        thinking={"type": "adaptive"},
        output_config={"effort": "high"},
    ),
    markdown=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    # Complex reasoning task that benefits from extended thinking
    agent.print_response(
        "Explain the key differences between recursion and iteration, "
        "and when you would choose one over the other in software development."
    )

    # With streaming
    agent.print_response(
        "What are the trade-offs between microservices and monolithic architectures?",
        stream=True,
    )

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno "anthropic[vertex]"

Set up Google Cloud access

Use a project with billing and aiplatform.googleapis.com enabled, enable the chosen Claude model in Model Garden, and give your calling identity permission to use it. Follow Google's Claude setup guide. Install the Google Cloud CLI for the local sign-in command below.

Set the project and a location supported by your model. us-east5 is a supported example for Sonnet 4 and Sonnet 4.6; check the model's current availability before switching models or locations.

export ANTHROPIC_VERTEX_PROJECT_ID="your-project-id"
export CLOUD_ML_REGION="us-east5"

Authenticate locally with Application Default Credentials:

gcloud auth application-default login

ADC supplies credentials; it does not enable models or grant IAM permissions. These examples authenticate to Google Cloud without an Anthropic API key.

Use the published model ID

Replace claude-sonnet-4-6@20250514 with claude-sonnet-4-6 in your saved Python file. Keep thinking={"type": "adaptive"} and output_config={"effort": "high"}.

Run the example

Save the code above as adaptive_thinking.py, then run:

python adaptive_thinking.py

Full source: cookbook/90_models/vertexai/claude/adaptive_thinking.py