Dayward AI

Interview Bank

328 questions total; 1 shown with current filters.

Mastering Codex and the OpenAI Agents SDK in 5 Days

D4 The OpenAI Agents SDK: Agents, Handoffs, Guardrails, Sessions, Tracing

  • Both Agents SDK sessions and the Responses API's previous_response_id remember multi-turn state. How do you choose, and what role does tracing play?Agents SDK 的 session 和 Responses API 的 previous_response_id 都能记住多轮,怎么选?tracing 在这里起什么作用?
    Common in ChinaCommon overseasIntermediate#agents-sdk#sessions#tracing

    How to reason about it · think before answering

    1. This probes your sensitivity to who holds the state, the SDK-level echo of 'you carry the history yourself'.
    2. Ask three questions: can the history be audited, trimmed or replayed, and kept within data-residency rules? previous_response_id keeps history server-side with minimal requests but answers all three poorly; sessions keep it in your store and answer all three, at the cost of managing storage.
    3. Conclude: prototypes and internal tools take previous_response_id; user-facing production keeps its own copy, for which sessions are the ready-made path; both can coexist.
    4. Of the four session operations, pop_item deserves mention: removing the last turn to honor a user's undo is only possible when you own the history.
    5. Tracing makes multi-agent behavior explainable: on by default, one trace per run recording turns, tool calls, handoffs and guardrail results; group a conversation with withTrace or group_id; disable via env var or swap in your own exporter for sensitive data.
    6. Expect the follow-up: does tracing ship user data out? By default it goes to the platform dashboard, so regulated settings must disable it or replace the processors.

    分析过程 · 先想清楚再作答

    1. 这题考的是对「状态放在谁手里」的敏感度,是 30 天课 D1「历史靠你自己搬」在 SDK 层的翻版。
    2. 拆法是问三件事:历史能不能审计、能不能裁剪或重放、能不能满足数据驻留要求。previous_response_id 的历史在服务端,请求最小、代码最简,但三个问题都答不好;session 的历史在你手里(内存、SQLite、Redis),三个都能做,代价是自己管存储。
    3. 结论:原型与内部工具用 previous_response_id 省事;面向用户的生产系统至少自己落一份历史,session 是现成的落法;两者可以同时用。
    4. session 的四个接口(取、追加、弹出最后一条、清空)里 pop_item 值得点出:用户撤回上一句时把最后一轮拿掉再重跑,这是自己持有历史才能做的事。
    5. tracing 的作用是让多 Agent 系统的行为可解释:默认开启,每次 run 一条,记录每轮、每次工具调用、交接与护栏判断;用 withTrace 或 group_id 把一段对话归到一起;敏感数据场景用环境变量关掉或换成自己的导出器。
    6. 可预期的追问:tracing 会不会把用户数据传出去?默认会传到平台面板,所以合规场景要么关、要么 setTraceProcessors 换成自己的后端。

    Key points

    • previous_response_id keeps history server-side, small and simple, but weak on audit, trimming and residency
    • Sessions keep history in your store, auditable and replayable, with pop_item for undo; production keeps its own copy
    • Tracing is on by default, one trace per run, capturing turns, tools, handoffs and guardrails, grouped via group_id
    • For sensitive data disable it with OPENAI_AGENTS_DISABLE_TRACING or swap in your own exporter

    答题要点

    • previous_response_id 历史在服务端,请求小代码简,但难审计、难裁剪、难满足数据驻留
    • session 历史在自己手里,可审计可重放,pop_item 支持撤回;生产至少自己落一份
    • tracing 默认开、每次 run 一条,记录每轮工具、交接与护栏,用 group_id 归组
    • 敏感数据场景用 OPENAI_AGENTS_DISABLE_TRACING 关掉或换成自己的导出器