cURL
curl -N -X POST 'http://localhost:8000/run_sse' \
-H 'Content-Type: application/json' \
-d '{"appName": "travel_assistant", "userId": "user-001", "sessionId": "session-001", "newMessage": {"role": "user", "parts": [{"text": "Plan a day in Beijing"}]}, "streaming": true}'import requests
url = "http://localhost:8000/run_sse"
payload = {
"userId": "user-001",
"sessionId": "session-001"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({userId: 'user-001', sessionId: 'session-001'})
};
fetch('http://localhost:8000/run_sse', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));"data: {\"content\":{\"role\":\"model\",\"parts\":[{\"text\":\"Hello\"}]},\"author\":\"travel_assistant\",\"invocationId\":\"invocation-001\",\"id\":\"event-001\",\"timestamp\":1789603200}\n\n"{
"detail": "<string>"
}{
"detail": "<string>"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}智能体运行
流式运行智能体
以 text/event-stream 返回事件,每条消息使用 data: 加 JSON 事件;streaming=true 时请求模型的增量流式输出
streaming 默认 false,此时仍使用 SSE 传输完整事件。成功流中的 JSON 事件使用 Event 结构;流已开始后的错误以 data: {"error":"..."} 发送。使用 curl -N 查看实时输出;交互式请求面板不保证逐事件展示
默认需先创建会话;启用 --auto_create_session 后可自动创建。appName 可在设置 ADK_DEFAULT_APP_NAME 时省略
POST
/
run_sse
cURL
curl -N -X POST 'http://localhost:8000/run_sse' \
-H 'Content-Type: application/json' \
-d '{"appName": "travel_assistant", "userId": "user-001", "sessionId": "session-001", "newMessage": {"role": "user", "parts": [{"text": "Plan a day in Beijing"}]}, "streaming": true}'import requests
url = "http://localhost:8000/run_sse"
payload = {
"userId": "user-001",
"sessionId": "session-001"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({userId: 'user-001', sessionId: 'session-001'})
};
fetch('http://localhost:8000/run_sse', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));"data: {\"content\":{\"role\":\"model\",\"parts\":[{\"text\":\"Hello\"}]},\"author\":\"travel_assistant\",\"invocationId\":\"invocation-001\",\"id\":\"event-001\",\"timestamp\":1789603200}\n\n"{
"detail": "<string>"
}{
"detail": "<string>"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>",
"input": "<unknown>",
"ctx": {}
}
]
}默认先创建会话,再提交消息。
每个 SSE 消息以
以上分别展示消息事件与错误事件的格式,不表示每次成功调用都会返回错误。HTTP
streaming 默认为 false,此时仍通过 SSE 发送完整事件;设为 true 时请求模型增量输出
运行会写入会话事件,并可能调用模型、工具与外部资源。重试请求可能再次执行外部操作
data: 开头,后接 JSON,并以空行结束。使用 curl -N 持续读取;事件可能只包含状态或制品变更,不一定包含文本,partial: true 表示增量内容
data: {"content":{"role":"model","parts":[{"text":"Hello"}]},"partial":false,"author":"travel_assistant","invocationId":"invocation-001","id":"event-001","timestamp":1789603200}
data: {"error":"Example execution error"}
200 仅表示流已开始;客户端还需检查流中的 error,并读取到连接结束。交互式请求面板不保证逐事件展示请求体
application/json
用户 ID
会话 ID
应用名称;省略时使用 ADK_DEFAULT_APP_NAME,未配置默认应用则返回 400
本轮输入消息;恢复调用时可省略,具体取决于应用支持的调用方式
Show child attributes
Show child attributes
是否请求模型增量流式输出,默认 false
本次写入的会话状态增量
对应函数调用的事件 ID,用于函数响应相关的流式处理
调用 ID
自定义元数据
响应
请求成功
The response is of type string.
最后修改于 2026年9月19日