Designing Workflows and Tool-Augmented Flows
This lesson explains how to design workflows, which break a task into focused steps, and tool-augmented flows, which use function calling to bring in live data or actions.
Learning outcomes
After completing this lesson, you will be able to:
- Decompose a task into workflow steps.
- Implement function calling with function definitions.
- Choose an orchestration option for a flow.
Designing a workflow
A workflow decomposes a task into steps with clear inputs and outputs. For example, an email response workflow might classify the email, extract the order number, look up the order, retrieve relevant policy, draft a reply, check the draft against policy and route it for approval if a refund is involved. Deterministic steps (lookups, validation, calculations, routing rules) are ordinary code; language steps use model calls with focused prompts, often on smaller models. Each step's output is validated before the next step, which makes failures visible and easy to trace.
Code or model step?
Function calling
A model can only produce text; it cannot look up an order or query a database by itself. Function calling is the mechanism that bridges this gap: the application describes the functions it is willing to run, and the model, instead of answering directly, can reply with a structured request to call one of them with specific arguments. A flow built this way is called a tool-augmented flow.
In a tool-augmented flow, the model decides when it needs a tool. The request includes function definitions with a name, description and JSON Schema parameters. If the model decides to call one, the response contains a function_call item with the name, arguments and a call ID. The application validates the arguments, runs the function and sends the result back as a function_call_output item with the same call ID; the model then continues, possibly calling more tools, until it produces a final answer.
The important point is that the model never runs the function itself; it only proposes a call. The application decides whether to execute it, which is where security and business rules belong. Arguments come from model output and may have been influenced by the user or by retrieved content, so the application treats them as untrusted input: it checks that the signed-in user may act on the requested order, validates formats and ranges, and refuses calls that break policy, returning an explanatory error as the function output so that the model can respond sensibly. A clear function description matters as much as the schema, because the model uses the description to decide when the tool applies.
import json
tools = [{
"type": "function", "name": "get_order_status",
"description": "Get the shipping status of an order by its order number.",
"parameters": {"type": "object",
"properties": {"order_number": {"type": "string", "pattern": "^ORD-[0-9]{6}$"}},
"required": ["order_number"], "additionalProperties": False},
"strict": True,
}]
r = openai.responses.create(model="chat-primary", input=question, tools=tools)
for item in r.output:
if item.type == "function_call":
result = get_order_status(**json.loads(item.arguments)) # your code runs the tool
r = openai.responses.create(
model="chat-primary", previous_response_id=r.id, tools=tools,
input=[{"type": "function_call_output", "call_id": item.call_id, "output": json.dumps(result)}],
)
print(r.output_text)Orchestration options
Orchestration is the logic that runs the steps of a workflow in the right order: it passes each step's output to the next step, evaluates conditions, repeats steps in loops, handles errors and pauses for human input where needed. There are three ways to provide it.
Simple flows are orchestrated in application code, with ordinary function calls and conditions.
Foundry workflows orchestrate agents and steps declaratively, with a visual designer and YAML definitions that include conditions, loops, variables and human-in-the-loop nodes.
The Microsoft Agent Framework provides graph-based workflows in Python and .NET with typed messages, checkpointing and support for long-running processes. The choice depends on whether the team wants low-code visibility, full control in code, or both.
Each option suits a different situation. A flow of three or four steps inside one service, such as classify, retrieve and answer, is easiest to write and test as ordinary application code. A process that business analysts must be able to read and change, or that pauses for a manager's approval, suits a Foundry workflow, because its steps, conditions and approval nodes are visible in the designer and run in the agent service. A complex process that must survive restarts, run for hours or days and coordinate several agents with typed messages suits the Agent Framework, whose checkpointing saves the workflow's state so that it can resume where it stopped.
The Foundry portal shows that Foundry workflows are being retired on 1 December 2026, and new workflows are built with the Microsoft Agent Framework. The exam guide may still name Foundry workflows, so the concepts in this section remain worth knowing, but new solutions use the Agent Framework for declarative and code-based orchestration.
Choose the orchestration
One prompt or a workflow
A single prompt classifies insurance claims, extracts amounts, applies coverage rules and writes a decision letter. It makes frequent errors in the coverage calculation, and auditors cannot see why decisions were made.
Split the task: a model step extracts structured fields; a code step applies coverage rules deterministically and records which rule applied; a model step writes the letter from the decision; and a check step compares the letter with the decision. Increasing the model size might reduce errors but would not make decisions auditable.
In function calling, who runs the function?
Show answer
Your code. The model returns a function_call; the application runs it and sends back a function_call_output with the same call ID.
Exam Tips
Remember for the exam
- Deterministic logic in code, language tasks in focused model steps.
- Function calling: the model returns function_call; your code runs it and returns function_call_output with the call ID.
- Strict schemas with patterns and enums reduce malformed tool arguments.