WorkflowsDefining workflows

Defining workflows

Define deterministic agent workflows with Runiq's workflow DSL.

Define workflows as code and register them with AddRuniqWorkflows.

A workflow should describe a process your application owns. The travel sample uses weather, place research, and planning because those stages are easy to understand, but the same DSL is meant for product and enterprise flows where order, fallback, and auditability matter.

The travel planner sample keeps workflow definitions in a Workflows folder:

Text
Runiq.WorkflowTravelPlanner/
  Program.cs
  Agents/
    WeatherAgent.cs
    PlacesAgent.cs
    PlannerAgent.cs
  Tools/
    WeatherTool.cs
    PlacesTool.cs
    MealSuggestionTool.cs
  Workflows/
    TravelPlanningWorkflow.cs

Example workflow

C#
using Runiq.WorkflowTravelPlanner.Agents;
using Runiq.Workflows;

namespace Runiq.WorkflowTravelPlanner.Workflows;

public static class TravelPlanningWorkflow
{
    public static Workflow Create()
    {
        return new Workflow(
                id: "travel-planning-workflow",
                name: "Travel Planning Workflow")
            .Step<WeatherAgent>("weather")
                .OnSuccess("places")
                .OnFailureContinue("places")
            .Step<PlacesAgent>("places")
                .OnSuccess("planner")
                .OnFailureContinue("planner")
            .Step<PlannerAgent>("planner")
                .OnFailureStop()
            .Build();
    }
}

This workflow says:

  • Start with WeatherAgent.
  • If weather succeeds, run PlacesAgent.
  • If weather fails, continue to PlacesAgent anyway.
  • If places succeeds or fails, continue to PlannerAgent.
  • Stop if the planner fails.

The important design choice is that these transitions live in C#, not in a prompt. Developers can review them, test them, version them, and align them with existing business rules. Agents still produce reasoning-heavy outputs, but the application controls which step runs next.

Register agents and workflow

The workflow references agent types, so those agents must also be registered with Runiq.

C#
using Runiq.Core;
using Runiq.WorkflowTravelPlanner.Agents;
using Runiq.WorkflowTravelPlanner.Workflows;
using Runiq.Workflows;

var builder = WebApplication.CreateBuilder(args);

var openAiApiKey = builder.Configuration["OpenAI:ApiKey"];

builder.Services.AddRuniqServer(options =>
{
    options.AddAgent(WeatherAgent.Create(openAiApiKey));
    options.AddAgent(PlacesAgent.Create(openAiApiKey));
    options.AddAgent(PlannerAgent.Create(openAiApiKey));
});

builder.Services.AddRuniqWorkflows(options =>
{
    options.AddWorkflow(TravelPlanningWorkflow.Create());
});

The workflow runtime resolves each step by the registered agent instance's CLR type.

Workflow validation

Runiq validates workflow definitions before registration and execution.

Validation checks include:

  • workflow has at least one step,
  • duplicate step ids are not allowed,
  • success targets must point to known step ids,
  • failure targets must point to known step ids.

Keep step ids stable and readable:

Text
weather
places
planner
policy-check
response-writer

On this page