Normandy.DSL.Workflow (normandy v0.2.0)
View SourceDSL 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
endParallel Execution
parallel :check do
agent Agent1, name: :check1
agent Agent2, name: :check2
input "same input for all"
endConditional Execution
step :process do
agent MyAgent
input from: :previous
when_result do
{:ok, value} when value > 10 -> :high
{:ok, _} -> :low
end
endRace Pattern
race :fastest do
agent FastAgent1, name: :fast1
agent FastAgent2, name: :fast2
input "Who can answer fastest?"
endFeatures
- 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
Specifies an agent for the current step.
Options
name:- Optional name for this agent in parallel/race steps
Specifies the input for the current step.
Can be:
- A string literal
from: :step_nameto use output from another step- A map
Defines a parallel execution step.
All agents run concurrently with the same input.
Defines a race execution step.
Returns the first successful result.
Defines a sequential step in the workflow.
Options
agent- Agent module or instance to useinput- Input for the agent (string, orfrom: :step_name)transform- Function to transform input from previous stepwhen_result- Conditional execution block
Transforms the input before passing to the agent.
Examples
transform fn prev_output ->
"Process this: #{prev_output}"
end
Conditional execution based on result.
Examples
when_result do
{:ok, value} when value > 10 -> :continue
{:ok, _} -> :stop
{:error, _} -> :retry
end
Defines a workflow block.