SaveMyCert
Log in
2 of 2 free questions left today·for 5 a day
Implement generative AI and agentic solutions

AI-103: Optimize and Operationalize Generative AI — Parameters, Reflection, Tracing and Model Routing

20 min readAI-103 · Implement generative AI and agentic solutionsUpdated

Optimizing and operationalizing a generative AI system means tuning how its models generate (prompts, sampling parameters, reasoning effort and verbosity), checking and improving their output (reflection loops and judge-based evaluation), watching it in production (tracing, token analytics, prompt caching, latency breakdowns and safety signals), and routing each request to the right model or rule. This lesson covers AI-103 task 2.3 at the implementation level: the parameter names, SDK calls, usage fields and design patterns behind each of those decisions in Microsoft Foundry.

What you’ll learn

  • Tune temperature or top_p on non-reasoning models, and choose the right parameters, output cap and message roles for reasoning models
  • Set reasoning effort and text verbosity independently, and size the output budget so reasoning tokens don't leave responses incomplete
  • Apply prompt engineering techniques — few-shot pairs, delimiters, repeated instructions, an out — and choose chain-of-thought prompting or a reasoning summary
  • Design bounded, grounded self-critique loops and evaluate outputs with built-in judges and code-, prompt- or endpoint-based custom evaluators
  • Set up server-side and client-side tracing, extend spans, and read token usage, cache hits and latency breakdowns
  • Log content-filter safety signals and protect recorded GenAI content in Application Insights
  • Orchestrate multiple models with model router, app-owned classifiers and cascades, and combine LLMs with deterministic rules

The 10 parts · about 16 min of reading

  1. How do temperature and top_p tune generation on non-reasoning models?Start hereLow temperature gives repeatable output and high gives variety; top_p trims the candidate pool, and you tune one of the two at a time.1 min
  2. Which parameters change on reasoning models?Reasoning models reject sampling parameters and max_tokens, rename the output cap per API, and spend hidden reasoning tokens from that cap.2 min
  3. How do reasoning effort and verbosity differ?Effort sets how much a model thinks and verbosity how long it answers; supported values and defaults differ between GPT-5 versions.1 min
  4. Which prompt engineering techniques improve output?Few-shot pairs, delimiters, repeated instructions and an explicit out shape output; chain-of-thought helps non-reasoning models only.2 min
  5. How do you implement reflection, self-critique loops and chain-of-thought evaluations?Critics need source evidence, bounded rounds and conditional revision; judge results carry a score, reason and configurable threshold.2 min
  6. How do you set up tracing in Foundry?A connected Application Insights traces agents with no code; client-side tracing needs the env var set before instrument() is called.2 min
  7. How do you analyze token usage and use prompt caching?Usage detail fields are subsets of their totals, reasoning bills as output, and caching needs an identical first 1,024 tokens.2 min
  8. How do you break down latency with traces?Nested invoke_agent, chat and execute_tool spans show which step takes the time, so you fix the slowest step first.1 min
  9. Which safety signals should observability capture?Content-filter results show blocked prompts, withheld completions and filter outages; a Protected AppGenAIContent table limits access.1 min
  10. How do you orchestrate multiple models, flows and rules engines?Model router picks a model per prompt by mode and subset; classifiers, cascades and rules engines keep routing under your control.2 min

Mind map

Low temperature = repeatable; high =variedtop_p=0.1 samples the top 10%probability massChange one of the two, not both1✓Temperature and top_pSampling params and max_tokens returnHTTP 400max_completion_tokens vsmax_output_tokensReasoning tokens count toward theoutput capReserve ~25,000 tokens while learninga workload2✓Reasoning modelparametersEffort = thinking depth; verbosity =answer lengthnone skips reasoning from gpt-5.1onwardgpt-5.1 defaults to none: set effortexplicitlyNever use the token cap as a lengthcontrol3✓Effort vs verbosityFew-shot pairs fix labels and formatDelimiters separate pasted contentRepeat key instructions at the endCoT for non-reasoning models only4✓Prompt engineeringGive the critic the source passagesBound rounds; return the best-scoreddraftVerify all, revise only the failuresResults carry score, reason andthreshold5✓Reflection and evaluationConnected App Insights traces agents,no codeViewing needs Log Analytics ReaderSet the tracing env var beforeinstrument()Span processor on_start tags everyspan6✓Tracing setupDetail fields are subsets of theirtotalsReasoning tokens bill at the outputrateCaching needs an identical first 1,024tokensStatic content first, dynamic contentlast7✓Token usage and cachinginvoke_agent holds chat andexecute_tool spansFix the slowest span firstStream and shorten long generationsTPM quota doesn't speed a singlerequest8✓Latency breakdownsHTTP 400 content_filter: promptblockedfinish_reason content_filter: outputwithheldcontent_filter_error: filter didn'trun, alertProtected AppGenAIContent table hidescontent9✓Safety signalsRouter modes: Balanced, Quality, CostModel subset fixes context-windowfailuresOwn classifier for fine-tuneddeploymentsRules engines make decisions auditable10✓Routing and rules enginesOptimize and operategenerative AI
Mind map

AI-103: Optimize and Operationalize Generative AI — Parameters, Reflection, Tracing and Model Routing

