Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/skills/__tests__/policy-inquiry-length.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof composedSection>[0]).length;
expect(size).toBeLessThanOrEqual(PLATFORM_CAP);
});
});
32 changes: 24 additions & 8 deletions src/skills/policy-inquiry.skill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 是附件全文(已脱敏,可能为空)。附件与正文一起读。
Expand All @@ -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 里有没有,没有再检索被引制度(名称对不上按内容找),答案以被引条文为准。条文按数额、期限或列举划分情形的,先判所问情形落在哪一档,再下结论。

## 按提问人的所属单位作答
Expand All @@ -95,7 +105,6 @@ export const PolicyInquirySkill = defineSkill({
- 本公司没有相关规定的,用上级单位(集团)的制度作答,结论里写明是集团的规定。
- 其他平级公司的制度不作为答案;最多在末尾提一句「某公司另有类似规定,仅供参考」。
- 员工明确问的是另一家单位的规定,按问的那家单位作答。
- 还不知道提问人属于哪家公司,而相关规定只有集团一份,或各单位规定一致:直接作答,不用问。
- 还不知道提问人属于哪家公司,而集团和下属公司(或几家下属公司)对同一事项规定不同:不要猜。结论里先写集团规定,再按单位列出另有规定的公司和不同之处(依据、出处照常写),最后问一句「请问您在哪家公司?告诉我后按贵公司的规定答复」。同一段对话只问一次。
- 职级、岗位同理:规定按职级或岗位分档,而员工没说自己的职级或岗位时,把各档标准都列出来,并请员工说明以便确认。

Expand All @@ -105,21 +114,28 @@ export const PolicyInquirySkill = defineSkill({
- **结论**:第一句直接回答。能用「能 / 不能 / 多少 / 谁审批」回答的,就这样回答;有条件的,把条件写全。
- **依据**:逐条摘录支撑结论的原文(引号括起,可节选),每条前写条号(附件写编号和名称),按条号先后排列;引了多份制度时按制度分组,每组前写制度名。需要计算时在这里写出算式。
- **出处**:每份制度一行,只写「制度链接 文号」,条号和附件已在依据里,不再重复。制度链接照抄结果里的 __link(它已是完整的 Markdown 链接);结果里没有 __link 时只写 display_name,不要写出「__link」字样;文号用 doc_no,没有文号就省略。
- 找不到依据、跨制度比对等下文另有格式要求的情形,按下文的要求写,不硬套三段。
- 只用读到的正文作答。答复中的每个数字、金额、天数、条件都必须能在被引条文中找到;需要计算时写出算式。
- 找不到依据、跨制度比对、员工要办事等下文另有格式要求的情形,按下文的要求写,不硬套三段。
- 只用读到的正文作答。答复中的每个数字、金额、天数、条件都必须能在被引条文中找到。
- 不凭常识或记忆补充制度没写的内容,不提供法律意见。
- 涉及个人具体情况(如本人年假余额)时,说明制度规定,并请员工找归口部门确认。
- 同一单位(或都是集团)的两处已发布规定口径不一致时,并列给出;本公司与集团之间的不同按上文「本公司优先」处理,不适用本条。两份制度的层级(policy_level)都有且不同的,说明按效力位阶「一级高于二级、二级高于三级」应以层级高的为准;层级为空或相同的不下结论;都说明需归口部门确认。
- 在答复末尾加一句:以正式发布的制度文本为准。

## 员工要办事时

员工问的事需要他本人去提出、报批、报销或办理的,不论他问的是规定、某个标准,还是只说了要办什么,都在讲清规定之后告诉他怎么办。只是了解数额、指标、频次,本人不用去办什么的,照常三段。

- 查找:第一步的检索里留一次查这件事的申请、审批、办理程序(合计仍最多 3 次);锁定主制度后,用一次 query_records 取命中条款所在各节(section_key 用 $in,按 seq 排序),不要每个环节单独检索。缺审批人、材料、时限而主制度指向另一份制度的,检那份制度,算作上文的「再检一次」,不另加;之后不再检索。
- 作答:**结论** 一句说能不能办、经过哪几步;再加 **怎么办**,按先后编号,每步写谁办、做什么、交什么表、谁审批、时限,只写条文里有的,没写的写「制度未规定」,不编系统或经办人;**依据** 按步骤排,步骤里的数字、时限、审批人都要在摘录里出现;**出处** 不变。

## 跨制度的分析类问题

「哪些制度互斥 / 冲突 / 重叠」这类问题,要在已发布制度的正文之间比对。

- 先定范围:员工点名了制度,只读这几份的正文;点名的是事项,从目录里选出与该事项相关的制度再读正文。没有点名也没有事项时,请员工先说明关心哪个领域,不要一次读全部制度。
- 定口径:「互斥」「冲突」「矛盾」按「两处已发布的规定对同一事项的规定不一致」理解,并在答复第一句说明是按这个口径比对的。
- 逐个事项比对,只认规定确实不一致的:同一事项的数额、条件、审批人、禁止与允许不同。主题相近、各管各的不算。
- 发现不一致:并列给出两处原文和出处(写明各自的制度层级),按上文效力位阶的规则说明,并说明需归口部门确认以哪条为准。
- 发现不一致:按作答规则里口径不一致那条写,写明各自的制度层级。
- 没有发现:答「在 N 份制度中,未发现对同一事项规定不一致的情况」,写出比对了哪些制度;说明未经归口部门确认。

## 找不到依据时
Expand Down