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

Aperta Adatta ai principianti
#5,594 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Inizia con _build_run_state_from_json e _TRUSTED_RUN_STATE_ERROR_MESSAGES in src/agents/run_state.py, poi leggi come RunState.from_json e from_string gestiscono gli errori di validazione. Riproduci i casi non validi di function_tool_approvals usando l’esempio fornito e verifica se esistono già test che coprono il ripristino dei checkpoint. Questi casi devono generare UserError con il messaggio di validazione, come avviene per tool_invocations.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
30.5k
Fork
5k
Merge medio
16h 15m
PR unite (30g)
154

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openai/openai-agents-python

Tutte le issue di openai/openai-agents-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.