Skip to content

fix: 修正决策模型中 noul 类型不兼容部分 SytemOne 协议的问题 - #10930

Closed
AlionSSS wants to merge 3 commits into
AstrBotDevs:masterfrom
AlionSSS:fix/system-one-noul-type-compatible
Closed

AlionSSS wants to merge 3 commits into
AstrBotDevs:masterfrom
AlionSSS:fix/system-one-noul-type-compatible

Conversation

@AlionSSS

@AlionSSS AlionSSS commented Nov 1, 2026 •

Copy link
Copy Markdown

修复了 issue #10920

Modifications / 改动点

  • 在模型供应商页面中新增决策模型的设置:在布尔判断 noul 类型下,默认 criteria 值是否为"criteria": {"true": "", "false": ""},默认关闭,关闭时不传入 criteria。用于兼容某些 SystemOne 协议接口必须要传 true 和 false 字段的情况。
  • 修改了该设置对应的前端、后端代码
  • 添加了对应的测试用例
  • 基于本次修改内容完善了 zh 和 en 文档
  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

  • 对于强制要求传 true 和 false 的 SystemOne 协议接口,默认关闭设置,效果如下
QQ20261101-194308
  • 对于强制要求传 true 和 false 的 SystemOne 协议接口,开启设置后,效果如下
QQ20261101-194322

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。

  • 📚 I checked the affected WebUI instructions and screenshots in docs/zh and docs/en against the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog.
    / 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新 docs/zh 和 docs/en 的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txt 和 pyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Resolves #10920

Summary by Sourcery

Fix System One compatibility for boolean decision questions by providing and validating their required criteria fields.

Bug Fixes:

  • Ensure boolean decision questions include the required true and false criteria fields when sent through the System One protocol.
  • Reject boolean criteria with missing, extra, or invalid keys to prevent incompatible System One requests.

Documentation:

  • Update the English and Chinese AI decision-model guides to document boolean criteria requirements and defaults.

Tests:

  • Add coverage for forwarding boolean criteria and rejecting invalid boolean criteria.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="astrbot/core/provider/sources/system_one_decision_source.py" line_range="155-157" />
<code_context>
                 }
-            else:
+            elif isinstance(question, DecisionBooleanQuestion):
+                if not isinstance(question.criteria, Mapping) or set(
+                    question.criteria
+                ) != {"true", "false"}:
+                    raise ValueError(
+                        f"question {head} field `criteria` must be an object with `true`/`false` keys"
</code_context>
<issue_to_address>
**Invalid criteria reach System One**

When a boolean criteria mapping has exactly the `true` and `false` keys but at least one value is not a string, `ask()` checks only the keys, then copies the values into the JSON payload. System One receives values that violate the string-description contract and rejects the request instead of returning a decision or a local validation error.

Validate that both criteria values are strings before copying them into the payload.
</issue_to_address>

### Comment 2
<location path="astrbot/core/provider/sources/system_one_decision_source.py" line_range="167" />
<code_context>
+                    "criteria": dict(question.criteria),
                 }
+            else:
+                raise TypeError(
+                    f"question {head} type must be one of the following: DecisionBooleanQuestion, DecisionChoiceQuestion, DecisionScoreQuestion"
+                )
</code_context>
<issue_to_address>
**Unsupported questions raise the wrong exception**

When a caller passes an unsupported question object without an `instructions` attribute, `ask()` accesses `question.instructions.strip()` before reaching the fallback type check, so it raises `AttributeError` instead of `TypeError`; callers handling unsupported types by catching `TypeError` miss the failure.

Check that the question has a supported type before accessing its instructions.
</issue_to_address>

Linked issues

#10920 [Bug] 决策模型协议 SystemOne 的 noul 类型请求未兼容标准格式 · 1 of 1 met

# Requirement Status Notes
1 Include criteria with true and false keys in System One noul questions. ✅ Met Boolean questions default to empty true and false descriptions, and the System One request forwards both keys.

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: astrbot/core/provider/sources/system_one_decision_source.py:157, astrbot/core/provider/sources/system_one_decision_source.py:167


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread astrbot/core/provider/entities.py Resolved

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linked issues

#10920 [Bug] 决策模型协议 SystemOne 的 noul 类型请求未兼容标准格式 · 0 of 1 met

# Requirement Status Notes
1 noul 类型 Questions 添加 criteria 的 true/false 字段,以兼容 SystemOne 接口 🟡 Partly met 显式传入布尔 criteria 或启用配置后会携带 true/false 字段,但该配置默认关闭,未配置的请求仍会省略 criteria。

Comment thread astrbot/core/config/default.py Resolved
@AlionSSS
AlionSSS requested a review from Soulter November 1, 2026 12:12
@Soulter

Soulter commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

你好,我觉得加单独的配置项也不是一个很好的解决方案。我觉得保留可选的入参,将选择权留给调用方(比如插件)即可,不需要单独的配置项。

这个配置不是用户关心的,因此不需要显式给用户看

@AlionSSS AlionSSS closed this Nov 1, 2026
@github-project-automation github-project-automation Bot moved this from Closed unmerged to Done in AstrBot Roadmap Nov 2, 2026
@Soulter Soulter moved this to Closed unmerged in AstrBot Roadmap Nov 2, 2026
@Soulter Soulter moved this from Done to Closed unmerged in AstrBot Roadmap Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed unmerged

Development

Successfully merging this pull request may close these issues.

[Bug] 决策模型协议 SystemOne 的 noul 类型请求未兼容标准格式

2 participants