单轮 API 调用的请求与响应结构
我们先看一个不涉及工具调用的最简单场景------用户问 "Hello, who are you?"(这里用本地部署的 Qwen3-0.6B 小模型作为示例,正好呼应本节稍后的本地 LLM 部署实验;示例中的时间戳仅作演示,与全书的时间设定无关):
```javascript
// ═══ Request constructed by the Agent framework ═══
{
"model": "Qwen3-0.6B",
"messages": [
{
"role": "system", // ← Written by developer
"content": "You are a helpful coding assistant. Follow user instructions."
},
{
"role": "user", // ← User input
"content": "Hello, who are you?"
}
]
}
```
```javascript
// ═══ Response returned by the API ═══
{
"choices": [{
"message": {
"role": "assistant", // ← Generated by model
"content": "Hi! I'm a coding assistant. I can help you write code, debug issues, and explain technical concepts. How can I help?"
}
}]
}
```
这个请求只包含两条消息:一条 system(开发者写的规则)和一条 user(用户的输入)。模型返回一条 assistant 消息作为回复。这就是大模型 API 最基本的交互模式------**每次调用都是无状态的,所有模型需要的信息必须在请求的消息列表中完整提供**。