Skip to content

Commit d01bc67

Browse files
declan-scaleclaude
andcommitted
fix(openai): forward previous_response_id in run_agent_streamed_auto_send [greptile]
The unified-surface migration of run_agent_streamed_auto_send dropped previous_response_id: it was accepted (suppressed by noqa: ARG002) but never passed to Runner.run_streamed, so any caller continuing a Responses-API conversation silently started a fresh one. Mirror the non-auto-send run_agent_streamed branching (max_turns x previous_response_id) and drop the now-incorrect noqa. The activity layer already forwarded params.previous_response_id. Adds a test asserting the id reaches Runner.run_streamed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 045b29e commit d01bc67

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

src/agentex/lib/core/services/adk/providers/openai.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ async def run_agent_streamed_auto_send(
678678
input_guardrails: list[InputGuardrail] | None = None,
679679
output_guardrails: list[OutputGuardrail] | None = None,
680680
max_turns: int | None = None,
681-
previous_response_id: str | None = None, # noqa: ARG002
681+
previous_response_id: str | None = None,
682682
created_at: datetime | None = None,
683683
) -> RunResultStreaming:
684684
"""
@@ -785,9 +785,23 @@ async def run_agent_streamed_auto_send(
785785

786786
agent = Agent(**agent_kwargs)
787787

788-
# Run with streaming
789-
if max_turns is not None:
788+
# Run with streaming. Forward previous_response_id so callers that
789+
# continue a Responses-API conversation resume the prior response
790+
# instead of silently starting a fresh one (mirrors the non-auto-send
791+
# run_agent_streamed path).
792+
if max_turns is not None and previous_response_id is not None:
793+
result = Runner.run_streamed(
794+
starting_agent=agent,
795+
input=input_list,
796+
max_turns=max_turns,
797+
previous_response_id=previous_response_id,
798+
)
799+
elif max_turns is not None:
790800
result = Runner.run_streamed(starting_agent=agent, input=input_list, max_turns=max_turns)
801+
elif previous_response_id is not None:
802+
result = Runner.run_streamed(
803+
starting_agent=agent, input=input_list, previous_response_id=previous_response_id
804+
)
791805
else:
792806
result = Runner.run_streamed(starting_agent=agent, input=input_list)
793807

tests/lib/adk/providers/test_openai_activities.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,43 @@ async def mock_stream_events():
354354
assert second.type == "tool_response"
355355
assert second.tool_call_id == "code_interpreter_call_123"
356356

357+
@patch("agents.Runner.run_streamed")
358+
async def test_run_agent_streamed_auto_send_forwards_previous_response_id(self, mock_runner_run_streamed):
359+
"""previous_response_id must reach Runner.run_streamed so a Responses-API
360+
conversation continues instead of silently starting fresh."""
361+
from agentex.lib.core.temporal.activities.adk.providers.openai_activities import (
362+
RunAgentStreamedAutoSendParams,
363+
)
364+
365+
mock_streaming_result = self._create_streaming_result_mock()
366+
367+
async def _no_events():
368+
return
369+
yield
370+
371+
mock_streaming_result.stream_events = _no_events
372+
mock_runner_run_streamed.return_value = mock_streaming_result
373+
374+
mock_tracer = self._create_mock_tracer()
375+
openai_service, openai_activities, env = self._create_test_setup(mock_tracer)
376+
self._setup_streaming_service_mocks(openai_service)
377+
378+
params = RunAgentStreamedAutoSendParams(
379+
input_list=[{"role": "user", "content": "continue"}],
380+
mcp_server_params=[],
381+
agent_name="test_agent",
382+
agent_instructions="You are a helpful assistant",
383+
trace_id="test-trace-id",
384+
parent_span_id="test-span-id",
385+
task_id="test-task-id",
386+
previous_response_id="response_123",
387+
)
388+
389+
await env.run(openai_activities.run_agent_streamed_auto_send, params)
390+
391+
mock_runner_run_streamed.assert_called_once()
392+
assert mock_runner_run_streamed.call_args.kwargs.get("previous_response_id") == "response_123"
393+
357394
def _create_mock_tracer(self):
358395
"""Helper method to create a properly mocked tracer with async context manager support."""
359396
mock_tracer = Mock()

0 commit comments

Comments
 (0)