Skip to main content

drive_loop_structured

Function drive_loop_structured 

Source
pub async fn drive_loop_structured(
    ctx: &mut RunCtx,
    agent: &Agent,
    input: &Value,
    schema: &Value,
) -> Result<LoopOutcome, RuntimeError>
Expand description

Runs the built-in agent loop under a declared output schema, returning a LoopOutcome::Completed whose value is the model’s structured answer (never a string of prose) or a park.

Same loop, same events, same caller contract as drive_loop: the difference is how the loop is allowed to end. The request offers ANSWER_TOOL beside the agent’s own tools with schema as its input schema and forces some tool call, and the loop ends only when that tool is called alone and its input satisfies schema under crate::validate_against_schema. See the module docs for what each other shape of turn feeds back.

§Errors

Everything drive_loop surfaces, plus RuntimeError::AnswerToolNameTaken when the agent already offers a real tool named ANSWER_TOOL. That one is checked before the first model call, so a refused drive records nothing.