Skip to content

Commit 7233e28

Browse files
Cyning12CyningMMcursoragent
authored
feat(chat): 推荐问法 API + Agent 软超时默认 45s (#114)
* 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> * fix(tech-graph): manifest 登记 GET /api/py/chat/suggested-questions 对齐 api/index.py chat_suggested_questions,修复 manifest_check CI。 Co-authored-by: Cursor <cursoragent@cursor.com> * fix(tech-graph): drift_check 与 graph.json 同步 suggested-questions - 00_main.md / 00_main.ai.md 登记 GET /api/py/chat/suggested-questions - export graph.json 节点 SQ Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: cyning <cyning12@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f415371 commit 7233e28

7 files changed

Lines changed: 77 additions & 2 deletions

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+

docs/_tech_graph/00_main.ai.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ flowchart TD
4343
E --"GET /api/py/chat/history"--> H1[[Chat History]]
4444
// → api/index.py chat_history
4545
46+
E --"GET /api/py/chat/suggested-questions"--> SQ[[Suggested Questions]]
47+
// → api/index.py chat_suggested_questions
48+
4649
E --"GET /api/py/chatbi/access/verify"--> CV[[ChatBI Access Verify]]
4750
// → api/index.py chatbi_access_verify
4851
@@ -101,12 +104,17 @@ flowchart TD
101104
- `POST /api/py/chain/chat``chain_chat_route` // → `api/index.py::chain_chat_route`
102105
- `POST /api/py/chat``chat` // → `api/index.py::chat`
103106
- `GET /api/py/chat/history``chat_history` // → `api/index.py::chat_history`
107+
- `GET /api/py/chat/suggested-questions``chat_suggested_questions` // → `api/index.py::chat_suggested_questions`
104108
- `GET /api/py/chatbi/access/verify``chatbi_access_verify` // → `api/index.py::chatbi_access_verify`
105109
- `POST /api/py/code/query``code_query` // → `api/index.py::code_query`
106110
- `POST /api/py/code/search``code_search` // → `api/index.py::code_search`
107111
- `GET /api/py/health``health` // → `api/index.py::health`
112+
- `GET /api/py/live``live` // → `api/index.py::live`
113+
- `GET /api/py/ready``ready` // → `api/index.py::ready`
108114
- `POST /api/py/text2sql/chat``text2sql_chat` // → `api/index.py::text2sql_chat`
109115
- `POST /api/py/unified/chat``unified_chat_route` // → `api/index.py::unified_chat_route`
116+
- `POST /api/py/unified/chat/graph``unified_chat_graph_route` // → `api/index.py::unified_chat_graph_route`
117+
- `POST /api/py/unified/chat/graph/stream``unified_chat_graph_stream_route` // → `api/index.py::unified_chat_graph_stream_route`
110118
- `POST /api/py/unified/chat/stream``unified_chat_stream_route` // → `api/index.py::unified_chat_stream_route`
111119

112120
#### Anchors(from manifest)

docs/_tech_graph/00_main.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ flowchart TD
1010
E -->|Unified Stream| U2[SSE 流式<br/>/api/py/unified/chat/stream<br/>api/index.py#L576 unified_chat_stream_route<br/>api/unified_chat.py::handle_unified_chat_stream]
1111
E -->|遗留 Chat| C1[RAG Chat<br/>/api/py/chat<br/>api/index.py#L591 chat]
1212
E -->|History| H1[Chat History<br/>/api/py/chat/history<br/>api/index.py chat_history]
13+
E -->|Suggested| SQ[Suggested Questions<br/>/api/py/chat/suggested-questions<br/>api/index.py chat_suggested_questions]
1314
E -->|ChatBI verify| CV[Access Verify<br/>GET /api/py/chatbi/access/verify<br/>api/index.py chatbi_access_verify]
1415
E -->|Health| HL[Health<br/>/api/py/health<br/>api/index.py health]
1516
E -->|Chain Chat| CH[Chain Timeline<br/>/api/py/chain/chat<br/>api/index.py#L546 chain_chat_route<br/>api/chain_chat.py::handle_chain_chat]

docs/_tech_graph/_manifest.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@
5252
"symbol": "chat_history"
5353
}
5454
},
55+
{
56+
"method": "GET",
57+
"path": "/api/py/chat/suggested-questions",
58+
"handler": "chat_suggested_questions",
59+
"anchor": {
60+
"path": "api/index.py",
61+
"symbol": "chat_suggested_questions"
62+
}
63+
},
5564
{
5665
"method": "POST",
5766
"path": "/api/py/chain/chat",

docs/_tech_graph/graph.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@
160160
"to": "OBS_DOC",
161161
"type": "depends_on"
162162
},
163+
{
164+
"anchors": [],
165+
"from": "E",
166+
"graph_id": "00_main",
167+
"label": "GET /api/py/chat/suggested-questions",
168+
"mark": "->",
169+
"sync": true,
170+
"to": "SQ",
171+
"type": "depends_on"
172+
},
163173
{
164174
"anchors": [],
165175
"from": "E",
@@ -2199,7 +2209,7 @@
21992209
}
22002210
],
22012211
"freeze_id": "TECH_GRAPH_S2_FREEZE_20260519_V2_3",
2202-
"generated_at": "2026-05-18T07:07:16Z",
2212+
"generated_at": "2026-06-04T08:24:47Z",
22032213
"graphs": [
22042214
{
22052215
"id": "00_main",
@@ -2788,6 +2798,11 @@
27882798
"id": "SPEC",
27892799
"label": ">docs/text2sql/v1/sql/supabase_init.sql"
27902800
},
2801+
{
2802+
"graph_id": "00_main",
2803+
"id": "SQ",
2804+
"label": "Suggested Questions"
2805+
},
27912806
{
27922807
"graph_id": "14_runtime_observability",
27932808
"id": "SQLR",
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)