Normandy.DSL.Workflow (normandy v0.2.0)

View Source

DSL for defining multi-agent workflows with a declarative syntax.

Provides macros to compose complex agent interactions in a readable, maintainable way.

Examples

defmodule ResearchWorkflow do
  use Normandy.DSL.Workflow

  workflow do
    # Sequential steps
    step :gather_sources do
      agent ResearchAgent
      input "Find sources about quantum computing"
    end

    step :analyze_sources do
      agent AnalysisAgent
      input from: :gather_sources
      transform fn sources -> "Analyze these: #{sources}" end
    end

    # Parallel execution
    parallel :validate do
      agent FactCheckAgent, name: :fact_check
      agent QualityAgent, name: :quality_check
      input from: :analyze_sources
    end

    # Conditional execution
    step :final_review do
      agent ReviewAgent
      input from: :validate
      when_result do
        {:ok, %{quality: q}} when q > 0.8 -> :approve
        {:ok, _} -> :needs_revision
      end
    end
  end
end

# Execute the workflow
{:ok, result} = ResearchWorkflow.execute(
  agents: %{
    ResearchAgent => research_agent,
    AnalysisAgent => analysis_agent
  },
  initial_input: "quantum computing"
)

Workflow Patterns

Sequential Steps

step :step1 do
  agent MyAgent
  input "some input"
end

step :step2 do
  agent AnotherAgent
  input from: :step1
end

Parallel Execution

parallel :check do
  agent Agent1, name: :check1
  agent Agent2, name: :check2
  input "same input for all"
end

Conditional Execution

step :process do
  agent MyAgent
  input from: :previous
  when_result do
    {:ok, value} when value > 10 -> :high
    {:ok, _} -> :low
  end
end

Race Pattern

race :fastest do
  agent FastAgent1, name: :fast1
  agent FastAgent2, name: :fast2
  input "Who can answer fastest?"
end

Features

  • Sequential, parallel, and race execution
  • Data flow between steps
  • Conditional execution
  • Result transformation
  • Error handling
  • Compile-time workflow validation

Summary

Functions

Specifies an agent for the current step.

Specifies the input for the current step.

Defines a parallel execution step.

Defines a race execution step.

Defines a sequential step in the workflow.

Transforms the input before passing to the agent.

Conditional execution based on result.

Defines a workflow block.

Functions

agent(module, opts \\ [])

(macro)

Specifies an agent for the current step.

Options

  • name: - Optional name for this agent in parallel/race steps

input(value)

(macro)

Specifies the input for the current step.

Can be:

  • A string literal
  • from: :step_name to use output from another step
  • A map

parallel(name, list)

(macro)

Defines a parallel execution step.

All agents run concurrently with the same input.

race(name, list)

(macro)

Defines a race execution step.

Returns the first successful result.

step(name, list)

(macro)

Defines a sequential step in the workflow.

Options

  • agent - Agent module or instance to use
  • input - Input for the agent (string, or from: :step_name)
  • transform - Function to transform input from previous step
  • when_result - Conditional execution block

transform(fun)

(macro)

Transforms the input before passing to the agent.

Examples

transform fn prev_output ->
  "Process this: #{prev_output}"
end

when_result(list)

(macro)

Conditional execution based on result.

Examples

when_result do
  {:ok, value} when value > 10 -> :continue
  {:ok, _} -> :stop
  {:error, _} -> :retry
end

workflow(list)

(macro)

Defines a workflow block.