Agentic Architectures at Scale · 2 of 5
Orchestration, State, and Control Flow
How software decides what happens next, remembers what matters, and keeps complex work from becoming accidental chaos.
Every useful system does more than run one instruction. It receives a request, gathers facts, calls tools, waits for replies, handles surprises, and eventually produces an outcome. Orchestration is the discipline of arranging those steps so the right work happens in the right order. State is the memory that lets the system know where it is. Control flow is the logic that decides what happens next. Together, they turn scattered actions into a dependable process.
Start with the simplest possible job
Imagine a service that receives a customer question, looks up an order, checks a policy, and sends an answer. None of those steps is hard by itself. The difficulty is in coordinating them. The system must know which step has already run, what data came back, what failed, and whether it is safe to continue.
Orchestration is the layer that manages that coordination. It does not necessarily do the work itself. Instead, it assigns work to components such as databases, application programming interfaces (APIs), large language models (LLMs), queues, or human reviewers. A good orchestrator is like a calm dispatcher: it knows the plan, tracks progress, and reacts when reality differs from the plan.
This idea applies equally to traditional software, artificial intelligence (AI) applications, business workflows, and data pipelines. The tools change, but the questions remain the same: What should happen first? What depends on what? What must be remembered? What should happen if something goes wrong?
Orchestration is not the same as execution
A worker performs a task. An orchestrator decides when that worker should be used, with which inputs, under which rules, and what should happen after it finishes. This separation matters because complex systems need both specialization and coordination.
For example, a payment service may know how to charge a card, but it should not also decide the whole order process. The order process may need inventory checks, fraud review, tax calculation, shipping selection, and notifications. The orchestrator holds that larger shape while each worker stays focused on its own responsibility.
In AI applications, the distinction becomes especially important. An LLM can generate text or choose among options, but the surrounding application still needs to control permissions, tool calls, approvals, retries, logging, and handoff to other systems. Microsoft Foundry can help teams build and manage AI applications, but the design question remains: which parts should be model behavior, and which parts should be explicit orchestration?
- Use workers for bounded tasks with clear inputs and outputs.
- Use orchestration for sequencing, policy, branching, and recovery.
- Keep business rules visible rather than hiding them inside prompts or scattered code.
- Treat AI model output as one input to a decision, not as the whole control system.
State is the system's memory of the work
State is any information the system keeps so it can continue correctly. It may be as small as a status flag or as rich as a full record of a conversation, selected tools, retrieved documents, approvals, and prior decisions.
There are different kinds of state. Some state is short-lived, such as a value held in memory while one request is processed. Some is durable, meaning it is written somewhere reliable so the work can resume after a restart. Some is business state, such as an order being approved. Some is technical state, such as a retry count or checkpoint.
State is powerful because it gives continuity. It is also risky because old, wrong, or incomplete state can drive wrong behavior. The central design question is not whether to keep state, but which state deserves to be kept, where it should live, who may read it, who may change it, and when it should expire.
Control flow is how the system chooses the next move
Control flow is the pattern of decisions that moves work from one step to another. The simplest control flow is a straight line: do A, then B, then C. Real systems need more. They branch when conditions differ, loop when work must repeat, wait when an outside event is needed, and stop when a rule says the work should not continue.
Control flow should be explicit enough that engineers can reason about it and operators can inspect it. Hidden control flow is a common source of incidents. If a process can silently retry forever, skip approval, or call a tool based on a vague instruction, it becomes hard to predict and hard to govern.
In AI systems, control flow may combine deterministic rules with probabilistic model output. Deterministic means the same input and rules produce the same result. Probabilistic means the output may vary. A healthy design often uses models for judgment or language, while keeping high-risk control flow in visible code, policies, or workflow definitions.
Reliability comes from planning for partial failure
Distributed systems rarely fail neatly. A tool may finish the work but fail to send confirmation. A network call may time out even though the remote service later completes the request. A model may return an invalid format. A human reviewer may take hours. Orchestration must assume that progress and evidence can disagree.
Retries are useful, but they are not a complete answer. If a step charges a customer, sends an email, or ships a package, repeating it blindly may cause harm. The safer pattern is idempotency, which means an operation can be requested more than once without changing the outcome beyond the first successful attempt.
Some workflows also need compensation. Compensation is a follow-up action that repairs or balances a prior action when the whole process cannot finish. Refunding a payment after a shipment fails is compensation. It is not the same as undoing time; it is a designed recovery path.
- Set timeouts so work does not wait forever.
- Use idempotency keys for operations that may be retried.
- Record checkpoints after meaningful progress.
- Separate temporary failures from business rejections.
- Design compensation for steps that cannot be cleanly undone.
Security and governance are part of the flow
Orchestration is also a security boundary. The component that decides what happens next often decides which tools may be called, which data may be read, and which actions require approval. That makes it a natural place to enforce identity, authorization, audit logging, and policy.
Identity answers who or what is acting. Authorization answers what that actor is allowed to do. In Microsoft environments, Microsoft Entra ID is commonly used to manage identities and access. The orchestrator should preserve that context rather than flattening all actions into one overpowered service account.
For AI applications, tool access deserves special care. If an assistant can use Foundry Tools or call business APIs, the system should constrain those calls by role, data classification, environment, and user intent. A model should not receive broad authority merely because it can produce a plausible instruction.
The real design decisions
Leaders and practitioners usually do not fail because they lack an orchestration tool. They fail because they choose the wrong boundary for coordination. Too much orchestration in one place creates a central bottleneck. Too little creates a maze of services that each know only part of the truth.
A useful first decision is whether the process is long-running or short-running. Short-running work can often stay inside one application request. Long-running work needs durable state, checkpoints, and a way to resume after delays. A second decision is whether the process is predictable or exploratory. Predictable processes fit explicit workflows. Exploratory processes may need agent-like planning, but still require guardrails and stopping rules.
Cost and accountability also matter. Every extra branch, model call, tool call, and stored record adds operational cost and review burden. The best orchestration is not the most elaborate; it is the simplest design that can explain what happened, recover when something breaks, and enforce the rules that matter.
- Who owns the end-to-end outcome when several systems contribute?
- Which decisions must be deterministic and auditable?
- Which state is temporary context, and which is a durable business record?
- Where should humans approve, override, or stop the flow?
- What evidence is needed to explain the result after the fact?
A practical starting pattern
A good beginner pattern is a small, explicit workflow with durable checkpoints. Start by naming the goal, the steps, the state each step needs, the state each step produces, and the conditions that end the process. Then add failure handling only where it is needed, rather than trying to solve every possible exception at once.
Keep the orchestration readable. A new engineer should be able to answer four questions quickly: where is the work now, why is it there, what can happen next, and who is allowed to make that happen. If those answers require searching through prompts, logs, queues, and hidden callbacks, the design needs simplification.
As the system grows, treat orchestration as architecture, not plumbing. It is where user intent, business rules, technical failure, security, and accountability meet. Done well, it fades into the background because the work simply proceeds. Done poorly, it becomes the place where every ambiguity in the system gathers.
Key takeaways
- Orchestration coordinates work; workers perform the individual tasks.
- State is the remembered information that lets a process continue correctly.
- Control flow defines branches, loops, waits, stops, and recovery paths.
- Reliable orchestration plans for partial failure, not just total success or total failure.
- Security belongs inside the flow, especially when tools and AI models can take action.
- The best design is the simplest one that can recover, explain itself, and enforce the rules.
Glossary
- Orchestration
- The coordination layer that decides when steps run, what inputs they receive, and what happens after each result.
- State
- Information a system keeps so it can understand progress, context, decisions, or history.
- Control flow
- The decision logic that determines which step runs next, including branches, loops, waits, and stops.
- Worker
- A component that performs a bounded task for an orchestrator, such as calling an API or updating a record.
- Checkpoint
- A saved record of progress that allows a process to resume from a known point after delay or failure.
- Idempotency
- The property of an operation that lets it be requested multiple times without causing duplicate effects.
- Compensation
- A designed follow-up action that balances or repairs a prior step when a larger process cannot complete.
- Authorization
- The decision about what an identified user, service, or system is allowed to do.