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

# CrewAI

> 了解如何在 CrewAI 中通过 LiteLLM 和自定义 base_url 接入 siflow endpoint，编排角色型 AI 智能体工作流。

[CrewAI](https://github.com/crewAIInc/crewAI) 是一个用于编排角色型自主 AI 智能体的常用框架。它的 `LLM` 类基于 LiteLLM，并支持自定义 `base_url`，因此可以让 crew 接入 siflow endpoint。

本文默认模型为 `glm-5.2`；完整模型列表和价格请查看 [模型广场](https://console.siflow.cn/model-inference/models)。

## 配置

在 [API 密钥](https://console.siflow.cn/model-inference/api_keys) 页面创建 API Key，并将其导出为环境变量：

```bash theme={null}
export SIFLOW_API_KEY="<Your API Key>"
```

创建一个接入 siflow endpoint 的 CrewAI `LLM`，然后传给您的 agents：

```python theme={null}
import os
from crewai import LLM, Agent, Task, Crew

llm = LLM(
    model="openai/glm-5.2",
    base_url="https://api.siflow.cn/model-api/v1",
    api_key=os.environ["SIFLOW_API_KEY"],
)

agent = Agent(role="Assistant", goal="Answer briefly",
              backstory="You are concise.", llm=llm)
```

| 字段         | 说明                                                                              |
| ---------- | ------------------------------------------------------------------------------- |
| `model`    | `openai/<id>`。`openai/` 前缀会通过 OpenAI-compatible provider 路由，例如 `openai/glm-5.2` |
| `base_url` | siflow OpenAI-compatible endpoint：`https://api.siflow.cn/model-api/v1`          |
| `api_key`  | 从环境变量读取的 API Key                                                                |

这个自定义 OpenAI-compatible endpoint 需要使用 `openai/` 前缀。CrewAI 通过 LiteLLM 路由，LiteLLM 会根据 provider 前缀为这类自定义 `base_url` 选择 OpenAI-compatible client。

如果要使用多智能体工具调用或任务委派功能，请选择原生支持 tool calling 的模型。`glm-5.2` 可用。

## 验证

运行一个单 agent crew。如果返回正常补全结果，即表示连接成功：

```python theme={null}
task = Task(description="In one short sentence, which model are you?",
            expected_output="One sentence.", agent=agent)
print(Crew(agents=[agent], tasks=[task]).kickoff())
```

您也可以通过配置好的 `LLM` 直接调用：

```python theme={null}
print(llm.call("In one short sentence, which model are you?"))
# → I am GLM, a large language model developed by Z.ai.
```
