Example

Use Claude with your Agent:

from phi.agent import Agent, RunResponse
from phi.model.anthropic import Claude

agent = Agent(
    model=Claude(id="claude-3-5-sonnet-20240620"),
)

# Get the response in a variable
# run: RunResponse = agent.run("Share a 2 sentence horror story.")
# print(run.content)

# Print the response on the terminal
agent.print_response("Share a 2 sentence horror story.")

Usage

You can get your API key from Anthropic here.

1

Create a virtual environment

Open the Terminal and create a python virtual environment.

python3 -m venv ~/.venvs/aienv
source ~/.venvs/aienv/bin/activate
2

Install libraries

pip install -U anthropic phidata
3

Export `ANTHROPIC_API_KEY`

export ANTHROPIC_API_KEY=xxx
4

Run Claude Agent

python cookbook/providers/claude/basic.py

Information