Skip to content

Conversation

@LukeJiaoR
Copy link

https://chatgpt.com/s/t_6964773209c08191999bd41fea2ba955

Features

  • Feature 1
  • Feature 2

Feature Docs

Influence

Result

Other

1. 禁止在入口文件中直接实例化或运行任何 Agent
2. 如果存在 run_task / run_agent / main_execute 之类逻辑,请注释或移除
3. 入口文件只保留启动服务或占位逻辑
4. 不引入新功能,不改变任何 Agent 行为
5. 代码必须仍可 import,不要求可执行

请只修改入口相关文件,不要改 agent、tool、memory 代码。
要求:
1. Task 必须包含:
   - id(字符串)
   - status(CREATED / RUNNING / DONE / FAILED / INTERRUPTED)
   - interrupt_flag(bool)
   - event_queue(线程安全或 asyncio 兼容)
2. 提供方法:
   - emit(type: str, data: Any)
   - interrupt()
   - is_interrupted()
3. 不依赖 FastAPI / WebSocket
4. 不修改任何已有代码
5. Task 设计要尽量通用,后续可被 agent / tool 使用

只新增文件,不改已有文件。
要求:
1. 所有 Agent 的入口方法签名改为:
   run(task: Task, input: Any)
2. Agent 内部不得直接 print / logging 作为输出
3. 所有“对外可见”的信息必须通过:
   task.emit(event_type, data)
4. 在每个主要执行步骤前,检查:
   if task.is_interrupted(): raise TaskInterrupted
5. 不改变 Agent 的决策逻辑,不优化 prompt,不新增能力

请只修改 Agent 相关文件。
1. Planner 的输出必须是结构化 plan(如 list[dict] 或 dataclass)
2. 生成 plan 的过程中,通过 task.emit(plan.step, step)
3. Planner 不执行任何 tool
4. Planner 完成时 emit(plan.done)

不要修改 Executor,不引入新模型调用。
1. Executor 只消费 Planner 生成的 plan
2. 每次执行 step 前:
   task.emit(execute.step.start, step)
3. 调用 tool 前:
   task.emit(tool.call, tool_name, args)
4. tool 执行完成后:
   task.emit(tool.result, result)
5. 支持 interrupt(中断后立刻停止)

不要修改 Planner 和 Tool 实现。
实现 ToolRunner 类,统一所有 tool 执行入口
提供 run(task, tool_name, args) -> ToolResult
支持:
timeout
捕获 stdout / stderr
在执行期间检查 task.is_interrupted()
不直接调用 os.system
不修改具体 tool 的业务逻辑
只新增 runner,不重构 tool。
1. 禁止直接 subprocess.run / os.system
2. 统一通过 ToolRunner 调用
3. 返回结构化 ToolResult(stdout / stderr / exit_code)
4. 支持 interrupt

不修改 shell 的功能行为。
实现 ContextEngine.build(task, agent_role, step_type)
Context 分为:
Hard facts(用户目标、当前 plan)
Recent events(最近 tool 输出)
Process summary(字符串)
支持 context token budget(简单字符裁剪即可)
不调用向量数据
1. 所有 Agent 在调用 LLM 前,必须通过 ContextEngine.build 获取上下文
2. Agent 不得自行拼接历史记录
3. 不修改 prompt 内容本身,只替换 context 来源

只改 prompt 构建相关代码。
1. 使用 FastAPI
2. 提供:
   - POST /tasks(创建任务)
   - GET /tasks/{id}(查询状态)
   - POST /tasks/{id}/interrupt
3. API 调用 TaskRegistry
4. Agent 在 background task 中运行
5. 不引入 WebSocket

只新增 server/api.py。
1. WebSocket endpoint: /tasks/{id}/stream
2. 从 task.event_queue 读取事件
3. 将事件以 JSON 形式推送给客户端
4. 支持客户端发送 interrupt 指令
5. 不包含业务逻辑,只做事件转发

不要修改 API 层。
1. TaskInterrupted → status = INTERRUPTED
2. 未捕获异常 → status = FAILED
3. 正常完成 → status = DONE
4. 所有状态变化 emit task.status 事件

不要改变业务逻辑,只补状态收敛。
使用 SQLAlchemy 定义 Task 模型,用于 PostgreSQL。
Task 字段:
task_id (UUID, 主键)
status (字符串)
input (JSON)
result (JSON, 可为空)
created_at (时间戳)
updated_at (时间戳)
将原来的内存 TaskRegistry 改成 DB 操作:
get_task(task_id)
create_task(...)
update_task(task)
ORM 模型放在 server/models.py。
禁止修改业务逻辑或 API 层。
保持与现有 /tasks API 接口兼容。
使用 Celery 作为异步任务执行框架。
创建 server/celery_app.py,初始化 Celery:
broker 使用 Redis (redis://redis:6379/0)
backend 使用 PostgreSQL 或 Redis
将 Task 执行逻辑包装成 Celery task:
接收 task_id,执行原来逻辑
执行完成后更新数据库 task.status = COMPLETED
将执行结果写入 task.result
FastAPI 的 /tasks POST API:
创建 Task(写 DB)
立即调用 Celery 异步执行
FastAPI 的 /tasks/{task_id} GET API:
直接查询数据库
不改变现有 API 路径。
1. 修改 server/api.py,使 API 查询和状态返回读取 PostgreSQL。
2. POST /tasks:
   - 写入 DB
   - 调用 Celery task 异步执行
   - 返回 task_id 和 status=CREATED
3. GET /tasks/{task_id}:
   - 查询 DB 返回 status + result
4. POST /tasks/{task_id}/interrupt:
   - 标记 DB task.status=INTERRUPTED
   - 可发送 Celery revoke 命令取消任务
5. 保持 FastAPI 路由不变
6. 不修改业务逻辑
1. 在项目根创建 Dockerfile,用于 FastAPI Web:
   - Python 3.10-slim
   - 安装 requirements.txt
   - CMD uvicorn main:app --host 0.0.0.0 --port 8000
2. 创建 docker-compose.yml:
   - 服务:
     a) web: FastAPI
     b) worker: Celery Worker,依赖 Redis + PostgreSQL
     c) redis: 最新官方镜像
     d) postgres: 最新官方镜像,持久化卷
   - 网络互通
   - 显式暴露端口 8000
3. Web 与 Worker 使用同一代码库
4. 保持 API 与 DB 连接参数一致
5. 不修改业务逻辑
1. 创建 .github/workflows/docker-celery-smoke-test.yml
2. CI 步骤:
   a) checkout 代码
   b) build docker-compose
   c) 启动容器 (web + worker + redis + postgres)
   d) 等待服务启动
   e) 验证 /health 返回 200
   f) 验证 /docs 返回 200
   g) 验证 /tasks POST + GET 返回正确 status
   h) 关闭并清理容器
3. 失败任意步骤 CI 红灯
4. 不修改源代码业务逻辑
5. Docker + Celery + DB 必须和 PR 代码一致
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant