Agent Optimizer in Foundry — Scaffold Python Agent
Prepare an existing Python hosted agent for Agent Optimizer in Foundry, then run optimization, apply the selected candidate locally, and deploy through azd after review.
When to Use This Skill
USE FOR: make my Python agent optimizable with Agent Optimizer in Foundry, scaffold optimizer config, add load_config, prepare .agent_configs, configure eval.yaml, run azd ai agent optimize, apply optimizer candidate, deploy optimized agent.
DO NOT USE FOR: non-Python agents, prompt agents, running standalone batch evaluations, prompt optimization of an already deployed agent, or general Foundry deployment. For normal deployment, use deploy. For eval analysis loops, use observe.
Quick Reference
| Property | Value |
|---|---|
| Phase | Scaffold, optimize, apply locally, deploy |
| Supported language | Python |
| Required runtime | azd project with hosted agent |
| Required package | azure-ai-agentserver-optimization |
| Required import | from azure.ai.agentserver.optimization import load_config |
| Required baseline | .agent_configs/baseline/ beside agent.yaml |
| Supported targets | instruction, model, skill folder, function tool definitions |
| azd setup | azd Setup |
| Detailed scaffold steps | Scaffold Workflow |
| Python/file patterns | Python Patterns |
| Eval config | eval.yaml Guidance |
| Optimize flow | Optimize Workflow |
High-Level Lifecycle
- Prepare azd: Verify azd, login, and
azure.ai.agentsextension with azd Setup. - Scaffold: Follow Scaffold Workflow when SDK wiring or
.agent_configs/baseline/is missing; stop for review if files changed. - Configure eval: Create or update
eval.yamlusing eval.yaml Guidance. - Optimize: Run and monitor
azd ai agent optimizewith Optimize Workflow. - Apply and deploy: Apply the selected candidate locally, review the diff, then deploy with
azd deploy.
Workflow
- Resolve the target agent root and confirm it is a Python hosted agent.
- Read azd Setup, then Scaffold Workflow if scaffolding is needed.
- Read eval.yaml Guidance and configure optimization inputs from known dataset/evaluator context.
- Read Optimize Workflow, run optimization, and ask before applying a candidate.
- After local review and approval, deploy with
azd deploy, then invoke via invoke.
Guardrails
- Target hosted Python agents only.
- Preserve existing frameworks, tools, hosting adapters, protocols, and entrypoints.
- Do not use one global scaffold across multi-agent roles unless the architecture already has one global prompt/model or the user approves.
- Keep edits scoped to the selected agent root.
- Do not apply candidates or deploy automatically; stop for review first.
- Prefer
azd ai agent optimize apply --candidateplusazd deployover direct optimize deploy so source changes are reviewable.