This repository has been archived on 2026-09-13. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
BPOS-MVP/activities/quote-archive/src/manifest.ts
T
ChaiHaoandClaude Opus 5 94f31f267b 调优:并发推进的真根因 + loop 的三处行为修正
E2E 跑 loop 时 A3 一口气发了八张一模一样的「请处理」卡。逐层查下去,四处:

① **并发推进的真根因**:`pg_try_advisory_lock` 是**会话级**的,而我们经连接池取连接 ——
   加锁与解锁多半落在不同连接上,解锁解不掉自己那把;同一连接被复用时又因可重入而直接放行。
   两头都不对,于是同一任务被并发推进(现象:同一步跑两遍、同一张卡发两张、
   同一行草稿写出两条互相打架的版本)。前一轮「共用同一把锁」的修法方向对、器械错。
   改用**进程内按目标互斥**(MVP 单进程,确定且够用),推进器与派发器共用一把;
   多进程部署时再叠事务级 `pg_try_advisory_xact_lock`(随事务释放,不依赖连接归属)。
   实测:同一单从 8 张卡降到 1 张,2 回合后落到等待。

② **非法行动会把回合打死**:AI 提了不合法的生命周期迁移(Available → Disabled),
   `applyAction` 抛出、运行时没落笔、推进器一遍遍重来。引擎拒绝它是对的
   ——「语义忠实:引擎不得私改迁移拓扑」——但不该因此崩掉。
   改为:拒绝 + 留痕 + 把理由喂回下一回合的上下文。AI 提出非法行动是预期内的事。

③ **副作用抢在校验之前**:卡在迁移合法性判定**之前**就发出去了,于是每个被拒的回合
   都白发一张卡 —— 卡收不回,负责人工作台上堆起一摞没人知道怎么答的「请处理」。
   human / tool 两个分支改为**先验迁移再动手**。

④ **裸调用**:模型只回一个「请处理」。按「调用必附上下文,裸调用不得发出」(AM 06)
   把卡面结构写进出参 schema(title / ask / basis / fields 必填),提示里讲明要求,
   归一时用当下局面兜底;卡片装配也修了 —— 结构化 basis 优先,嵌套对象转 JSON,
   不再出现一行 `[object Object]`。
   实测卡面:「请确认 NE555P 历史报价并判定采用策略」+ 三个回填字段。

gates: tsc / eslint / depcruise(336 模块)/ api-report / 429 测试 全绿

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeDBx2PHLavbURXB8LJJ7m
2026-07-27 11:31:41 +08:00

204 lines
7.4 KiB
TypeScript

