feat(events): add SESSION_START and SESSION_END lifecycle events#47
Merged
Conversation
- Add SESSION_START event carries SessionManifest (topology, models, session managers) - Add SESSION_END event carries effective session_id - Add strands_compose.manifest - Add SessionManifest Pydantic models in types.py - wire_event_queue() builds manifest and emits SESSION_START - Test suite update - Docs update
- Implement _handle_session_start and _handle_session_end to show session lifecycle events in ANSI renderer - Remove not required flush from example 12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
External consumers of the event stream had no reliable way to know the topology of a session before agent activity started, and no typed signal that a session had cleanly ended.
This PR adds two session-level lifecycle events that bracket every invocation, giving consumers a deterministic start and end marker with rich metadata attached.
SESSION_START— first event on the queue, emitted synchronously before any agent runs. Carries aSessionManifestindata.SESSION_END— last typed event before the end-of-stream sentinel. Carries{"session_id": <str|null>}so consumers can finalise UI state deterministically without relying on the sentinel.strands_compose.manifestmodule with pure builder functionsbuild_manifest()andbuild_session_manager_descriptor().SessionManifestPydantic v2 models intypes.py:AgentDescriptor,OrchestrationDescriptor,EntryDescriptor,ModelDescriptor,NodeRef,EdgeRef,SessionManagerDescriptor.EventQueue.emit_session_start(manifest)— synchronous, guarded against double-emission.EventQueue.flush()resets bothSESSION_STARTandSESSION_ENDguards in addition to draining the queue.wire_event_queue()builds the manifest and emitsSESSION_STARTbefore returning.AnsiRendererupdated to handleSESSION_STARTandSESSION_ENDRelated Issues
N/A
Type of Change
YAML / API Impact
No YAML schema changes. All new Python API is additive:
make_event_queue()(entry_name,session_id) default toNone— existing callers are unaffected.wire_event_queue()behaviour is unchanged for single-turn use. Callers that reuse the queue across turns (e.g. multi-turn servers) must callflush()thenemit_session_start()explicitly after each flush to re-emitSESSION_STARTper turn.SessionManifest,AgentDescriptor,OrchestrationDescriptor,EntryDescriptor,ModelDescriptor,NodeRef,EdgeRef,FileProviderDescriptor,S3ProviderDescriptor,AgentCoreProviderDescriptor,CustomProviderDescriptor.Fully backwards-compatible.
Testing
How have you tested the change?
uv run just check(lint + type check)uv run just testfor overall testingexamples/still workChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.