feat:删除多余代码

This commit is contained in:
2026-10-01 07:32:02 -07:00
parent 071228c5f8
commit dd2fd8bcde
14 changed files with 25 additions and 833 deletions
-135
View File
@@ -274,138 +274,3 @@ def build_graph(checkpointer=None):
# 模块加载时创建共享图实例,复用该实例的调用也共用其检查点存储
query_app = build_graph()
if __name__ == "__main__":
import argparse
import asyncio
import json
from uuid import uuid4
from langgraph.types import Command
from pydantic import BaseModel
from app.clients.decision import close_decision_engine
from app.observability.tracing import ainvoke_screen, flush_tracing
# 选择场景时只切换用户需求,共用同一份画布,方便比较执行结果
examples = {
"move": "把销售额统计向右移动 50px,其他内容保持不变",
"layout": (
"重新排列现有两个图表,销售额统计放在左侧,销售占比放在右侧,"
"统一尺寸为 600×400,画布改为 1600×900,不新增或删除组件"
),
"add": "保留现有组件,在下方新增一个柱状图,使用物料示例数据,不需要真实数据绑定",
"clarify": "这个图不太对",
}
parser = argparse.ArgumentParser(description="运行大屏 Agent 完整流程示例")
parser.add_argument("--case", choices=examples, default="move", help="选择联调场景")
args = parser.parse_args()
async def main():
# 1. 创建请求,每次运行使用独立会话,避免混入之前的澄清历史
state: QueryState = {
"request": {
"prompt": examples[args.case],
"screen": {
"canvas": {"width": 1920, "height": 1080},
"nodes": [
{
"id": "sales-chart",
"type": "bar-chart",
"name": "销售额统计",
"layout": {"x": 26, "y": 34.8, "width": 400, "height": 260},
"props": {"option": {"title": {"text": "销售额统计"}}},
},
{
"id": "sales-share",
"type": "pie-chart",
"name": "销售占比",
"layout": {
"x": 500,
"y": 34.8,
"width": 400,
"height": 260,
},
"props": {"option": {"title": {"text": "销售占比"}}},
},
],
"dataSource": [],
},
"context": {"selected_node_ids": ["sales-chart"]},
}
}
# 2. 执行图,程序退出时关闭共享连接
thread_id = str(uuid4())
session_id = (
state["request"].get("context", {}).get("conversation_id") or thread_id
)
print(f"场景:{args.case}\n需求:{examples[args.case]}")
if args.case == "clarify":
print("澄清回答示例:把销售额统计向右移动 50px,其他内容保持不变")
try:
final_state = await ainvoke_screen(
query_app, state, thread_id=thread_id, session_id=session_id
)
# 3. 展示真实澄清问题,用同一个 thread_id 恢复流程
while final_state.get("__interrupt__"):
pending = final_state["__interrupt__"][0].value
print(pending["question"])
options = pending.get("options", [])
for index, option in enumerate(options, 1):
marker = "(推荐)" if option["recommended"] else ""
print(
f"{index}. {option['label']}{marker}:{option['description']}"
)
answer = input("输入编号或自由回答(/cancel 取消):")
reply = {"cancel": True} if answer == "/cancel" else {"answer": answer}
if answer.isdigit() and 1 <= int(answer) <= len(options):
reply = {"option_id": options[int(answer) - 1]["id"]}
notes = input("补充说明(可留空):").strip()
if notes:
reply["answer"] = notes
final_state = await ainvoke_screen(
query_app,
Command(resume=reply),
thread_id=thread_id,
session_id=session_id,
)
finally:
await close_decision_engine()
flush_tracing()
# 4. 聚焦最终结果,校验失败时 simulated_screen 应为 None
result = {
"status": final_state.get("status"),
"intent": final_state.get("intent"),
# 保留需求与规划,方便定位模型输出和执行能力之间的不一致
"requirement": final_state.get("requirement"),
"screen_plan": final_state.get("screen_plan"),
"validation_passed": final_state.get("validation_passed"),
"retry_count": final_state.get("retry_count", 0),
"failure_reason": final_state.get("failure_reason"),
"validation_errors": final_state.get("validation_errors", []),
"actions": final_state.get("actions", []),
"simulated_screen": final_state.get("simulated_screen"),
"answer": final_state.get("answer"),
}
print(
json.dumps(
result,
ensure_ascii=False,
indent=2,
default=lambda value: (
value.model_dump(mode="json")
if isinstance(value, BaseModel)
else str(value)
),
)
)
# 原始坐标单独展示,确认后端试执行没有修改请求中的画布
original = state["request"]["screen"]["nodes"][0]["layout"]
print(f"原始销售额坐标:{original['x']},{original['y']}")
asyncio.run(main())