Skip to content

Commit 144fb13

Browse files
authored
Merge pull request lightspeed-core#792 from tisnik/lcore-461-sequence-diagram-for-streaming-query-endpoint
LCORE-461: sequence diagram for streaming query endpoint
2 parents 552704c + 6f86812 commit 144fb13

3 files changed

Lines changed: 183 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ The service includes comprehensive user data collection capabilities for various
8080
* [REST API](#rest-api)
8181
* [Sequence diagrams](#sequence-diagrams)
8282
* [Query endpoint REST API handler](#query-endpoint-rest-api-handler)
83+
* [Streaming query endpoint REST API handler](#streaming-query-endpoint-rest-api-handler)
8384

8485
<!-- vim-markdown-toc -->
8586

@@ -900,3 +901,7 @@ For complete integration setup, deployment options, and configuration details, s
900901
### Query endpoint REST API handler
901902
902903
![Query endpoint](docs/query_endpoint.svg)
904+
905+
## Streaming query endpoint REST API handler
906+
907+
![Streaming query endpoint](docs/streaming_query_endpoint.svg)

docs/streaming_query_endpoint.puml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@startuml
2+
3+
participant Client
4+
participant Endpoint as "Streaming query endpoint handler"
5+
participant Auth
6+
participant LlamaStack as "Llama Stack Client"
7+
participant EventHandler as "Stream build event"
8+
participant SSE as "SSE Response Stream"
9+
10+
Client->>Endpoint: HTTP POST /stream_query
11+
Endpoint->>Auth: Validate auth, user, conversation access
12+
Auth-->>Endpoint: Access granted
13+
Endpoint->>LlamaStack: Call retrieve_response(model, query)
14+
LlamaStack-->>Endpoint: AsyncIterator[AgentTurnResponseStreamChunk]
15+
16+
Endpoint->>SSE: stream_start_event(conversation_id)
17+
SSE-->>Client: SSE: start
18+
19+
loop For each chunk from LlamaStack
20+
Endpoint->>EventHandler: stream_build_event(chunk, chunk_id, metadata)
21+
alt Chunk Type: turn_start
22+
EventHandler->>SSE: emit turn_start event
23+
else Chunk Type: inference
24+
EventHandler->>SSE: emit inference (token) event
25+
else Chunk Type: tool_execution
26+
EventHandler->>SSE: emit tool_call + tool_result events
27+
else Chunk Type: shield
28+
EventHandler->>SSE: emit shield validation event
29+
else Chunk Type: turn_complete
30+
EventHandler->>SSE: emit turn_complete event
31+
else Error
32+
EventHandler->>SSE: emit error event
33+
end
34+
SSE-->>Client: SSE event(s)
35+
end
36+
37+
Endpoint->>SSE: stream_end_event(metadata, summary, token_usage)
38+
SSE-->>Client: SSE: end (with metadata)
39+
40+
Endpoint->>Endpoint: Conditionally persist transcript & cache
41+
Endpoint-->>Client: Close stream
42+
43+
@enduml

0 commit comments

Comments
 (0)