Skip to main content

Module azure_chatbot

Module azure_chatbot 

Source
Expand description

Runs one chatbot turn against the Azure Responses API and streams it to the client as NDJSON.

A turn is everything the assistant does in answer to one learner message: as many rounds as the model needs, each round one request to Azure and the response it streams back, up to the answer that ends the turn. A turn is not one HTTP request โ€” one that calls a tool the client answers suspends, and a later request resumes it from the stored conversation.

turn, turn::round and turn::text_response hold one async_stream::try_stream! generator each, and the seams are between them, never inside one. A generator exits through break 'outer and return Err(e)?, which no extracted helper can carry across a function boundary, so anything lifted out of one has to be a pure function over values, an async fn that borrows the connection and returns a value, or another stream. azure::sse classifies a response as a plain async fn precisely because it yields nothing the turn cannot receive as a return value.

Modulesยง

azure
The wire side of the Azure Responses API: its request and response shapes, how a tool is advertised in a request, its SSE framing, and the HTTP call. Nothing here knows about conversations, what a tool does or the database.
client_tool_calls ๐Ÿ”’
Tool calls the client answers rather than the server: validating an answer that comes back, and closing out calls that never will be answered.
events
What the turn reports: the NDJSON events the client reads, and the events the parsers pass between themselves on the way there.
request ๐Ÿ”’
Building the request one turn sends: the conversation as Azure should replay it, plus the system prompt and the tools the caller may use.
search_grounding ๐Ÿ”’
Builds the system-prompt addendum appended when Azure Search is offered, grounding answers in retrieved course material and pointing the model at whichever other course-material tools this chatbotโ€™s configuration actually offers.
turn
The turn driver: keeps asking Azure while a round answers itself with tool calls, and ends on an answer, an error, a suspension, or the round budget.