-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Is your feature request related to a problem? Please describe.
When building applications that need to explore multiple conversation paths from a single point, there's no way to create a copy of an existing session without modifying the original.
The current rewind_async() API modifies the original session's state and artifacts, making it impossible to:
- Preserve the original conversation while exploring alternative paths
- Create "what-if" branches from a conversation midpoint
- Allow users to fork a conversation and continue in different directions
Example scenario: A user is at turn 5 of a conversation and wants to try a different approach from turn 3, but also keep the original turn 3→5 history intact. Currently this is not possible.
Describe the solution you'd like
Add a fork_session() or clone_session() API that creates a new independent session by copying events, state, and artifact references up to a specified invocation point.
# Option A: In SessionService
new_session = await session_service.fork_session(
app_name=app_name,
user_id=user_id,
source_session_id=original_session.id,
fork_before_invocation_id="inv_3", # Fork point
)
# Option B: In Runner (similar to rewind_async)
new_session = await runner.fork_async(
user_id=user_id,
session_id=session_id,
fork_before_invocation_id="inv_3",
)The original session remains completely unchanged.
Describe alternatives you've considered
-
Rewind then copy: Doesn't work because
rewind_async()modifies the original session's state and artifacts before any copy could be made. -
Manual event copying: Requires manually iterating events, recomputing state deltas, and handling artifact references. Error-prone and not officially supported.
-
External backup before rewind: Outside ADK's scope, doesn't integrate with artifact versioning, and requires users to implement their own session serialization.
Additional context
- Related existing feature:
rewind_async()inrunners.py:509-647- similar pattern could be followed - Use cases: conversation branching UI, A/B testing agent responses, debugging/development snapshots
- I'm willing to contribute this feature if the design is approved