Skip to content

Commit ccef1d4

Browse files
committed
fix review comments
1 parent 8800212 commit ccef1d4

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/agents/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ def _with_reasoning_item_id_policy(result: RunResult) -> RunResult:
663663
hooks=hooks,
664664
context_wrapper=context_wrapper,
665665
run_config=run_config,
666+
server_manages_conversation=server_conversation_tracker is not None,
666667
run_state=run_state,
667668
)
668669

tests/test_run_impl_resume_paths.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,72 @@ async def fake_run_single_turn(**_kwargs):
225225
assert "function_call" in saved_types
226226

227227

228+
@pytest.mark.parametrize(
229+
("conversation_id", "previous_response_id", "auto_previous_response_id"),
230+
[
231+
("conv_1", None, False),
232+
(None, "resp_prev", False),
233+
(None, None, True),
234+
],
235+
)
236+
@pytest.mark.asyncio
237+
async def test_resumed_interruption_passes_server_managed_conversation_flag(
238+
monkeypatch: pytest.MonkeyPatch,
239+
conversation_id: str | None,
240+
previous_response_id: str | None,
241+
auto_previous_response_id: bool,
242+
) -> None:
243+
agent = Agent(name="resume-agent")
244+
context_wrapper: RunContextWrapper[dict[str, str]] = RunContextWrapper(context={})
245+
state = RunState(
246+
context=context_wrapper,
247+
original_input="input",
248+
starting_agent=agent,
249+
max_turns=1,
250+
conversation_id=conversation_id,
251+
previous_response_id=previous_response_id,
252+
auto_previous_response_id=auto_previous_response_id,
253+
)
254+
255+
state._current_step = NextStepInterruption(interruptions=[])
256+
state._model_responses = [
257+
ModelResponse(output=[], usage=Usage(), response_id="resp_1"),
258+
]
259+
state._last_processed_response = ProcessedResponse(
260+
new_items=[],
261+
handoffs=[],
262+
functions=[],
263+
computer_actions=[],
264+
local_shell_calls=[],
265+
shell_calls=[],
266+
apply_patch_calls=[],
267+
tools_used=[],
268+
mcp_approval_requests=[],
269+
interruptions=[],
270+
)
271+
server_managed_values: list[bool] = []
272+
273+
async def fake_resolve_interrupted_turn(**kwargs: object) -> SingleStepResult:
274+
server_managed_values.append(cast(bool, kwargs["server_manages_conversation"]))
275+
return SingleStepResult(
276+
original_input="input",
277+
model_response=ModelResponse(output=[], usage=Usage(), response_id="resp_resume"),
278+
pre_step_items=[],
279+
new_step_items=[],
280+
next_step=NextStepFinalOutput("done"),
281+
tool_input_guardrail_results=[],
282+
tool_output_guardrail_results=[],
283+
)
284+
285+
monkeypatch.setattr(run_module, "resolve_interrupted_turn", fake_resolve_interrupted_turn)
286+
287+
runner = run_module.AgentRunner()
288+
result = await runner.run(agent, state, run_config=RunConfig())
289+
290+
assert result.final_output == "done"
291+
assert server_managed_values == [True]
292+
293+
228294
@pytest.mark.asyncio
229295
async def test_resumed_approval_does_not_duplicate_session_items() -> None:
230296
async def test_tool() -> str:

0 commit comments

Comments
 (0)