Agent 将 const 误解为字面值而非 schema 约束 #129

Closed
opened 2026-06-06 00:57:49 +00:00 by xiaonuo · 0 comments
Owner

问题

当 output schema 使用 const 关键字时,agent 不理解这是 JSON Schema 约束,而是把 const 当作字面值输出。

复现

hello.yaml:

steps:
  - name: greet
    output:
      $status:
        type: string
        const: greeted
      message: string
    procedure: |
      Write a short greeting.

运行后 agent 输出:

$status: const
message: "hello world"

期望输出:

$status: greeted
message: "hello world"

分析

const 是 JSON Schema 规范关键字,意思是"值必须是这个"。但 agent 不懂 JSON Schema,它看到的只是原始 schema 文本。

根因

UWF 引擎应该把 const: greeted 翻译成 agent 能理解的提示词,例如:

"你必须输出 $status: greeted"

而不是把原始 schema 直接丢给 agent。

临时 Workaround

在 procedure 里明确告诉 agent 输出什么值:

procedure: |
  Write a short greeting.
  
  Your response must start with YAML frontmatter:
  ```yaml
  $status: greeted
  message: "your greeting"

## 建议

在构建 agent prompt 时,把 schema 里的 `const` 翻译成自然语言指令,而不是原样注入。
## 问题 当 output schema 使用 `const` 关键字时,agent 不理解这是 JSON Schema 约束,而是把 `const` 当作字面值输出。 ## 复现 hello.yaml: ```yaml steps: - name: greet output: $status: type: string const: greeted message: string procedure: | Write a short greeting. ``` 运行后 agent 输出: ```yaml $status: const message: "hello world" ``` 期望输出: ```yaml $status: greeted message: "hello world" ``` ## 分析 `const` 是 JSON Schema 规范关键字,意思是"值必须是这个"。但 agent 不懂 JSON Schema,它看到的只是原始 schema 文本。 ## 根因 UWF 引擎应该把 `const: greeted` 翻译成 agent 能理解的提示词,例如: > "你必须输出 `$status: greeted`" 而不是把原始 schema 直接丢给 agent。 ## 临时 Workaround 在 procedure 里明确告诉 agent 输出什么值: ```yaml procedure: | Write a short greeting. Your response must start with YAML frontmatter: ```yaml $status: greeted message: "your greeting" ``` ``` ## 建议 在构建 agent prompt 时,把 schema 里的 `const` 翻译成自然语言指令,而不是原样注入。
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shazhou/united-workforce#129