Conditional Planning
Conditional planning adds branching logic to a plan. The agent follows different paths based on the results of previous steps.
8 min•By Priygop Team•Updated 2026
When to Use Conditional Plans
- When the next step depends on the outcome of the current step (success vs failure)
- When different input types require different handling (e.g., in-stock vs out-of-stock products)
- When the agent needs to escalate to a human under specific conditions
- When a fast path exists for common cases but a slow path handles edge cases
Conditional Plan Example
Conditional Plan Example
# Conditional planning for a refund workflow
def create_refund_plan(order_id: str, reason: str) -> dict:
"""
Create a conditional plan for processing a refund.
Different paths based on order age and amount.
"""
return {
"goal": f"Process refund for order {order_id}",
"steps": [
{
"id": "S1",
"action": "get_order",
"args": {"order_id": order_id},
"description": "Retrieve order details",
"next": "S2" # Always go to S2
},
{
"id": "S2",
"action": "check_refund_eligibility",
"args": {"order_id": order_id, "reason": reason},
"description": "Check if order qualifies for refund",
"conditions": {
"eligible_auto": "S3", # Small amount → auto-approve
"eligible_manual": "S4", # Large amount → human review
"not_eligible": "S5", # Not eligible → notify customer
}
},
{
"id": "S3",
"action": "issue_refund_auto",
"description": "Auto-approve refund (amount < $50)",
"next": "S6"
},
{
"id": "S4",
"action": "request_human_approval",
"description": "Request manager approval (amount ≥ $50)",
"next": "S3" # After approval, go to issue refund
},
{
"id": "S5",
"action": "send_rejection_email",
"description": "Inform customer of ineligibility",
"next": "END"
},
{
"id": "S6",
"action": "send_confirmation_email",
"description": "Confirm refund to customer",
"next": "END"
}
]
}
plan = create_refund_plan("ORD-123", "product damaged")
print("Conditional plan created")
print(f"Steps: {len(plan['steps'])}")
for step in plan['steps']:
print(f" {step['id']}: {step['description']}")Key Takeaways
- Conditional planning adds branching logic to a plan.
- When the next step depends on the outcome of the current step (success vs failure)
- When different input types require different handling (e.g., in-stock vs out-of-stock products)
- When the agent needs to escalate to a human under specific conditions