From 4705d045793c436ba6f5f9b6b65c72b02b5cd5f8 Mon Sep 17 00:00:00 2001 From: Lokin Date: Mon, 15 Sep 2025 12:18:37 +0800 Subject: [PATCH 1/2] docs: add session parameter to manage conversation history --- src/agents/run.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/agents/run.py b/src/agents/run.py index 1027b2355..1b2b92938 100644 --- a/src/agents/run.py +++ b/src/agents/run.py @@ -383,6 +383,7 @@ def run_streamed( previous_response_id: The ID of the previous response, if using OpenAI models via the Responses API, this allows you to skip passing in input from the previous turn. conversation_id: The ID of the stored conversation, if any. + session: The Session to manage conversation history. Returns: A result object that contains data about the run, as well as a method to stream events. """ From 261c1fb41a5ef247b3abfc638385bc8e374a29bd Mon Sep 17 00:00:00 2001 From: Lokin Date: Mon, 15 Sep 2025 12:18:49 +0800 Subject: [PATCH 2/2] feat: add session parameter to run_demo_loop for conversation history management --- src/agents/repl.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/agents/repl.py b/src/agents/repl.py index 34222870c..caeae6cf2 100644 --- a/src/agents/repl.py +++ b/src/agents/repl.py @@ -4,6 +4,7 @@ from openai.types.responses.response_text_delta_event import ResponseTextDeltaEvent +from . import Session from .agent import Agent from .items import TResponseInputItem from .result import RunResultBase @@ -13,7 +14,7 @@ async def run_demo_loop( - agent: Agent[Any], *, stream: bool = True, context: TContext | None = None + agent: Agent[Any], *, stream: bool = True, context: TContext | None = None, session: Session | None = None ) -> None: """Run a simple REPL loop with the given agent. @@ -25,6 +26,7 @@ async def run_demo_loop( agent: The starting agent to run. stream: Whether to stream the agent output. context: Additional context information to pass to the runner. + session: The Session to manage conversation history. """ current_agent = agent @@ -44,7 +46,7 @@ async def run_demo_loop( result: RunResultBase if stream: - result = Runner.run_streamed(current_agent, input=input_items, context=context) + result = Runner.run_streamed(current_agent, input=input_items, context=context, session=session) async for event in result.stream_events(): if isinstance(event, RawResponsesStreamEvent): if isinstance(event.data, ResponseTextDeltaEvent):