coze-dev / coze-dev/coze-studio

COZE本地化API调用智能体,工作流调用失败

Open
#2,363 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
21.6k
Forks
3.1k
PR merge metrics
No merged PRs in 30d

Description

web界面是可以正常调用工作流的。

Image

调用代码:
`import requests
import json

url = "http://0.0.0.0:8888/v3/chat"

headers = {
"Authorization": "Bearer pat_9676efd3641fe28xxxxxxxxxxxxxxxxxxxxx",
"Content-Type": "application/json"
}

data = {
"bot_id": "7563552430344896512",
"user_id": "676767655",
"stream": False,
"auto_save_history": True,
"additional_messages": [
{
"role": "user",
"content": "深圳的天气咋样",
"content_type": "text"
}
]
}

response = requests.post(url, headers=headers, json=data, stream=False)

def fix_mojibake(text: str) -> str:
try:
repaired = text.encode('latin-1').decode('utf-8')
if any('\u4e00' <= ch <= '\u9fff' for ch in repaired):
return repaired
except Exception:
pass
return text

print(f"状态码: {response.status_code}")

content_type = response.headers.get("Content-Type", "")
if response.status_code == 200 and "text/event-stream" in content_type:
print("检测到流式 SSE 响应,开始逐行处理事件(处理编码修复):")
story_content = []
event_type = ""
for raw_line in response.iter_lines(decode_unicode=False):
if not raw_line:
continue
try:
line = raw_line.decode('utf-8').strip()
except UnicodeDecodeError:
line = raw_line.decode('latin-1').strip()
line = fix_mojibake(line)

if line.startswith("event:"):
event_type = line[len("event:"):].strip()
print(f"事件: {event_type}")
elif line.startswith("data:"):
payload = line[len("data:"):].strip()
try:
parsed = json.loads(payload)
# 只累加 delta 事件内容
if event_type == "conversation.message.delta" and parsed.get("type") == "answer" and parsed.get("role") == "assistant":
if "content" in parsed:
story_content.append(parsed["content"])
# completed事件只展示,不累加
elif event_type == "conversation.message.completed" and parsed.get("type") == "answer" and "content" in parsed:
print("\n【完整回复】\n" + parsed["content"] + "\n")
else:
print(json.dumps(parsed, indent=2, ensure_ascii=False))
except json.JSONDecodeError:
print(f"数据(非JSON): {fix_mojibake(payload)}")
else:
print(fix_mojibake(line))
# 最后只输出 delta 拼接内容
if story_content:
print("\n【故事内容(自动拼接)】\n" + "".join(story_content) + "\n")
print("SSE 流处理完成")
else:
text = response.text
text = fix_mojibake(text)
print(f"响应内容: {text}")
if response.status_code == 200:
try:
result = response.json()
print(json.dumps(result, indent=2, ensure_ascii=False))
except ValueError:
print("无法解析为 JSON,已输出原始(或修复后)响应内容。")
else:
print(f"请求失败,状态码: {response.status_code}")`

返回结果:

但是通过API调用时,出现
状态码: 200
检测到流式 SSE 响应,开始逐行处理事件(处理编码修复):
事件: conversation.chat.created
{
"id": "7563622151173963776",
"conversation_id": "7563622151132020736",
"bot_id": "7563552430344896512",
"created_at": 1761043013,
"completed_at": 0,
"failed_at": 0,
"status": "in_progress",
"section_id": "7563622151132037120"
}
事件: conversation.chat.in_progress
{
"id": "7563622151173963776",
"conversation_id": "7563622151132020736",
"bot_id": "7563552430344896512",
"created_at": 1761043013,
"completed_at": 0,
"failed_at": 0,
"status": "in_progress",
"section_id": "7563622151132037120"
}
事件: conversation.message.delta
事件: conversation.message.completed

