WorkflowsFailure handling

Failure handling

Control how workflow steps behave when an agent step fails.

Workflows are useful because they define both success and failure paths.

Each step can choose what happens after success and what happens after failure.

Success transitions

Use OnSuccess(...) to move to another step:

Text
.Step<WeatherAgent>("weather")
    .OnSuccess("places")

Use OnSuccessEnd() to end the workflow after a successful step:

Text
.Step<ResponseWriterAgent>("response")
    .OnSuccessEnd()

If a step has no success target, the workflow ends after that step succeeds.

Failure behaviors

MethodBehavior
OnFailureStop()Stop the workflow and return failure.
OnFailureContinue("next")Continue to a specified next step.
OnFailureGoTo("fallback")Go to a fallback step.

The travel sample intentionally allows some specialist steps to fail without killing the whole workflow:

Text
.Step<WeatherAgent>("weather")
    .OnSuccess("places")
    .OnFailureContinue("places")
.Step<PlacesAgent>("places")
    .OnSuccess("planner")
    .OnFailureContinue("planner")
.Step<PlannerAgent>("planner")
    .OnFailureStop()

This makes sense because final planning can still produce a response with partial context. If the final planner fails, the workflow should stop.

Choosing failure behavior

Use OnFailureStop() when the step is required.

Use OnFailureContinue(...) when the next step can still work with partial context.

Use OnFailureGoTo(...) when you have a dedicated fallback agent, such as:

Text
policy-check -> response-writer
policy-check failure -> fallback-response

Failure handling is part of the product behavior. Define it intentionally rather than leaving every decision to a single agent.

On this page