backend-api-test-doc-routing.md 9.4 KB

鎺ュ彛娴嬭瘯鏂囨。 鈥?routing


1. 妯″潡姒傝

瀛楁 鍊?
妯″潡鍚嶇О routing
妯″潡璇存槑 璺敱涓庢剰鍥捐瘑鍒?鈥?娑堟伅璺敱(mention/inheritance/default) + 鎰忓浘璇嗗埆 + Agent浜ゆ帴 + 鏂囦欢涓婁紶
璺敱鍓嶇紑 /api/v1
鏁版嵁搴撹〃 ai_agents
澶栭儴渚濊禆 LLMClient锛堟剰鍥捐瘑鍒級銆丼essionStore锛堜細璇濈姸鎬侊級銆丗ileParser銆丱SSClient

2. 鎺ュ彛鍒楄〃

搴忓彿 鏂规硶 璺緞 璇存槑
1 POST /api/v1/chat/completions 璺敱鍐崇瓥鎺ュ彛
2 POST /api/v1/files/upload 鏂囦欢涓婁紶涓庢枃鏈彁鍙?

3. 鎺ュ彛璇︾粏璇存槑

3.1 璺敱鍐崇瓥鎺ュ彛

鍩烘湰淇℃伅

瀛楁 鍊?
鏂规硶 POST
璺緞 /api/v1/chat/completions
璇存槑 鏍规嵁mention/缁ф壙/榛樿绛栫暐璺敱娑堟伅锛屾墽琛屾剰鍥捐瘑鍒拰Agent浜ゆ帴
Content-Type application/json

璇锋眰鍙傛暟

鍙傛暟鍚? 浣嶇疆 绫诲瀷 蹇呭~ 璇存槑
session_id body string 鏄? 浼氳瘽ID锛屾渶闀?4
user_id body string 鏄? 鐢ㄦ埛ID锛屾渶闀?4
channel body string 鏄? 娑堟伅娓犻亾锛屾渶闀?4
query body string 鏄? 鐢ㄦ埛闂锛?~5000瀛楃
mentioned_agent_code body string 鍚? @鎻愬強鐨凙gent缂栫爜
file_url body string 鍚? 鏂囦欢URL

鍝嶅簲鍙傛暟

瀛楁璺緞 绫诲瀷 璇存槑
session_id string 浼氳瘽ID
routing object 璺敱淇℃伅
routing.agent_id integer Agent ID
routing.agent_code string Agent缂栫爜
routing.agent_name string Agent鍚嶇О
routing.routing_reason string 璺敱鍘熷洜锛歮ention/inheritance/default
intent object 鎰忓浘淇℃伅锛坢ention鏃朵负null锛?
intent.intent string 鎰忓浘鍚?
intent.confidence float 缃俊搴?
handoff object 浜ゆ帴淇℃伅锛堝悓Agent鎴栭娆″璇濇椂涓簄ull锛?
handoff.from_agent_id integer 婧怉gent ID
handoff.to_agent_id integer 鐩爣Agent ID
handoff.to_agent_name string 鐩爣Agent鍚嶇О
handoff.handoff_message string 浜ゆ帴娑堟伅
response_content string 鍥炲鍐呭
created_at string 鍒涘缓鏃堕棿

*閿欒鐮?

HTTP 鐘舵€佺爜 瑙﹀彂鏉′欢
400 mentioned_agent涓嶅瓨鍦?/ 绠″Agent鏈厤缃?

3.2 鏂囦欢涓婁紶涓庢枃鏈彁鍙?

鍩烘湰淇℃伅

瀛楁 鍊?
鏂规硶 POST
璺緞 /api/v1/files/upload
Content-Type multipart/form-data

璇锋眰鍙傛暟

鍙傛暟鍚? 浣嶇疆 绫诲瀷 蹇呭~ 璇存槑
session_id form string 鏄? 鍏宠仈浼氳瘽ID
file form file 鏄? 涓婁紶鏂囦欢

鍝嶅簲鍙傛暟

瀛楁璺緞 绫诲瀷 璇存槑
file_url string 鏂囦欢URL
file_name string 鏂囦欢鍚?
file_size integer 鏂囦欢澶у皬
extracted_text string 鎻愬彇鐨勬枃鏈紙鍥剧墖涓簄ull锛?
session_id string 浼氳瘽ID

*閿欒鐮?

HTTP 鐘舵€佺爜 瑙﹀彂鏉′欢
400 涓嶆敮鎸佺殑鏂囦欢鏍煎紡 / 鏂囦欢杩囧ぇ

4. 娴嬭瘯鍦烘櫙

4.1 璺敱鍐崇瓥

搴忓彿 鍦烘櫙鍚嶇О 鍒嗙被 棰勬湡缁撴灉
1 @mention璺敱鍒版寚瀹欰gent 姝e父 agent_code="metric-agent", reason="mention"
2 缁ф壙璺敱鍒板綋鍓岮gent 姝e父 agent_code="metric-agent", reason="inheritance"
3 榛樿璺敱鍒扮瀹禔gent 姝e父 agent_code="steward", reason="default"
4 @mention瑕嗙洊缁ф壙 姝e父 reason="mention", agent_code="detail-agent"

4.2 鎰忓浘璇嗗埆

