RunState.from_string()/from_json() replace approval-checkpoint validation errors with RuntimeError('Error details are redacted.')

未关闭 适合新手
#5,594 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

从 src/agents/run_state.py 中的 _build_run_state_from_json 和 _TRUSTED_RUN_STATE_ERROR_MESSAGES 开始,然后阅读 RunState.from_json 和 from_string 如何处理验证错误。使用提供的示例重现格式错误的 function_tool_approvals 情况,并检查是否已有涵盖检查点恢复的测试。完成的标准是这些情况会引发带有验证消息的 UserError,与 tool_invocations 的行为一致。

由索引模型根据 Issue 内容生成。

描述

Please read this first
  • Have you read the docs? Agents SDK docs Yes
  • Have you searched for related issues? Yes. #4297 maintains the trusted-message list; I found no report about these messages.
Describe the bug

Restoring a checkpoint whose context.function_tool_approvals is malformed raises RuntimeError: Error details are redacted. instead of the UserError the validation code raises. Sibling checks keep their type and message: a malformed context.tool_invocations raises UserError: RunState tool_invocations must be a mapping. Applications that handle invalid checkpoints by catching UserError therefore miss this case, and the diagnostic is lost.

Cause: _build_run_state_from_json (src/agents/run_state.py) raises UserError with messages such as "RunState function_tool_approvals must be a list.", but those messages are not in _TRUSTED_RUN_STATE_ERROR_MESSAGES, so the redaction in RunState.from_json/from_string treats them as untrusted and replaces both the type and the message.

Debug information
  • Agents SDK version: v0.24.0 (also reproduced on main at 27c75c5)
  • Related library versions (optional, e.g. any-llm, litellm, or pydantic): openai 3.29.0, pydantic 2.12.3
  • Python version: 3.12.13
  • Operating system: Linux (aarch64)
  • Model and model provider: None (no model call)
  • Does the issue reproduce with the latest Agents SDK release? Yes (v0.24.0, and main at 27c75c5)
  • Does the issue occur consistently or intermittently? Consistently
tool_invocations = []:         UserError: RunState tool_invocations must be a mapping.
function_tool_approvals = {}:  RuntimeError: Error details are redacted.
invalid approval record:       RuntimeError: Error details are redacted.
Repro steps
import asyncio
import json

from agents import Agent, RunContextWrapper, RunState

agent = Agent(name="Assistant")
checkpoint = json.loads(RunState(context=RunContextWrapper(context={}), original_input="Hi", starting_agent=agent).to_string())


async def restore(field, value):
    damaged = json.loads(json.dumps(checkpoint))
    damaged["context"][field] = value
    try:
        await RunState.from_string(agent, json.dumps(damaged))
    except Exception as error:
        return f"{type(error).__name__}: {error}"


async def main():
    print("tool_invocations = []:        ", await restore("tool_invocations", []))
    print("function_tool_approvals = {}: ", await restore("function_tool_approvals", {"unexpected": "mapping"}))
    print("invalid approval record:      ", await restore("function_tool_approvals",
                                                         [{"tool_key": "save", "decision": ["invalid"]}]))


asyncio.run(main())
Expected behavior

All three lines report a UserError with the validation message, e.g. UserError: RunState function_tool_approvals must be a list.

主要语言
Python
星标
30.5k
派生
5k
平均合并
16 小时 15 分钟
30 天内合并 PR
154

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openai/openai-agents-python 的其他 Issue

查看 openai/openai-agents-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。