Orchestrate Multiple Models and Rules Engines
30-second answer
Don't send everything to the biggest model. A hybrid design tries rules first for answers code can decide exactly, a small language model for easy language work, and a large or reasoning model only for hard requests. A model router deployment can choose among models for you, or your own cascade can escalate when the small model is unsure. This lowers cost and latency, and you measure each route with evaluations and traces.
Simulate it » No Azure account neededExam objective: 2.3.4 Orchestrate multiple models, flows, or hybrid LLM and rules engines. (Skills measured as of April 16, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
Deploy a <strong>small</strong> model for easy work and a <strong>large</strong> one for hard work. Each gets its own deployment name and quota.
👆 Click the glowing item in the portal to continue
Read the steps as text
- Deploy a small model for easy work and a large one for hard work. Each gets its own deployment name and quota.
- A model router deployment picks a model for each prompt for you. It’s one option. Another is your own routing code.
- Rules first, then the small model, and the large model only when needed. Two of four requests used no model at all.
- Watch Monitoring and Tracing to confirm the router sends what you expect, and tune the rules if too much reaches the large model.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
Route requests to the right model
A hybrid design puts rules first for answers code can decide, a small model for easy language work and a large or reasoning model only when needed. A model router can pick for you. Fewer big-model calls means a lower bill and faster replies.
🤔 What happens if…
Read this tour as text
- Deploy a model, call the deployment. A deployment is a named copy of a model with a version, a deployment type and capacity. Your app calls the deployment name, never the model name. Pick a large model for hard work and a small language model for cheap, fast, simple work.
- RAG: retrieve first, then answer. Retrieval-augmented generation searches your own content (Azure AI Search, hybrid keyword plus vector), puts the best chunks in the prompt and asks the model to answer from them with citations. Without retrieval the model guesses.
- A multistep flow with checks. A workflow breaks one big request into steps you control: classify, extract to a JSON schema, call a tool, draft, then verify. Retries, fallbacks and a final check live in code, so one bad step can’t slip through unseen.
- Evaluate before you ship. Evaluators score each answer on a test set: groundedness (is it supported by the context?), relevance, coherence and safety checks. A fabrication shows up as a low groundedness score on one row, so you fix it before users see it.
- SDK, project endpoint and connections. The Foundry SDK (
azure-ai-projects) opens one door: AIProjectClient with the project endpoint and DefaultAzureCredential. From it your app gets an OpenAI-compatible client, deployments and connections (Azure AI Search, Application Insights) with no secrets in code. - Design the agent: role, goal, tool schema. An agent is a model plus instructions (role and goal), tools and a conversation (thread). A strict function schema names each parameter and marks the required ones, so the model asks the user instead of inventing a value.
- Retrieval, function calling and memory. One agent can use file search for documents, a function for live data and memory for what it learned about a user. The model asks to call a function; your code runs it and returns the result. Memory survives into a new conversation.
- Multi-agent orchestration. Several specialist agents can share a job. Sequential passes work down a line, concurrent fans out and merges, handoff moves control to the right specialist, group chat lets agents take turns in one shared conversation and Magentic lets a manager agent plan and delegate. Microsoft Agent Framework builds all five.
- Autonomy with approvals. Reads are safe, writes are not. A tool marked approval required pauses the run until a person decides. A hard limit in code blocks what no one should approve, whatever the model says.
- Monitor and debug agent runs. Agent evaluators read the whole run: intent resolution, tool call accuracy and task adherence. Error analysis groups the failing rows, such as a made-up tool argument, and points to the fix.
- Tune prompts and parameters. Instructions shape tone and rules, a few-shot example shows the format, temperature and top_p change how adventurous the wording is, and max output tokens caps length. A self-critique loop drafts, checks against a checklist and revises once.
- Trace every call and count tokens. OpenTelemetry spans record each agent run, model call and tool call, with tokens and latency, and Application Insights stores them. Tracing is opt-in, and recording message content is for development only because it captures prompts and answers.
- Route requests to the right model. A hybrid design puts rules first for answers code can decide, a small model for easy language work and a large or reasoning model only when needed. A model router can pick for you. Fewer big-model calls means a lower bill and faster replies.
Contoso handles warranty claim emails. Run a five-step flow with a tool and a verification, break the tool to see the fallback, then cut the bill by sending only the hard requests to the large model.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
Every request goes to the large model, including “what time do you open?”.
😊 THE SOLUTION
Answer with rules where code can decide, a small model for easy language work, and a large model only when needed.
- Exact answers✓ A rules engine
- Easy classification✓ A small model
- Hard reasoning✓ A large or reasoning model
Start with a question
Who answers the phone at a good hospital?
The receptionist answers “what are the visiting hours?” from a card on the desk. A nurse handles common questions. Only the hard cases go to a consultant, whose time is the most expensive.
A good AI system works the same way. Rules answer what a table can answer. A small model handles easy language work. The large model is the consultant, called only when needed.
Explain it like I’m 10
The technical explanation
Choose the cheapest thing that works
| Request | Handled by | Why |
|---|---|---|
| “What are your store hours?” | Rules (lookup table) | Exact, free, no model |
| “Refund ₹1,200 for ORD-1042” | Rules (policy limit in code) | The limit is a policy, so code decides |
| “Classify this review” | Small model (Phi-4-mini-instruct) | Simple, high volume |
| “Compare three warranty plans for a café” | Large or reasoning model (gpt-4.1, o4-mini) | Multi-part reasoning |
A cascade in code
def route(request: str) -> str:
if re.search(r"store hours|opening time", request, re.I): return "rules" # deterministic answer, no LLM
if re.search(r"refund", request, re.I): return "rules" # policy limit decided by code
if len(request) < 120: return os.environ.get("SMALL_DEPLOYMENT", "Phi-4-mini-instruct")
return os.environ.get("LARGE_DEPLOYMENT", "gpt-4.1") # long, multi-part reasoning
for req in REQUESTS:
target = route(req)
answer = RULES[req] if target == "rules" else openai.responses.create(model=target, input=req).output_text
Real systems often decide with more than length. They use a classifier, the small model’s own confidence, or the result of a first attempt, and escalate when the cheaper component isn’t sure.
Let a router choose
A model router is a Foundry deployment (preview as of 25 November 2026) that looks at each prompt and selects one of several underlying models, balancing quality and cost. You call it like any deployment, and the response says which model answered. Use it when you want routing without writing the logic, and check traces to confirm the mix is what you expect.
Combine models and tools in one flow
Routing also joins different kinds of components in one flow: Content Understanding extracts fields from an invoice, a small model classifies the vendor, a large model drafts a dispute letter, and rules check the totals. Each piece is the right size for its job.
Measure it
In the lab’s four-request example, one large model makes 4 model calls. The cascade makes 2, because rules answered two requests, so the relative cost falls to roughly a quarter. Compare quality, cost and latency per route with evaluations and traces, and watch the share of requests that reach the large model.
Architect level Guard the router too
If a user’s text decides which model runs, a user can try to steer it. Don’t let the request tell the router “use the biggest model”. Route on your own signals, cap the large-model calls per user, and trace routing decisions so a spike of expensive calls is easy to spot.
Real-world business scenario
Northwind Traders (fictional)
- The problem
- Every customer message went to the largest model, including store hours and refund limits. Replies were slow at peak and the bill kept growing.
- What they used
- A cascade: a rules table for store hours and the refund limit, Phi-4-mini-instruct for review labels, and gpt-4.1 only for long multi-part questions, with escalation when the small model is unsure.
- Why that choice
- Exact answers cost nothing, simple language work uses the small model, and the large model sees only the requests that need it.
- The result
- Half the requests needed no model call, average latency fell, and the model bill dropped by about three quarters with no drop in evaluation scores.
When to use it and when not to
✓ Use it when…
- Request difficulty varies a lot.
- Some answers are exact policy that code can decide.
- Volume is high enough that model size changes the bill.
✕ Think twice when…
- A single, uniform task. One model is simpler.
- You can't test each route. Untested routing hides quality loss.
- Routing based on text the user controls, with no limits.
↔ Alternatives to consider
- One well-chosen model when traffic is small.
- A model router for routing with no custom logic.
- A workflow when steps, not requests, differ.
Test yourself with exercises
5 original practice questions in the AI-103 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner Why not use the biggest model for everything?
Model answer
It's slower and costs more, and for simple questions it gives no better answer. A lookup table answers store hours perfectly for free.
Intermediate How does a cascade work?
Model answer
The request goes to rules first. If no rule fits, a small model tries. If it's unsure or the task is hard, the request goes to the large model. Each step is cheaper than the next, and most requests stop early.
Experienced developer What are the risks of routing?
Model answer
Misrouting a hard request to a weak model lowers quality, and routing logic is another thing to test. I evaluate each route on its own and the whole path together, set confidence thresholds for escalation, and watch traces for requests that bounce between models.
Scenario Reviews must be labelled at 100,000 an hour, but a few are sarcastic and confuse the small model. What do you do?
Model answer
I keep the small model for the volume, have it return a confidence or a label I can check, and escalate low-confidence reviews to a larger model. I measure how many escalate and whether accuracy improves.
Quick revision
Key points
- Rules first for exact answers.
- Small models for simple, high-volume language work.
- Large or reasoning models only when needed.
- Escalate when the cheaper component is unsure.
- Evaluate each route and the whole path.
Important terminology
- Hybrid design
- A system that combines a rules engine, small models and large models, each doing what it does best.
- Cascade
- Trying the cheapest component first and escalating to a stronger one only when needed.
- Model router
- A Foundry deployment that selects among underlying models for each prompt.
- Rules engine
- Plain code or tables that give exact, repeatable answers with no model call.
- Escalation
- Passing a request to a larger model or a person when the first attempt is unsure.
- Reasoning model
- A model that thinks through multistep problems before answering, at higher cost and latency.
Common mistakes
- Using a model for a lookup a table can answer.
- Routing with no fallback for low confidence.
- Never measuring how many requests reach the large model.
Exam tips
- "Fixed policy limit" = rules engine.
- "High-volume simple labelling" = small model.
- "Pick the model for each prompt automatically" = model router.
Five quick revision questions
-
1.What goes first in a cascade?Show
Rules.
-
2.Which model suits simple volume labelling?Show
A small language model.
-
3.What chooses a model per prompt?Show
A model router.
-
4.When do you escalate?Show
When the cheaper component is unsure.
-
5.What do you measure per route?Show
Quality, cost and latency.
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Generate and Edit Images
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.