Patrones

Patrón: Workflows multi-turno con variable de paso

Secuencias largas donde cada respuesta decide el siguiente paso.

Fuente: patterns/ascript-patterns-multi-turn.md

Úsalo cuando el agente deba hacer una secuencia larga de preguntas obligatorias, validar cada respuesta y decidir la siguiente en función de la anterior, pudiendo pasar varios turnos dentro del mismo subagente.

Step-Based Agent Router
start_agent agent_router:
    description: "Welcome the user and determine the appropriate subagent based on user input"

    reasoning:
        instructions: ->
            if @variables.currentInterviewStep == "Permission":
                transition to @subagent.permission
            if @variables.currentInterviewStep == "Eligibility":
                transition to @subagent.eligibility
            if @variables.currentInterviewStep == "End":
                transition to @subagent.end_interview

subagent permission:
    description: "Confirm the candidate has the legal right to work in Wonderland."

    reasoning:
        instructions: ->
            | Confirm whether the candidate has the legal right to work in Wonderland.
              If the candidate is eligible, call {!@actions.setCurrentInterviewStep} with currentInterviewStep set to "Eligibility".
              If the candidate is NOT eligible, call {!@actions.setCurrentInterviewStep} with currentInterviewStep set to "End".

        actions:
            setCurrentInterviewStep: @utils.setVariables
                description: "Set the CurrentInterviewStep variable"
                with currentInterviewStep = ...
  • Una responsabilidad por subagente: valida una respuesta y pasa al siguiente paso.
  • Nombres de paso explícitos: permission, eligibility, availability.
  • Deja que cada subagente decida cuándo la respuesta es satisfactoria.
Temas relacionados