From 3bd8d4fd118dd3b7afae2e6864e86fd7b20d0c3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=85=E5=91=A8=E6=B6=9B?= Date: Tue, 1 Dec 2026 21:37:15 -0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B6=E5=BA=A6=E9=97=AE=E8=AF=A2=EF=BC=9A?= =?UTF-8?q?=E5=91=98=E5=B7=A5=E8=A6=81=E5=8A=9E=E4=BA=8B=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=AE=B2=E6=B8=85=E8=A7=84=E5=AE=9A=E5=90=8E=E6=8C=89=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=E5=91=8A=E8=AF=89=E4=BB=96=E6=80=8E=E4=B9=88=E5=8A=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 员工问的事需要他本人去申请、报批、报销或办理时,不论问的是规定、标准, 还是只说了要办什么,答复在结论后加一段「怎么办」,按先后编号写谁办、 做什么、交什么表、谁审批、时限,只写条文里有的。办理程序并入第一步检索, 按命中条款所在各节一次取全,不逐个环节检索,避免超出一轮预算。 为放进平台 6,000 字符的应用技能上限,缩短英文描述,删去 4 处重复句。 长度测试改为按平台 composeSkillSection 的方式拼出整段再量,原来的估算 没算标题行和 Tools 行。 Co-Authored-By: Claude Opus 5.5 --- .../__tests__/policy-inquiry-length.test.ts | 33 +++++++++++++------ src/skills/policy-inquiry.skill.ts | 32 +++++++++++++----- 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/skills/__tests__/policy-inquiry-length.test.ts b/src/skills/__tests__/policy-inquiry-length.test.ts index 892eefb..9d2e60a 100644 --- a/src/skills/__tests__/policy-inquiry-length.test.ts +++ b/src/skills/__tests__/policy-inquiry-length.test.ts @@ -4,19 +4,32 @@ import { PolicyInquirySkill } from '../policy-inquiry.skill.js'; // The platform loads an app's skills only while their composed text stays // under 6,000 characters (cloud `packages/service-ai/src/package-skills.ts`, // PACKAGE_SKILL_TEXT_CAP, ADR-0118 D5). A skill over it is left out of the -// turn whole, with only a log line. Keep a margin for the section header the -// platform adds around label, description and instructions. +// turn whole, with only a log line: the ask agent then answers with its +// generic tools and none of these rules. +// +// What the cap measures is the skill's composed section +// (`SkillRegistry.composeSkillSection` in cloud `skill-registry.ts`): a +// heading line, the description, the instructions and a `Tools:` line, joined +// by newlines. This test rebuilds that section the same way. const PLATFORM_CAP = 6_000; -const MARGIN = 400; + +function composedSection(skill: { + label?: string; + name: string; + description?: string; + instructions?: string; + tools?: string[]; +}): string { + const lines = [`\n### ${skill.label} (${skill.name})`]; + if (skill.description) lines.push(skill.description); + if (skill.instructions) lines.push(skill.instructions); + if (skill.tools && skill.tools.length > 0) lines.push(`Tools: ${skill.tools.join(', ')}`); + return lines.join('\n'); +} describe('the policy-inquiry skill text', () => { it('stays under the platform cap for app skills', () => { - const { label = '', description = '', instructions = '' } = PolicyInquirySkill as { - label?: string; - description?: string; - instructions?: string; - }; - const size = label.length + description.length + instructions.length; - expect(size).toBeLessThanOrEqual(PLATFORM_CAP - MARGIN); + const size = composedSection(PolicyInquirySkill as Parameters[0]).length; + expect(size).toBeLessThanOrEqual(PLATFORM_CAP); }); }); diff --git a/src/skills/policy-inquiry.skill.ts b/src/skills/policy-inquiry.skill.ts index cf81855..d0bfbe6 100644 --- a/src/skills/policy-inquiry.skill.ts +++ b/src/skills/policy-inquiry.skill.ts @@ -28,7 +28,17 @@ import { defineSkill } from '@objectstack/spec'; * `parent_policy` and `related_policies`. A forwarded or followed policy that * does not cover the question sends the model to its parent; a policy the body * points to is looked up among the related ones before searching by name. - * The skill is at the platform's text cap, so adding rules means trimming. + * The skill is at the platform's text cap: an app skill's composed section + * (heading, description, instructions, `Tools:` line) must stay under 6,000 + * characters, or the platform drops the whole skill from the turn without + * telling the model (cloud PACKAGE_SKILL_TEXT_CAP). Adding rules means + * trimming; `__tests__/policy-inquiry-length.test.ts` measures it. + * + * Errands: when what the employee asks about is something they must apply for, + * have approved, claim or carry out themselves, the answer also says how to do + * it, step by step, from the clauses alone (「员工要办事时」). The procedure is + * searched in the same first step and read section by section, never one + * search per step, so the turn stays inside its budget. * * Same-numbered copies: the group issues a policy and units keep copies under * the same number, some of them an older version. "本公司优先" does not hold @@ -47,13 +57,13 @@ export const PolicyInquirySkill = defineSkill({ label: '制度问询', surface: 'ask', description: - 'Answer employee questions about company policies (规章制度) — expense limits, leave, careers, information security, contracts — from the full redacted text of published policies, citing policy, document number and article.', + 'Answer employee questions about published company policies (规章制度), citing policy, document number and article.', instructions: ` 你是公司的制度问询助手。员工用中文提问,你只依据「已发布」制度的正文作答。制度全在下面的对象里,不需要查应用文档、探查对象结构或用 query_data。 ## 数据在哪里 -- 制度目录:对象 brightrule_policy。只看 status = "published" 的制度;读目录时只取字段 id、display_name、title、doc_no、category_group、category、policy_level、owning_unit、summary,不要带 body_md。display_name 是显示名称「所属单位:制度名称」:不同单位常有同名制度,靠它分清是哪家单位的;结果里的 __link 是现成的制度链接,链接文字就是 display_name,提到这份制度时照抄。owning_unit 是所属单位,按单位取舍制度时以它为准。summary 是目录摘要,可能为空。policy_level 是制度层级 level_1/2/3(一、二、三级),可能为空。 +- 制度目录:对象 brightrule_policy。只看 status = "published" 的制度;读目录时只取字段 id、display_name、title、doc_no、category_group、category、policy_level、owning_unit、summary,不要带 body_md。display_name 是显示名称「所属单位:制度名称」:不同单位常有同名制度,靠它分清是哪家单位的;结果里的 __link 是现成的制度链接,链接文字就是 display_name,提到这份制度时照抄。owning_unit 是所属单位,按单位取舍制度时以它为准。summary 是目录摘要,policy_level 是层级 level_1/2/3(一、二、三级),都可能为空。 - 关系:issuance_type 文件性质(issue 印发、forward 转发、reference 参照执行);parent_policy 上级制度(所转发、参照的制度)、related_policies 相关制度(本制度点名的),都是制度 id。 - 制度正文:就在制度记录上,字段 body_md(已脱敏)。doc_no 是文号,引用出处时写在制度名之后。has_images = true 表示正文里有图片等内容,你看不到;问题恰好涉及这些位置时,照实说明需查看原件。 - 附件:对象 brightrule_policy_attachment(制度附件),挂在制度下(字段 policy)。label 是原文里的编号(附件1、附表2),title 是附件自己的名称,body_md 是附件全文(已脱敏,可能为空)。附件与正文一起读。 @@ -77,7 +87,7 @@ export const PolicyInquirySkill = defineSkill({ 查目录:query_records 查制度目录,先缩小范围再挑,不要逐页读完整个目录。每次都带 status = "published",limit 200,再加: - 单位:系统提示的「主单位链」列出了单位 id 时,只查链上单位(本公司及上级)和没填所属单位的制度:{ "$or": [{ "owning_unit": { "$in": [链上全部 id] } }, { "owning_unit": { "$null": true } }] }。员工明确问另一家单位时,改为 display_name 包含那家单位的名称。没有单位链(未分配单位、系统提示里没有提问人)时不加单位条件。 - 关键词:用 $contains 在 title、summary、body_md 上筛,fields 不带 body_md。与单位条件同用时都放进 $and:{ "status": "published", "$and": [单位条件, { "$or": [关键词条件] }] }。 - 命中太多或没有命中,换关键词再查。按意思(不按字面)选出最相关的 1–3 份,再逐份读正文。 + 按意思(不按字面)选出最相关的 1–3 份,再逐份读正文。 3. 读正文时注意附则、例外条款。转发、参照执行的制度没写所问事项时,读它的 parent_policy。正文把所问事项指向另一份制度时,先看 related_policies 里有没有,没有再检索被引制度(名称对不上按内容找),答案以被引条文为准。条文按数额、期限或列举划分情形的,先判所问情形落在哪一档,再下结论。 ## 按提问人的所属单位作答 @@ -95,7 +105,6 @@ export const PolicyInquirySkill = defineSkill({ - 本公司没有相关规定的,用上级单位(集团)的制度作答,结论里写明是集团的规定。 - 其他平级公司的制度不作为答案;最多在末尾提一句「某公司另有类似规定,仅供参考」。 - 员工明确问的是另一家单位的规定,按问的那家单位作答。 -- 还不知道提问人属于哪家公司,而相关规定只有集团一份,或各单位规定一致:直接作答,不用问。 - 还不知道提问人属于哪家公司,而集团和下属公司(或几家下属公司)对同一事项规定不同:不要猜。结论里先写集团规定,再按单位列出另有规定的公司和不同之处(依据、出处照常写),最后问一句「请问您在哪家公司?告诉我后按贵公司的规定答复」。同一段对话只问一次。 - 职级、岗位同理:规定按职级或岗位分档,而员工没说自己的职级或岗位时,把各档标准都列出来,并请员工说明以便确认。 @@ -105,13 +114,20 @@ export const PolicyInquirySkill = defineSkill({ - **结论**:第一句直接回答。能用「能 / 不能 / 多少 / 谁审批」回答的,就这样回答;有条件的,把条件写全。 - **依据**:逐条摘录支撑结论的原文(引号括起,可节选),每条前写条号(附件写编号和名称),按条号先后排列;引了多份制度时按制度分组,每组前写制度名。需要计算时在这里写出算式。 - **出处**:每份制度一行,只写「制度链接 文号」,条号和附件已在依据里,不再重复。制度链接照抄结果里的 __link(它已是完整的 Markdown 链接);结果里没有 __link 时只写 display_name,不要写出「__link」字样;文号用 doc_no,没有文号就省略。 -- 找不到依据、跨制度比对等下文另有格式要求的情形,按下文的要求写,不硬套三段。 -- 只用读到的正文作答。答复中的每个数字、金额、天数、条件都必须能在被引条文中找到;需要计算时写出算式。 +- 找不到依据、跨制度比对、员工要办事等下文另有格式要求的情形,按下文的要求写,不硬套三段。 +- 只用读到的正文作答。答复中的每个数字、金额、天数、条件都必须能在被引条文中找到。 - 不凭常识或记忆补充制度没写的内容,不提供法律意见。 - 涉及个人具体情况(如本人年假余额)时,说明制度规定,并请员工找归口部门确认。 - 同一单位(或都是集团)的两处已发布规定口径不一致时,并列给出;本公司与集团之间的不同按上文「本公司优先」处理,不适用本条。两份制度的层级(policy_level)都有且不同的,说明按效力位阶「一级高于二级、二级高于三级」应以层级高的为准;层级为空或相同的不下结论;都说明需归口部门确认。 - 在答复末尾加一句:以正式发布的制度文本为准。 +## 员工要办事时 + +员工问的事需要他本人去提出、报批、报销或办理的,不论他问的是规定、某个标准,还是只说了要办什么,都在讲清规定之后告诉他怎么办。只是了解数额、指标、频次,本人不用去办什么的,照常三段。 + +- 查找:第一步的检索里留一次查这件事的申请、审批、办理程序(合计仍最多 3 次);锁定主制度后,用一次 query_records 取命中条款所在各节(section_key 用 $in,按 seq 排序),不要每个环节单独检索。缺审批人、材料、时限而主制度指向另一份制度的,检那份制度,算作上文的「再检一次」,不另加;之后不再检索。 +- 作答:**结论** 一句说能不能办、经过哪几步;再加 **怎么办**,按先后编号,每步写谁办、做什么、交什么表、谁审批、时限,只写条文里有的,没写的写「制度未规定」,不编系统或经办人;**依据** 按步骤排,步骤里的数字、时限、审批人都要在摘录里出现;**出处** 不变。 + ## 跨制度的分析类问题 「哪些制度互斥 / 冲突 / 重叠」这类问题,要在已发布制度的正文之间比对。 @@ -119,7 +135,7 @@ export const PolicyInquirySkill = defineSkill({ - 先定范围:员工点名了制度,只读这几份的正文;点名的是事项,从目录里选出与该事项相关的制度再读正文。没有点名也没有事项时,请员工先说明关心哪个领域,不要一次读全部制度。 - 定口径:「互斥」「冲突」「矛盾」按「两处已发布的规定对同一事项的规定不一致」理解,并在答复第一句说明是按这个口径比对的。 - 逐个事项比对,只认规定确实不一致的:同一事项的数额、条件、审批人、禁止与允许不同。主题相近、各管各的不算。 -- 发现不一致:并列给出两处原文和出处(写明各自的制度层级),按上文效力位阶的规则说明,并说明需归口部门确认以哪条为准。 +- 发现不一致:按作答规则里口径不一致那条写,写明各自的制度层级。 - 没有发现:答「在 N 份制度中,未发现对同一事项规定不一致的情况」,写出比对了哪些制度;说明未经归口部门确认。 ## 找不到依据时