Low temperature = repeatable; high =variedtop_p=0.1 samples the top 10%probability massChange one of the two, not both1✓Temperature and top_pSampling params and max_tokens returnHTTP 400max_completion_tokens vsmax_output_tokensReasoning tokens count toward theoutput capReserve ~25,000 tokens while learninga workload2✓Reasoning modelparametersEffort = thinking depth; verbosity =answer lengthnone skips reasoning from gpt-5.1onwardgpt-5.1 defaults to none: set effortexplicitlyNever use the token cap as a lengthcontrol3✓Effort vs verbosityFew-shot pairs fix labels and formatDelimiters separate pasted contentRepeat key instructions at the endCoT for non-reasoning models only4✓Prompt engineeringGive the critic the source passagesBound rounds; return the best-scoreddraftVerify all, revise only the failuresResults carry score, reason andthreshold5✓Reflection and evaluationConnected App Insights traces agents,no codeViewing needs Log Analytics ReaderSet the tracing env var beforeinstrument()Span processor on_start tags everyspan6✓Tracing setupDetail fields are subsets of theirtotalsReasoning tokens bill at the outputrateCaching needs an identical first 1,024tokensStatic content first, dynamic contentlast7✓Token usage and cachinginvoke_agent holds chat andexecute_tool spansFix the slowest span firstStream and shorten long generationsTPM quota doesn't speed a singlerequest8✓Latency breakdownsHTTP 400 content_filter: promptblockedfinish_reason content_filter: outputwithheldcontent_filter_error: filter didn'trun, alertProtected AppGenAIContent table hidescontent9✓Safety signalsRouter modes: Balanced, Quality, CostModel subset fixes context-windowfailuresOwn classifier for fine-tuneddeploymentsRules engines make decisions auditable10✓Routing and rules enginesOptimize and operategenerative AI

How the exam tests this

Expect Microsoft-style scenarios: a company, a model deployment (gpt-4.1, o4-mini, a GPT-5 model or a model router), a symptom — output that varies run to run, an HTTP 400 after a model migration, an incomplete response with no text, cached_tokens stuck at 0, client spans that don't link to server spans, an answer that reached users unfiltered, a critic that approves everything — and a constraint such as minimal development effort, no code changes, keep automatic model selection, deterministic and auditable, or no extra requests. Several items hinge on exact names: which API uses max_completion_tokens versus max_output_tokens, which usage field holds cached or reasoning tokens, which effort values a given model accepts, and the order of tracing setup calls. Some show a short Python snippet. Select-TWO items usually need two independent changes, or two signals that each answer half of the requirement, so judge each option on its own.

Key takeaways

  1. Lower temperature for repeatable output, raise it for variety; top_p is the alternative control — change one of the two, not both.
  2. Reasoning models reject temperature, top_p, penalties and max_tokens; use max_completion_tokens on Chat Completions and max_output_tokens on the Responses API.
  3. Reasoning tokens are hidden, billed as output and count toward the output cap; a small cap can return an incomplete or empty response, so reserve about 25,000 tokens while learning a workload.
  4. Reasoning effort controls thinking depth and verbosity controls answer length; none (gpt-5.1+) is for latency-critical work, minimal is original GPT-5 only, and gpt-5.1 defaults to none.
  5. Chain-of-thought prompting is for non-reasoning models; for reasoning models request a reasoning summary — other ways of extracting reasoning are unsupported.
  6. Self-critique needs a grounded critic, explicit criteria, a round limit and, when failures are rare, revision only for outputs that fail a fast check.
  7. Built-in evaluators return score, reason, label and a threshold (default 3); code-based custom evaluators are deterministic but have no network, endpoint-based ones can call your services.
  8. Set AZURE_EXPERIMENTAL_ENABLE_GENAI_TRACING before instrument(), get OpenAI clients after it, and remember @trace_function always records parameters.
  9. Prompt caching is automatic from 1,024 tokens with an identical prefix: static content first, dynamic content last; cached_tokens and reasoning_tokens are subsets of their totals.
  10. Use model router for managed per-prompt selection (Balanced, Quality, Cost, subsets); use your own classifier, cascade or rules engine when routing must be auditable, reach custom deployments or be deterministic.
0/10
Ready to start

Part 1: How do temperature and top_p tune generation on non-reasoning models?

Low temperature gives repeatable output and high gives variety; top_p trims the candidate pool, and you tune one of the two at a time.

1 min read · 10 parts, about 16 min in allStart lesson

Frequently asked questions

Should I change temperature or top_p in Azure OpenAI?

Change one of them, not both. Temperature (0 to 2) and top_p both control randomness on non-reasoning models such as gpt-4.1: lower values give focused, repeatable output and higher values give varied output. Microsoft recommends adjusting one and leaving the other at its default so the effect of each change can be measured. Reasoning models such as o4-mini and the GPT-5 family don't support either parameter.

Why does a reasoning model return an empty or incomplete response?

Its hidden reasoning tokens used up the output budget. Reasoning tokens count toward max_output_tokens (Responses API) or max_completion_tokens (Chat Completions) together with the visible answer, and they are billed as output tokens. When reasoning fills the cap, the Responses API returns status incomplete with reason max_output_tokens and Chat Completions returns empty content with finish_reason length. Raise the cap, and control answer length with verbosity or instructions instead.

What is the difference between reasoning effort and verbosity?

Reasoning effort sets how much a GPT-5 or o-series model thinks before answering, which affects accuracy, latency and reasoning-token cost. Verbosity (low, medium or high — text.verbosity in the Responses API, verbosity in Chat Completions) sets how long the visible answer is. They are independent, so you can combine high effort for accuracy with low verbosity for short answers.

Sign up free to mark lessons complete, bookmark topics and track your exam readiness.

Spotted a mistake in this lesson?