## 为什么你需要一个自己的AI助手

2026年,AI Agent已经不再是科幻概念。从写周报到自动回复邮件,从代码审查到数据分析,AI Agent正在重塑我们的工作方式。

在我们的小九AI百晓生评测中([查看DeepSeek Chat评测](/post/50)),DeepSeek在中文场景下表现突出,代码能力满分。今天就手把手带你搭建一个能用的AI助手。

---

## 第一步:注册并获取API Key

1. 访问 platform.deepseek.com 注册账号
2. 进入 API Keys 页面,点 Create new key
3. 复制保存 key(关闭页面就看不到了)

---

## 第二步:3行代码调通

确保已安装Python 3.8+,然后:

```bash
pip install openai
```

创建 my_first_agent.py:

```python
from openai import OpenAI

client = OpenAI(
api_key="sk-你的key",
base_url="https://api.deepseek.com/v1"
)

response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "你好"}]
)

print(response.choices[0].message.content)
```

运行 `python my_first_agent.py`,看到回复就成功了!

---

## 第三步:写一个周报生成器

把基础调用包装成实用工具:

```python
def generate_weekly_report(daily_notes):
prompt = f"根据以下工作要点生成周报,分天列出,并总结:{daily_notes}"
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": prompt}],
temperature=0.3
)
return response.choices[0].message.content

notes = "周一写API文档,周二评审需求,周三部署搜索优化"
print(generate_weekly_report(notes))
```

---

## 第四步:工具调用 - Agent的真正能力

Function Calling让AI能调用你写的函数:

```python
tools = [{
"type": "function",
"function": {
"name": "search_kb",
"description": "搜索知识库",
"parameters": {
"type": "object",
"properties": {
"query": {"type": "string"}
},
"required": ["query"]
}
}
}]
```

---

## 进阶方向

- 集成更多工具(数据库/邮件/文件)
- 用向量数据库加记忆
- 定时任务自动运行

找一个身边的重复劳动,试试用AI替代它——从能用到好用,只差一个API Key的距离。