@@ -106,13 +106,35 @@ async def append_event(self, session: Session, event: Event) -> Event:
106106 """Appends an event to a session object."""
107107 if event .partial :
108108 return event
109+ # Apply temp-scoped state to the in-memory session BEFORE trimming the
110+ # event delta, so that subsequent agents within the same invocation can
111+ # read temp values (e.g. output_key='temp:my_key' in SequentialAgent).
112+ self ._apply_temp_state (session , event )
109113 event = self ._trim_temp_delta_state (event )
110114 self ._update_session_state (session , event )
111115 session .events .append (event )
112116 return event
113117
118+ def _apply_temp_state (self , session : Session , event : Event ) -> None :
119+ """Applies temp-scoped state delta to the in-memory session state.
120+
121+ Temp state is ephemeral: it lives in the session's in-memory state for
122+ the duration of the current invocation but is NOT persisted to storage
123+ (the event delta is trimmed separately by _trim_temp_delta_state).
124+ """
125+ if not event .actions or not event .actions .state_delta :
126+ return
127+ for key , value in event .actions .state_delta .items ():
128+ if key .startswith (State .TEMP_PREFIX ):
129+ session .state [key ] = value
130+
114131 def _trim_temp_delta_state (self , event : Event ) -> Event :
115- """Removes temporary state delta keys from the event."""
132+ """Removes temporary state delta keys from the event.
133+
134+ This prevents temp-scoped state from being persisted, while the
135+ in-memory session state (updated by _apply_temp_state) retains the
136+ values for the duration of the current invocation.
137+ """
116138 if not event .actions or not event .actions .state_delta :
117139 return event
118140
@@ -128,6 +150,4 @@ def _update_session_state(self, session: Session, event: Event) -> None:
128150 if not event .actions or not event .actions .state_delta :
129151 return
130152 for key , value in event .actions .state_delta .items ():
131- if key .startswith (State .TEMP_PREFIX ):
132- continue
133153 session .state .update ({key : value })
0 commit comments