# yaml-language-server: $schema=../automation-document.schema.json
# Outcomes: the Writer drafts, a model scores the draft against the rubric, and a
# failing score sends the draft and the reason back to the Writer, up to 3 times.
# The webhook request carries the goal and the rubric. Fill the ids with --var:
#   checkfu automations create -f outcomes.yaml --var RUNS_AS=prin_… --var WRITER_AGENT=agent_… \
#     --var ENVIRONMENT=env_…
# Delete the environment_id line when the Workspace has exactly one Environment.
name: Draft until it meets the rubric
runs_as: "${RUNS_AS}"
environment_id: "${ENVIRONMENT}"
blocks:
  - id: request
    type: trigger
    trigger: { type: webhook, dedupe_pointer: /id }
  - id: draft
    type: agent
    agent: "${WRITER_AGENT}"
    prompt: |
      {{request.goal}}
      Your previous draft (empty on the first try): {{draft.output}}
      Reviewer feedback (empty on the first try): {{grade.reason}}
  - id: grade
    type: model
    route: { profile: fast-judge }
    prompt: "Score this draft against the rubric. Rubric: {{request.rubric}} Draft: {{draft.output}}"
    format: { type: score, levels: 10, pass_at: 8 }
wires:
  - { from: request, to: draft }
  - { from: draft, to: grade }
  - { from: grade, port: fail, to: draft, max_attempts: 3 }
