financial_analyst_thinking.py
"""
Anthropic Financial Analyst Thinking
====================================
Cookbook example for `anthropic/financial_analyst_thinking.py`.
"""
from agno.agent import Agent
from agno.models.anthropic import Claude
from agno.tools.calculator import CalculatorTools
from agno.tools.yfinance import YFinanceTools
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
# Complex multi-step reasoning problem that demonstrates interleaved thinking
task = (
"I'm considering an investment portfolio. I want to invest $50,000 split equally "
"between Apple (AAPL) and Tesla (TSLA). Calculate how many shares of each I can buy "
"at current prices, then analyze what my total portfolio value would be if both stocks "
"increased by 15%. Also calculate what percentage return that represents on my initial investment. "
"Think through each step and show your reasoning process."
)
agent = Agent(
model=Claude(
id="claude-sonnet-4-20250514",
thinking={"type": "enabled", "budget_tokens": 2048},
betas=["interleaved-thinking-2025-05-14"],
),
tools=[
CalculatorTools(),
YFinanceTools(),
],
instructions=[
"You are a financial analysis assistant with access to calculator and stock price tools.",
"For complex problems, think through each step carefully before and after using tools.",
"Show your reasoning process and explain your calculations clearly.",
"Use the calculator tool for all mathematical operations to ensure accuracy.",
],
markdown=True,
)
agent.print_response(task, stream=True)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
pass
Run the Example
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno anthropic yfinance
3
Export your Anthropic API key
export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
$Env:ANTHROPIC_API_KEY="your_anthropic_api_key_here"
4
Run the example
Save the code above as
financial_analyst_thinking.py, then run:python financial_analyst_thinking.py