搴忓彿 鍦烘櫙鍚嶇О 鍒嗙被 棰勬湡缁撴灉
1 鏌ヨ绫绘剰鍥? 姝e父 intent="query-metric", confidence>0
2 鏈煡鎰忓浘褰掍负general-qa 姝e父 intent="general-qa"
3 @mention璺宠繃鎰忓浘璇嗗埆 姝e父 intent=None

4.3 Agent浜ゆ帴

搴忓彿 鍦烘櫙鍚嶇О 鍒嗙被 棰勬湡缁撴灉
1 Agent鍒囨崲鐢熸垚浜ゆ帴 姝e父 handoff闈瀗ull, 鍚玣rom/to/handoff_message
2 鍚孉gent鏃犱氦鎺? 姝e父 handoff=None
3 棣栨瀵硅瘽鏃犱氦鎺? 姝e父 handoff=None

4.4 鏂囦欢涓婁紶

搴忓彿 鍦烘櫙鍚嶇О 鍒嗙被 棰勬湡缁撴灉
1 PDF涓婁紶鎻愬彇鏂囨湰 姝e父 extracted_text闈炵┖
2 涓嶆敮鎸佺殑鏍煎紡 寮傚父 ValueError "涓嶆敮鎸佺殑鏂囦欢鏍煎紡"
3 鏂囦欢杩囧ぇ 寮傚父 ValueError "鏂囦欢澶у皬瓒呰繃闄愬埗"
4 鍥剧墖涓婁紶鏃犳枃鏈彁鍙? 姝e父 extracted_text=None

4.5 闆嗘垚涓庡紓甯?

搴忓彿 鍦烘櫙鍚嶇О 鍒嗙被 棰勬湡缁撴灉
1 榛樿鈫抦ention瀹屾暣娴佺▼ 闆嗘垚 鍏坉efault鍚巑ention, 鐢熸垚handoff
2 mentioned Agent涓嶅瓨鍦? 寮傚父 ValueError "Agent涓嶅瓨鍦?
3 绠″Agent鏈厤缃? 寮傚父 ValueError "绠″Agent"

5. 瀵瑰簲娴嬭瘯浠g爜

娴嬭瘯鏂囦欢锛歚backend/tests/test_routing_api.py`

娴嬭瘯绫? 娴嬭瘯鏂规硶 瀵瑰簲鍦烘櫙
TestRoutingDecision test_mention_routes_to_mentioned_agent 4.1-1
TestRoutingDecision test_inheritance_routes_to_current_agent 4.1-2
TestRoutingDecision test_default_routes_to_steward 4.1-3
TestRoutingDecision test_mention_overrides_inheritance 4.1-4
TestIntentRecognition test_intent_recognized_for_query 4.2-1
TestIntentRecognition test_intent_general_for_unknown_query 4.2-2
TestIntentRecognition test_mention_skips_intent_recognition 4.2-3
TestHandoff test_handoff_generated_on_agent_switch 4.3-1
TestHandoff test_no_handoff_when_same_agent 4.3-2
TestHandoff test_no_handoff_on_default_first_message 4.3-3
TestFileUpload test_upload_and_extract_text 4.4-1
TestFileUpload test_unsupported_format_returns_error 4.4-2
TestFileUpload test_file_too_large_returns_error 4.4-3
TestFileUpload test_upload_without_extraction 4.4-4
TestRoutingServiceIntegration test_full_flow_default_then_mention 4.5-1
TestRoutingServiceIntegration test_mentioned_agent_not_found 4.5-2
TestRoutingServiceIntegration test_steward_agent_not_found 4.5-3

附录A 字段说明

A.1 通用响应字段

字段 类型 说明
code integer 业务响应码。200 表示成功,400 表示请求参数错误,401 表示未授权,403 表示无权限,404 表示资源不存在,409 表示资源冲突,500 表示服务器内部错误。
message string 响应说明。成功时固定为 success,失败时为具体错误原因。
data object/null 实际业务数据。成功时返回对象或分页结构,失败时固定为 null。

A.2 分页字段

如果接口是列表查询,则 data 一般使用分页结构:

字段 类型 说明
total integer 总记录数。
page integer 当前页码,默认从 1 开始。
page_size integer 每页数量,默认 20,最大 100。
list array 当前页数据列表。

A.3 常见时间字段

字段类型 格式 说明
created_at ISO 8601 string 创建时间。
updated_at ISO 8601 string 更新时间。
deleted_at ISO 8601 string 删除时间,仅删除类接口出现。
archived_at ISO 8601 string 归档时间,仅归档类接口出现。
triggered_at ISO 8601 string 触发时间,仅任务或同步类接口出现。

A.4 常见布尔与状态字段

字段 类型 说明
success boolean 是否成功,通常用于删除、归档、状态切换等动作接口。
status string 业务状态字段,具体取值以各接口正文说明为准,例如 enable、disable、active、archived、failed。

A.5 ID 与编码字段

字段类型 说明
*_id 业务主键或外部主键。不同模块含义不同,需结合接口正文说明理解。
*_code 业务编码字段,通常用于唯一标识某类对象,稳定性高于展示名称。

A.6 说明约定

  • 具体接口字段的业务含义,以各文档正文中的“请求参数”“响应参数”“示例响应”为准。
  • 本附录用于统一解释所有文档里重复出现的通用字段,避免重复写相同说明。
  • 如果某个接口没有分页能力,则不会返回 total / page / page_size / list。