Skip to content

Commit cebc8bd

Browse files
CyningMMcursoragent
andcommitted
feat(chat): 推荐问法 API + Agent 软超时默认 45s
- GET /api/py/chat/suggested-questions 供 Ink BFF 转发 - AGENT_MAX_LATENCY_MS 未设时默认 45000,降低 Intent 慢于 15s 即 V1 降级的误触发 Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f415371 commit cebc8bd

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

api/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __init__(
8585
self._tools = {t.name: t for t in tools}
8686
self._memory = memory
8787
self._max_steps = max(1, int(os.getenv("AGENT_MAX_STEPS", "5")))
88-
self._max_latency_ms = max(1000, int(os.getenv("AGENT_MAX_LATENCY_MS", "15000")))
88+
self._max_latency_ms = max(1000, int(os.getenv("AGENT_MAX_LATENCY_MS", "45000")))
8989
self._min_confidence = float(os.getenv("INTENT_MIN_CONFIDENCE", "0.6"))
9090

9191
def _select_tool(self, tool_name: ToolName) -> Tool:

api/index.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,3 +1142,20 @@ async def py_admin_ingest(
11421142
status = 400
11431143
return JSONResponse({"ok": False, "error": msg}, status_code=status)
11441144

1145+
1146+
@app.get("/api/py/chat/suggested-questions")
1147+
def chat_suggested_questions() -> JSONResponse:
1148+
"""返回推荐问法列表,供前端展示(不再本地写死)。"""
1149+
return JSONResponse(
1150+
{
1151+
"ok": True,
1152+
"questions": [
1153+
"《AI 编程可闭环协作》卷三讲什么?Harness 和签收是什么?",
1154+
"Tech Graph 是什么",
1155+
"冷/温/热 和 架构三层 区别?",
1156+
"简单介绍下刘新宁",
1157+
"AI Ink Brain 的架构是怎样的",
1158+
],
1159+
}
1160+
)
1161+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from __future__ import annotations
2+
3+
import importlib
4+
5+
import pytest
6+
from fastapi.testclient import TestClient
7+
8+
9+
def test_chat_suggested_questions_returns_list(monkeypatch: pytest.MonkeyPatch) -> None:
10+
monkeypatch.setenv("SYNC_ADMIN_SECRET", "secret-token-1234567890")
11+
monkeypatch.setenv("CHATBI_USE_AGENT", "false")
12+
13+
index = importlib.import_module("api.index")
14+
importlib.reload(index)
15+
16+
client = TestClient(index.app)
17+
res = client.get("/api/py/chat/suggested-questions")
18+
19+
assert res.status_code == 200
20+
data = res.json()
21+
assert data["ok"] is True
22+
questions = data["questions"]
23+
assert isinstance(questions, list)
24+
assert len(questions) >= 1
25+
assert all(isinstance(q, str) and q.strip() for q in questions)

0 commit comments

Comments
 (0)