【完整回复】
我无法直接获取深圳当前的天气信息。你可以通过以下几种方式了解深圳的天气情况:
1. **天气预报网站**:访问专业的天气预报网站,如中国天气网、天气在线等,在搜索栏中输入“深圳”,即可查看当地的天气详情。
2. **天气预报应用**:在手机应用商店中下载安装天气预报类应用,如墨迹天气、彩云天气、天气通等,打开应用后定位到深圳,就能获取实时天气及未来的天气预报。
3. **电视和广播**:收看或收听当地的电视台、广播电台的天气预报节目,以了解深圳地区的天气状况。

事件: conversation.message.completed
{
"id": "7563622178206253056",
"conversation_id": "7563622151132020736",
"bot_id": "7563552430344896512",
"role": "assistant",
"type": "follow_up",
"content": "墨迹天气的功能有哪些",
"content_type": "text",
"meta_data": {
"bot_state": "{\"bot_id\":\"7563552430344896512\",\"agent_name\":\"\",\"agent_id\":\"7563552430344896512\",\"awaiting\":\"7563552430344896512\"}"
},
"chat_id": "7563622151173963776",
"created_at": 1761043020,
"reasoning_content": ""
}
事件: conversation.message.completed
{
"id": "7563622178244001792",
"conversation_id": "7563622151132020736",
"bot_id": "7563552430344896512",
"role": "assistant",
"type": "follow_up",
"content": "中国天气网的网址是什么",
"content_type": "text",
"meta_data": {
"bot_state": "{\"bot_id\":\"7563552430344896512\",\"agent_name\":\"\",\"agent_id\":\"7563552430344896512\",\"awaiting\":\"7563552430344896512\"}"
},
"chat_id": "7563622151173963776",
"created_at": 1761043020,
"reasoning_content": ""
}
事件: conversation.message.completed
{
"id": "7563622178277556224",
"conversation_id": "7563622151132020736",
"bot_id": "7563552430344896512",
"role": "assistant",
"type": "follow_up",
"content": "深圳未来一周天气趋势如何",
"content_type": "text",
"meta_data": {
"bot_state": "{\"bot_id\":\"7563552430344896512\",\"agent_name\":\"\",\"agent_id\":\"7563552430344896512\",\"awaiting\":\"7563552430344896512\"}"
},
"chat_id": "7563622151173963776",
"created_at": 1761043020,
"reasoning_content": ""
}
事件: conversation.message.completed
{
"id": "7563622178315304960",
"conversation_id": "7563622151132020736",
"bot_id": "7563552430344896512",
"role": "assistant",
"type": "verbose",
"content": "{\"msg_type\":\"generate_answer_finish\",\"data\":\"{\\\"finish_reason\\\":0,\\\"fin_data\\\":\\\"\\\"}\",\"from_unit\":\"\"}",
"content_type": "text",
"meta_data": {
"bot_state": "{\"bot_id\":\"7563552430344896512\",\"agent_name\":\"\",\"agent_id\":\"7563552430344896512\",\"awaiting\":\"7563552430344896512\"}"
},
"chat_id": "7563622151173963776",
"created_at": 1761043020,
"reasoning_content": ""
}
事件: conversation.chat.completed
{
"id": "7563622151173963776",
"conversation_id": "7563622151132020736",
"bot_id": "7563552430344896512",
"created_at": 1761043013,
"completed_at": 1761043020,
"failed_at": 0,
"status": "completed",
"section_id": "7563622151132037120"
}
事件: conversation.stream.done
数据(非JSON):

【故事内容(自动拼接)】
我无法直接获取深圳当前的天气信息。你可以通过以下几种方式了解深圳的天气情况:
1. **天气预报网站**:访问专业的天气预报网站,如中国天气网、天气在线等,在搜索栏中输入“深圳”,即可查看当地的天气详情。
2. **天气预报应用**:在手机应用商店中下载安装天气预报类应用,如墨迹天气、彩云天气、天气通等,打开应用后定位到深圳,就能获取实时天气及未来的天气预报。
3. **电视和广播**:收看或收听当地的电视台、广播电台的天气预报节目,以了解深圳地区的天气状况。

SSE 流处理完成

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported Python request to the /v3/chat endpoint and compare its events with a successful web-interface workflow call. Trace how the API handles the supplied bot_id and workflow execution, then verify that the API response reflects the intended workflow result rather than only the reported fallback answer.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.