> ## 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.

# Weave

## 概述

此示例演示如何使用 Weights & Biases (WandB) 的 Weave 来记录来自 Agno 代理的模型调用。

## 代码

```python theme={null}
import weave
from agno.agent import Agent
from agno.models.openai import OpenAIChat

# 创建并配置代理
agent = Agent(model=OpenAIChat(id="gpt-4o"), markdown=True, debug_mode=True)

# 使用您的项目名称初始化 Weave
weave.init("agno")

# 定义一个运行代理的函数，并用 weave.op() 装饰
@weave.op()
def run(content: str):
    return agent.run(content)

# 使用该函数记录模型调用
run("分享一个两句话的恐怖故事")
```

## 用法

<Steps>
  <Step title="安装 Weave">
    ```bash theme={null}
    pip install agno openai weave
    ```
  </Step>

  <Step title="使用 WandB 进行身份验证">
    * 前往 [WandB](https://wandb.ai) 并从[此处](https://wandb.ai/authorize)复制您的 API 密钥。
    * 在终端提示时输入您的 API 密钥，或将其导出为环境变量：

    ```bash theme={null}
    export WANDB_API_KEY=<your-api-key>
    ```
  </Step>

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

      ```bash Windows theme={null}
      python cookbook/observability/weave_op.py
      ```
    </CodeGroup>
  </Step>
</Steps>

## 注意事项

* **初始化**: 调用 `weave.init("project-name")` 以您的项目名称初始化 Weave。
* **装饰器**: 使用 `@weave.op()` 来装饰您希望通过 Weave 记录的函数。
