> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Ollama 代理

## 代码

```python cookbook/apps/playground/ollama_agents.py theme={null}
from agno.agent import Agent
from agno.models.ollama import Ollama
from agno.playground import Playground
from agno.storage.sqlite import SqliteStorage
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.yfinance import YFinanceTools
from agno.tools.youtube import YouTubeTools

local_agent_storage_file: str = "tmp/local_agents.db"
common_instructions = [
    "如果用户询问关于你或你的技能，请告知你的名字和角色。",
]

web_agent = Agent(
    name="Web Agent",
    role="搜索网络信息",
    agent_id="web-agent",
    model=Ollama(id="llama3.1:8b"),
    tools=[DuckDuckGoTools()],
    instructions=["始终包含来源。"] + common_instructions,
    storage=SqliteStorage(
        table_name="web_agent",
        db_file=local_agent_storage_file,
        auto_upgrade_schema=True,
    ),
    show_tool_calls=True,
    add_history_to_messages=True,
    num_history_responses=2,
    add_name_to_instructions=True,
    add_datetime_to_instructions=True,
    markdown=True,
)

finance_agent = Agent(
    name="Finance Agent",
    role="获取财务数据",
    agent_id="finance-agent",
    model=Ollama(id="llama3.1:8b"),
    tools=[
        YFinanceTools(
            stock_price=True,
            analyst_recommendations=True,
            company_info=True,
            company_news=True,
        )
    ],
    description="你是一位投资分析师，负责研究股票并帮助用户做出明智的决策。",
    instructions=["始终使用表格展示数据"] + common_instructions,
    storage=SqliteStorage(
        table_name="finance_agent",
        db_file=local_agent_storage_file,
        auto_upgrade_schema=True,
    ),
    add_history_to_messages=True,
    num_history_responses=5,
    add_name_to_instructions=True,
    add_datetime_to_instructions=True,
    markdown=True,
)


youtube_agent = Agent(
    name="YouTube Agent",
    role="理解 YouTube 视频并回答问题",
    agent_id="youtube-agent",
    model=Ollama(id="llama3.1:8b"),
    tools=[YouTubeTools()],
    description="你是一个 YouTube 代理，拥有理解 YouTube 视频和回答相关问题的特殊技能。",
    instructions=[
        "使用视频 URL，通过 `get_youtube_video_data` 工具获取视频数据，并通过 `get_youtube_video_data` 工具获取字幕。",
        "根据视频数据和字幕，以引人入胜且深思熟虑的方式回答用户的问题。重点关注最重要的细节。",
        "如果你在视频中找不到答案，请说明情况并请求用户提供更多详细信息。",
        "保持回答简洁而引人入胜。",
    ]
    + common_instructions,
    add_history_to_messages=True,
    num_history_responses=5,
    show_tool_calls=True,
    add_name_to_instructions=True,
    add_datetime_to_instructions=True,
    storage=SqliteStorage(
        table_name="youtube_agent",
        db_file=local_agent_storage_file,
        auto_upgrade_schema=True,
    ),
    markdown=True,
)

playground = Playground(
    agents=[web_agent, finance_agent, youtube_agent],
    name="Ollama Agents",
    description="Ollama 代理的游乐场",
    app_id="ollama-agents",
)
app = playground.get_app(use_async=False)


if __name__ == "__main__":
    playground.serve(app="ollama_agents:app", reload=True)

```

## 用法

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="安装 Ollama">
    <p>
      请按照 [Ollama.com](https://ollama.com) 上的说明下载并安装 Ollama。
    </p>
  </Step>

  <Step title="拉取模型">
    ```bash theme={null}
    ollama pull llama3.1:8b
    ```
  </Step>

  <Step title="安装库">
    ```bash theme={null}
    pip install -U "uvicorn[standard]" ollama duckduckgo-search yfinance pypdf sqlalchemy 'fastapi[standard]' youtube-transcript-api agno
    ```
  </Step>

  <Step title="运行代理">
    <CodeGroup>
      ```bash Mac theme={null}
      python cookbook/apps/playground/ollama_agents.py
      ```

      ```bash Windows theme={null}
      python cookbook/apps/playground/ollama_agents.py
      ```
    </CodeGroup>
  </Step>
</Steps>
