feat: upgrade investigation and presentation runtime
This commit is contained in:
@@ -51,6 +51,7 @@ const taskExecutionPayloadSchema = z.object({
|
||||
task_id: z.string().uuid(),
|
||||
run_id: z.string().uuid(),
|
||||
execution_request_id: z.string().uuid(),
|
||||
agent_instance_id: z.string().trim().min(1).max(128),
|
||||
workflow: z.string().trim().min(1).max(120).optional(),
|
||||
});
|
||||
|
||||
@@ -64,6 +65,13 @@ const taskExecutionDebugPayloadSchema = z.object({
|
||||
session_id: z.string().trim().min(1).max(128),
|
||||
}).strict();
|
||||
|
||||
export const buildTaskExecutionPrompt = (workflow?: string) =>
|
||||
`执行宿主绑定的工况任务${workflow ? `:${workflow}` : ""}。` +
|
||||
`第一步分别调用 mcp_tjwater_get_task_context 读取默认摘要和 section="skill";` +
|
||||
`以返回的 skill.name、skill.version 和 instructions 为本轮业务流程,不沿用记忆中的旧版本。` +
|
||||
`若 Skill 返回不可用或读取失败,明确报告执行异常,不得声称已按某个版本执行。` +
|
||||
`随后按后台调查指令推进当前目标,保存证据、进度和报告;收尾遵循后台调查指令的停止条件。`;
|
||||
|
||||
const sessionListQuerySchema = z.object({
|
||||
purpose: z.enum(["ordinary_chat", "task_execution", "task_collaboration"]).optional(),
|
||||
task_id: z.string().uuid().optional(),
|
||||
@@ -187,7 +195,7 @@ export const registerChatSessionRoutes = (
|
||||
conversation: record.sessionId,
|
||||
model,
|
||||
stream: true,
|
||||
input: `执行工况任务${workflow ? `:${workflow}` : ""}。先读取后端任务上下文,自主查询并保存证据和调查报告;每次开始真实步骤或改变路线时发布完整 task progress,可用 Mermaid 调查图向人解释方向、分支和依据,图及 todo 均不约束执行。实际查询资料可通过 task presentation 发布,recorded 仅表示已记录,不等待浏览器展示。数据权限由系统配置,关键数据不足时发布最终报告并正常结束本轮,人工审核仅针对具体工单等业务动作。`,
|
||||
input: buildTaskExecutionPrompt(workflow),
|
||||
}),
|
||||
}).then(async (response) => {
|
||||
const reader = response.body?.getReader();
|
||||
@@ -241,6 +249,7 @@ export const registerChatSessionRoutes = (
|
||||
if (
|
||||
["claimed", "running"].includes(activeRun.status)
|
||||
&& activeRun.agent_session_id === record.sessionId
|
||||
&& activeRun.agent_instance_id === config.AGENT_INSTANCE_ID
|
||||
) {
|
||||
return "running";
|
||||
}
|
||||
@@ -288,7 +297,6 @@ export const registerChatSessionRoutes = (
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const authContext = getLocalAgentContext(req);
|
||||
const projectId = authContext.projectId;
|
||||
const userId = authContext.userId;
|
||||
@@ -604,6 +612,10 @@ export const registerChatSessionRoutes = (
|
||||
res.status(400).json({ message: "invalid request payload", detail: parsed.error.flatten() });
|
||||
return;
|
||||
}
|
||||
if (parsed.data.agent_instance_id !== config.AGENT_INSTANCE_ID) {
|
||||
res.status(409).json({ message: "task execution targeted a different Agent instance" });
|
||||
return;
|
||||
}
|
||||
const credential = getTrustedProductCredential(req);
|
||||
if (!credential) {
|
||||
res.status(401).json({ message: "task execution requires product credentials" });
|
||||
@@ -636,6 +648,7 @@ export const registerChatSessionRoutes = (
|
||||
created: false,
|
||||
status: "running",
|
||||
model: existing.modelId,
|
||||
agent_instance_id: config.AGENT_INSTANCE_ID,
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -661,6 +674,7 @@ export const registerChatSessionRoutes = (
|
||||
created: false,
|
||||
status: "running",
|
||||
model: taskModel,
|
||||
agent_instance_id: config.AGENT_INSTANCE_ID,
|
||||
});
|
||||
startTaskExecution(existing, credential, taskModel, parsed.data.workflow);
|
||||
return;
|
||||
@@ -706,6 +720,7 @@ export const registerChatSessionRoutes = (
|
||||
created: true,
|
||||
status: "running",
|
||||
model: taskModel,
|
||||
agent_instance_id: config.AGENT_INSTANCE_ID,
|
||||
});
|
||||
startTaskExecution(record, credential, taskModel, parsed.data.workflow);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user