Skip to content

[feat][evaluation]: support declaring custom output field schemas for CustomAgent - #627

Merged
Asichurter merged 5 commits into
mainfrom
feat/loong-ext-output
Aug 24, 2026
Merged

[feat][evaluation]: support declaring custom output field schemas for CustomAgent#627
Asichurter merged 5 commits into
mainfrom
feat/loong-ext-output

Conversation

@Asichurter

@Asichurter Asichurter commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

What type of PR is this?

feat

Check the PR title

  • This PR title match the format: [<type>][<scope>] <description>. For example: [fix][backend] flaky fix
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Add documentation if the current PR requires user awareness at the usage level.
  • This PR is written in English. PRs not in English will not be reviewed.

(Optional) Translate the PR title into Chinese

(Optional) More detailed description for this PR(en: English/zh: Chinese)

en:
Allow a CustomAgent evaluation target to declare custom output field schemas, so
downstream evaluation can consume extra key-value output beyond the message body.

Changes:

  1. entity.CustomAgent gains a CustomFieldSchemas []*CustomFieldSchema field
    (reusing the existing entity.CustomFieldSchema type).
  2. Adds ValidateCustomFieldSchemas, a create-time validation that rejects
    invalid declarations rather than falling back silently:
    • field name must be non-empty, contain no whitespace, match
      ^[a-zA-Z][a-zA-Z0-9_]*$, and be at most 50 characters;
    • names must be unique within a declaration;
    • at most 20 fields may be declared;
    • the type must resolve to one of the supported types (string / integer /
      float / boolean / multipart); object, array and trajectory are rejected.
  3. Adds unit tests covering the validation branches and the accepted wire form.

(Optional) Which issue(s) this PR fixes

Asichurter and others added 4 commits August 11, 2026 19:29
M-7358884601

长连接 Agent(CustomAgent)非消息额外 KV 数据透出需求的 coze-loop 侧改动
(方案 B:声明入口在 fornax 应用注册页,经 ListApplicationRPC 注入,IDL 零改动)。

1. entity.CustomAgent 新增 CustomFieldSchemas []*CustomFieldSchema
   (复用既有 entity.CustomFieldSchema,写法照抄 CustomRPCServer)
2. 新增 ValidateCustomFieldSchemas 创建时前置校验:
   - 字段名 ^[a-zA-Z][a-zA-Z0-9_]*$ + 上限 50 字符,与前端既有
     columnNameRuleValidator / maxLength={50} 严格一致(不允许 _ 开头),
     避免「前端拦得住、OpenAPI 绕得过」的脏数据死锁
   - 保留字拦截(引用 consts 常量,不写字面量)
   - 同批重名拦截
   - 类型白名单:4 类标量 + 多模态;显式拒绝 Object/Array/Trajectory
     (Trajectory 会被 buildOutputSchema 静默丢弃)
3. 单测覆盖 R1-R8b 全部规则与合法用例边界
P0:长连接 Agent 声明输出字段后创建评测对象必失败,报「缺少字段类型」。

根因:ValidateCustomFieldSchemas 把 SchemaKey 当成标量类型的必填载体,
但既有范式(前端 custom-field-schema-convert.ts:35-43 +
field-convert.ts convertDataTypeToSchema,后端 buildOutputSchema)里
SchemaKey 只用来标记 Trajectory 一种特例:
  - 标量     content_type=text,       schema_key=undefined, text_schema=JSON Schema
  - 多模态   content_type=multi_part, schema_key=undefined
  - 轨迹     content_type=text,       schema_key=trajectory
前端提交的 5 种类型 schema_key 全是 undefined,于是全部被判「缺少字段类型」。

改动:
- 类型判定改为对齐既有范式:ContentType==MultiPart 即多模态;
  显式带 SchemaKey 时查白名单(拦 Trajectory 等);其余以 text_schema
  顶层 type 为准(白名单 string/integer/number/boolean)。
  SchemaKey 不再必填。
- Object/Array 的拒绝从「无对应 SchemaKey」迁到「text_schema 顶层
  type 为 object/array」,保持原意图在新范式下的等价落点。
- 其他既有校验(名字正则/长度 50/保留字/同批重名)逐字未动。
- 单测改用前端真实 wire 值(schema_key=nil + text_schema),
  并新增 TestValidateCustomFieldSchemas_FrontendWireFormat 防回归。

爆炸半径:ValidateCustomFieldSchemas 仅由 CustomAgent 的 BuildBySource
调用,CustomPsm / SandboxAgent / A2A / WebAgent 均不经过此函数。

Co-Authored-By: Claude <noreply@anthropic.com>
…M-7358884601

三处修正(CR 发现):

1. 删除保留字校验(原 R6)。该规则本次新增、main 上不存在同类校验,而对照的
   既有类型 custom_psm 完全不经过任何校验,一直允许声明 actual_output。
   这条规则反而是本需求 P0-2 的根因:它导致前端无法像 custom_psm 那样预置
   actual_output 只读锁定行。改为与 custom_psm 一致地接受,前端稳定传、
   后端 buildCustomAgentOutputSchema 侧去重。

2. 堵住 text_schema 两条绕过路径。原「多模态」与「显式带白名单 SchemaKey」
   两个分支都直接 return nil 不看 TextSchema,而消费侧对 TextSchema 非空是
   无条件覆盖 JsonSchema、与走哪条分支无关 —— object/array 因此可借这两条路
   夹带进 OutputSchema。新增 validateCustomFieldTextSchemaIfPresent:
   为空放行、非空仍查白名单。

3. 新增声明数量上限 R1b = 20,对齐前端表单 maxColumn(custom-field-schema-config
   .tsx),与既有 maxLength=50 同一条铁律:后端不设限则 OpenAPI 可写入远超上限
   的声明,用户下次在页面编辑该 Agent 时因前端上限无法保存(脏数据死锁)。

测试:删除 4 条已失效的保留字必拦用例,新增 actual_output / trajectory 字段名
放行用例、20/21 边界用例、4 条绕过必拦 + 2 条合法对照。均为纯函数直调,无 mockey。
@CLAassistant

CLAassistant commented Aug 24, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Asichurter
Asichurter requested review from jamesonics and kidkidkid and removed request for jamesonics and kidkidkid August 24, 2026 09:13
@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #627      +/-   ##
==========================================
+ Coverage   78.36%   78.41%   +0.04%     
==========================================
  Files         693      694       +1     
  Lines       85184    85353     +169     
==========================================
+ Hits        66753    66928     +175     
+ Misses      14503    14500       -3     
+ Partials     3928     3925       -3     
Flag Coverage Δ
unittests 78.41% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...n/entity/target_builtin_custom_agent_validation.go 100.00% <100.00%> (ø)

... and 13 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2bf8536...de13488. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…d messages in English

Translate comments, test names and error messages to English and remove
non-public context, so the file is consistent with the repository's
open-source conventions. No logic or test data changes.

Co-Authored-By: Claude <noreply@anthropic.com>
@Asichurter Asichurter changed the title [feat][evaluation] CustomAgent 支持声明自定义输出字段 schema (M-7358884601) [feat][evaluation]: support declaring custom output field schemas for CustomAgent Aug 24, 2026
@Asichurter
Asichurter merged commit a2c804d into main Aug 24, 2026
17 checks passed
@Asichurter
Asichurter deleted the feat/loong-ext-output branch August 24, 2026 11:21
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.

4 participants