/**
* 活动包清单 —— 统一报价 A7 · 情报归档。
*
* 业务素材:docs/MVP示例工作流.html §1.7(S1 结果登记 → S2 画像更新 → S3 落地率统计)。
* 「不成交也留资产:情报、客户画像、落地率」—— 写的是**共享域**,跨活动的沉淀事实。
*/
import type { ActivityManifest } from '@contracts';
import { ARCHIVE_SKILLS } from './skills.ts';
import { activityIdSchema } from '@contracts';
import { ARCHIVE_LOGGED, ARCHIVE_RELEASE } from './views/report.ts';
const ACTIVITY_ID = activityIdSchema.parse('quote-archive');
export const manifest: ActivityManifest = {
identity: {
activityId: ACTIVITY_ID,
name: 'A7 · 情报归档',
packageVersion: '0.1.5',
category: '统一报价',
paradigm: 'flow',
sdkVersion: '0.1.0-m5',
checksum: 'dev-checksum-quote-archive',
},
contract: {
activityId: ACTIVITY_ID,
version: '0.1.0',
input: {
data: {
type: 'object',
required: ['customerCode', 'quoteNo'],
properties: {
/** 归档写 (pn, quoted_at) 这一行,两个主键都由调用方给定 */
pn: { type: 'string' },
quotedAt: { type: 'string' },
customerCode: { type: 'string' },
quoteNo: { type: 'string' },
reason: { type: 'string' },
competitorPrice: { type: 'number' },
},
},
messageAllowed: true,
},
output: {
mandatory: [
{
name: 'archived',
payload: { type: 'object', properties: { landingRate: { type: 'number' } } },
description: '归档闭环:情报回写 + 落地率落账',
},
],
selective: [],
},
requiredDeliverables: [
{ key: 'history-archive', label: '历史价格情报(归档)' },
{ key: 'landing-stats', label: '报价落地率统计' },
],
acceptanceCriteria: [
{ key: 'reason-logged', label: '拒绝原因 / 竞对价位已回写', level: 'L1', predicate: 'reasonLogged = true' },
{ key: 'profile-updated', label: '客户画像标签已更新', level: 'L2', predicate: 'profileUpdated = true' },
{ key: 'bd-release', label: 'BD 放行', level: 'L5' },
],
prohibitions: [{ key: 'no-blank-archive', statement: '不得空归档 —— 每一单不成交的报价也是情报资产' }],
authorization: { discretion: [], preauthorizedActions: [], humanCallBudget: 2 },
resources: {
tools: [],
skills: ARCHIVE_SKILLS.map((s) => s.id),
models: ['quote-extractor'],
roles: ['BD'],
budget: { steps: 30, tokens: 60_000, activeMinutes: 60, humanCalls: 2 },
},
},
declarations: {
models: ['quote-extractor'],
tools: [],
ledger: [
{
// 共享域:跨活动的沉淀事实(AM 11.3 暗耦合禁令的两条合法路径之一)
domain: 'shared',
object: 'history_price',
label: '历史价格情报',
fields: [
{ name: 'pn', type: 'text', primaryKey: true, masked: false },
{ name: 'quoted_at', type: 'date', primaryKey: true, masked: false },
{ name: 'lost_reason', type: 'text', primaryKey: false, masked: false, label: '拒绝原因' },
{ name: 'competitor_price', type: 'number', primaryKey: false, masked: false, label: '竞对价位' },
],
},
{
domain: 'shared',
object: 'customer',
label: '客户资料库',
fields: [
{ name: 'customer_code', type: 'text', primaryKey: true, masked: false, label: '客户码' },
{ name: 'grade', type: 'text', primaryKey: false, masked: false, label: '客户等级' },
{ name: 'profile_tags', type: 'text', primaryKey: false, masked: false, label: '画像标签' },
],
},
{
domain: 'shared',
object: 'landing_stats',
label: '报价落地率统计',
fields: [
{ name: 'period', type: 'text', primaryKey: true, masked: false, label: '月份' },
{ name: 'landing_rate', type: 'number', primaryKey: false, masked: false, label: '落地率' },
{ name: 'type_a_hit', type: 'number', primaryKey: false, masked: false, label: 'TypeA命中' },
{ name: 'reply_rate_d3', type: 'number', primaryKey: false, masked: false, label: 'D+3回复率' },
],
},
],
listeners: [],
// 7 天闭环(MVP示例 §1.7)
harness: { memoryWindow: 15, stallAfter: 'P1D', nudge: [], retry: { times: 2, backoff: 'PT30S' } },
},
assets: {
businessModel: {
paradigm: 'flow',
steps: [
{
kind: 'llm',
name: 'S1_log_result',
label: 'S1 结果登记(拒绝原因 / 竞对价位)',
input: { reason: 'reason', quoteNo: 'quoteNo' },
output: {
domain: 'shared',
object: 'history_price',
key: { pn: 'pn', quoted_at: 'quotedAt' },
fields: { lost_reason: 'lostReason' },
},
model: 'quote-extractor',
template: '从跟进反馈里抽出拒绝原因与竞对价位。只输出 JSON。反馈:{{reason}}',
outputSchema: {
type: 'object',
properties: { lostReason: { type: 'string' }, competitorPrice: { type: 'number' } },
},
view: 'archive-logged',
failure: { retry: { times: 2, backoff: 'PT30S' }, fallback: { kind: 'human', workOrder: 'execution' } },
},
{
kind: 'pure-tool',
name: 'S2_profile',
label: 'S2 画像更新(供 P-01 的客户等级因子取用)',
input: { customerCode: 'customerCode', reason: 'reason' },
output: {
domain: 'shared',
object: 'customer',
key: { customer_code: 'customerCode' },
fields: { profile_tags: 'tags' },
},
tool: 'quote-archive.profile',
failure: { retry: { times: 1, backoff: 'PT10S' }, fallback: { kind: 'blocked' } },
},
{
kind: 'pure-tool',
name: 'S3_landing_rate',
label: 'S3 落地率统计',
input: {},
output: {
domain: 'shared',
object: 'landing_stats',
key: { period: 'period' },
fields: { landing_rate: 'landingRate' },
},
tool: 'quote-archive.landing-rate',
failure: { retry: { times: 1, backoff: 'PT10S' }, fallback: { kind: 'blocked' } },
},
{
kind: 'human',
name: 'S4_release',
label: 'S4 归档闭环验收放行',
input: {},
workOrder: 'acceptance',
card: { title: '情报归档请验收', deliverable: 'history-archive' },
deadline: 'P1D',
view: 'archive-release',
failure: { retry: { times: 0, backoff: 'PT30S' }, fallback: { kind: 'blocked' } },
},
],
parallelGroups: [],
},
skills: ARCHIVE_SKILLS,
viewTemplates: [
{ name: 'archive-logged', html: ARCHIVE_LOGGED },
{ name: 'archive-release', html: ARCHIVE_RELEASE },
],
cardSchemas: {},
distillHooks: [
{ on: 'terminal', prompt: '归纳丢单的共性:价格、交期、竞对、客户类型 —— 供下一单更快更准。' },
],
},
samples: [
{
name: '客户拒绝',
input: { customerCode: 'C001', quoteNo: 'Q202601', reason: '竞对报价更低' },
expect: { ports: ['archived'] },
},
],
entry: { file: 'index.js', checksum: 'dev-entry-quote-archive' },
};