Skip to main content

prepare_session_for_execution

Function prepare_session_for_execution 

Source
pub fn prepare_session_for_execution(
    session: &mut Session,
    system_prompt: Option<&str>,
    model: Option<&str>,
)
Expand description

Apply the authoritative pre-execution mutations to session.

This encodes the single, authoritative behavior that every execution entry point must share:

  • If system_prompt is Some, it is applied as the session’s leading System message. The supplied prompt is authoritative: if the first message is already a Role::System message it is replaced (never duplicated), otherwise a System message is inserted at index 0. This guarantees a caller-supplied session can’t silently shadow the configured instruction.
  • If model is Some, session.model is set to it.

Call sites that don’t supply one of these inputs (e.g. the spawn paths, whose caller already placed the system prompt) pass None for that parameter, so behavior is identical to the previous inline logic.