Build a sequential workflow
Use a workflow when you know which steps should run and in what order. Your application calls each agent, passes its result to the next step, and decides how to handle failures. Each agent can have its own instructions, model, and tools.
For a short sequence, ordinary function calls are enough:
Define a Graph when you need dependencies across parallel
branches or conditional edges. Use the
vended graph tool when an agent should
construct the graph.
Define a Graph when you need dependencies across parallel
branches or conditional edges. Use the
vended graph tool when an agent should
construct the graph.
Graph orchestration is not available. Keep the control flow in your application.
Pass results from one agent to the next
Section titled “Pass results from one agent to the next”This workflow extracts facts from incident notes, analyzes those facts, and writes a report. The agents receive the information they need through their prompts; your code fixes the order of the calls.
Before running the example, install the SDK and configure a model provider as shown in the quickstart.
from strands import Agent
def process_workflow(notes: str) -> str: researcher = Agent( system_prompt="Extract the facts in the supplied incident notes.", callback_handler=None, ) analyst = Agent( system_prompt="Analyze the supplied facts. Distinguish causes from guesses.", callback_handler=None, ) writer = Agent( system_prompt="Write a concise incident report from the supplied analysis.", callback_handler=None, )
facts = researcher(f"Extract facts from these notes:\n{notes}") analysis = analyst(f"Analyze these incident facts:\n{facts}") report = writer(f"Write a report from this analysis:\n{analysis}") return str(report)
# Fictional notes keep the example independent of external data sources.notes = ( "09:00: deployed version 2.3. 09:05: checkout errors increased. " "09:12: rolled back to version 2.2. 09:15: error rate returned to normal. " "Root cause has not been confirmed.")print(process_workflow(notes))import { Agent } from '@strands-agents/sdk'
async function processWorkflow(notes: string): Promise<string> { const researcher = new Agent({ systemPrompt: 'Extract the facts in the supplied incident notes.', printer: false, }) const analyst = new Agent({ systemPrompt: 'Analyze the supplied facts. Distinguish causes from guesses.', printer: false, }) const writer = new Agent({ systemPrompt: 'Write a concise incident report from the supplied analysis.', printer: false, })
const facts = await researcher.invoke(`Extract facts from these notes:\n${notes}`) const analysis = await analyst.invoke(`Analyze these incident facts:\n${facts}`) const report = await writer.invoke(`Write a report from this analysis:\n${analysis}`) return report.toString()}
// Fictional notes keep the example independent of external data sources.const notes = '09:00: deployed version 2.3. 09:05: checkout errors increased. ' + '09:12: rolled back to version 2.2. 09:15: error rate returned to normal. ' + 'Root cause has not been confirmed.'console.log(await processWorkflow(notes))cargo add tokio --features macros,rt-multi-threaduse strands::Agent;
async fn process_workflow(notes: &str) -> strands::Result<String> { let mut researcher = Agent::builder() .system_prompt("Extract the facts in the supplied incident notes.") .printer(false) .build()?; let mut analyst = Agent::builder() .system_prompt("Analyze the supplied facts. Distinguish causes from guesses.") .printer(false) .build()?; let mut writer = Agent::builder() .system_prompt("Write a concise incident report from the supplied analysis.") .printer(false) .build()?;
let facts = researcher .invoke(format!("Extract facts from these notes:\n{notes}")) .await?; let analysis = analyst .invoke(format!("Analyze these incident facts:\n{facts}")) .await?; let report = writer .invoke(format!("Write a report from this analysis:\n{analysis}")) .await?;
researcher.shutdown().await?; analyst.shutdown().await?; writer.shutdown().await?; Ok(report.to_string())}
#[tokio::main]async fn main() -> strands::Result<()> { let notes = "09:00: deployed version 2.3. 09:05: checkout errors increased. \09:12: rolled back to version 2.2. 09:15: error rate returned to normal. \Root cause has not been confirmed.";
println!("{}", process_workflow(notes).await?); Ok(())}The researcher finishes before the analyst starts, and the analyst finishes before the writer starts. The report’s wording varies with the model; the order and inputs come from your application code. Creating the agents inside the function gives each run a fresh conversation.
Decide what happens when a step fails
Section titled “Decide what happens when a step fails”If an agent call raises an error in this example, the function exits and later steps do not run. Catch errors around a step when your application should retry it, ask for input, or return a partial result. Check the returned content before continuing when a successful call can still produce an unsuitable answer.
A sequence of function calls does not add workflow persistence, a shared run status, or an overall deadline. Implement the controls your application needs.
You can instead use a Graph and its orchestration APIs. The supervised orchestrator example shows node timeouts, an approval gate, and cancellation, including the limits of timeout enforcement.
You can instead use a Graph and its orchestration APIs. The supervised orchestrator example shows node timeouts, an approval gate, and cancellation, including the limits of timeout enforcement.
Keep persistence, deadlines, and failure handling in the application workflow.
Let an agent construct the workflow
Section titled “Let an agent construct the workflow”Use the vended graph tool when the agent should decide how to divide a request
into subtasks. The model supplies nodes and dependency edges; the tool creates
the agents, runs independent nodes in parallel, and passes upstream outputs to
downstream nodes.
Use the vended graph tool when the agent should decide how to divide a request
into subtasks. The model supplies nodes and dependency edges; the tool creates
the agents, runs independent nodes in parallel, and passes upstream outputs to
downstream nodes.
The vended graph tool is not available. Keep dynamic workflow construction in
application code.
The tool accepts acyclic graphs. Configure it to constrain the graph’s size and the instructions, models, and tools available to its nodes. For a fixed sequence like the example above, keep the calls in your application. For cycles or conditional edges that your application defines, use the Graph SDK API.