🔄
Multi-Step Workflows
Orchestrate complex multi-turn conversations with clear state management.
The Challenge
Multi-step workflows need different prompts for each stage. Managing state transitions and ensuring each step has the right context is error-prone when scattered across code.
The Solution
Define all workflow states in a single .prompt file. Each state gets its own instruction block, and the response contract tells your application what state comes next.
workflow.prompt
init do@version: 1.0@major: 1params:@workflow_state: enum[collect_info, analyze, generate, review]@user_input: str@collected_data: list[str]fragments:{system_prompt}: static from: workflows/systemend initcase @workflow_state docollect_info: # Step 1You are collecting information from the user.Ask clarifying questions to gather needed details.Focus on: `@collected_data`analyze: # Step 2You are analyzing the collected information.Review what has been gathered:{for data in @collected_data}- {data}{end for}Provide a summary and identify gaps.generate: # Step 3Based on the analysis, generate the requested output.Reference the collected data throughout.review: # Step 4Review the generated output for accuracy.Suggest improvements if needed.end @workflow_state@user_inputresponse do{"workflow_state": "@workflow_state","next_state": "...","data_needed": []}end response
Key Benefits
- Single file defines entire workflow
- State transitions are explicit in response contract
- Fragments compose common workflow elements