代码

cookbook/models/litellm/tool_use.py
from agno.agent import Agent
from agno.models.litellm import LiteLLM
from agno.tools.yfinance import YFinanceTools

openai_agent = Agent(
    model=LiteLLM(
        id="gpt-4o",
        name="LiteLLM",
    ),
    markdown=True,
    tools=[YFinanceTools()],
)

# 提出一个可能触发工具使用的问题
openai_agent.print_response("How is TSLA stock doing right now?")

用法

1

创建虚拟环境

打开 Terminal 并创建一个 python 虚拟环境。

python3 -m venv .venv
source .venv/bin/activate
2

设置你的 API 密钥

export LITELLM_API_KEY=xxx
3

安装库

pip install -U litellm openai agno
4

运行代理

python cookbook/models/litellm/tool_use.py