Skip to main content

clean_up_abandoned_turn

Function clean_up_abandoned_turn 

Source
async fn clean_up_abandoned_turn(
    pool: PgPool,
    conversation_id: Uuid,
    response_ids: Arc<Mutex<Vec<String>>>,
    response_message_id: Arc<Mutex<Option<Uuid>>>,
    full_response_text: Arc<Mutex<String>>,
)
Expand description

Cleans up after a turn the client abandoned mid-stream: answers the tool calls it left without an output, then deletes the response message if it never received any text, or saves the text it did receive as its (incomplete) answer.

The tool calls are answered first and whether or not there is a message: a call with no output makes the LLM reject every later message of the conversation, while a turn that died in a tool round created no message at all.

Unlike save_partial_answer, this decides whether there is anything to save.