Agent Optimizer is currently in preview. This preview is provided without a service-level agreement, and we don’t recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.
load_config() at startup.
This step is the first step in the optimization workflow. The baseline configuration you create defines the inputs the optimizer improves: instructions, tools, skills, and the model. Your agent works the same whether or not optimization is active.
To make your agent optimizer-ready, complete three steps:
- Install the optimization package.
- Set up a baseline configuration directory with your instructions and, optionally, tools and skills.
- Load the config at startup with
load_config()and use the values it returns.
Prerequisites
- A Foundry project with a deployed hosted agent
- Familiarity with hosted agents
- Python 3.10 or later
Install the optimization package
Install theazure-ai-agentserver-optimization package:
Set up the configuration directory
Create the.agent_configs/baseline/ directory at your project root. This directory defines your agent’s baseline configuration — the starting point that the optimizer reads and improves upon.
metadata.yaml and instructions.md. The tools.json file and skills/ directory are optional - include them only if your agent uses tools or skills. The optimizer activates each target based on which of these files are present.
metadata.yaml
The metadata file tells the optimization loader where to find configuration files and which model to use:instructions.md
Your agent’s system prompt. Write it as plain text or markdown:tools.json
Declare the tools your agent can call using the OpenAI function-calling format:skills/ (Agent Skills format)
Skills use the open Agent Skills format. Each skill is a folder containing aSKILL.md file:
SKILL.md file has YAML frontmatter for metadata and markdown body for instructions:
name and description) enables progressive disclosure — the agent loads only metadata at startup, then activates the full skill instructions when a matching task is detected.
The optimizer can discover and create new skills during optimization. These skills are written to the skills/ directory when you apply an optimized candidate.
Learn more about the Agent Skills format at agentskills.io.
Load and use the config
Add the config loader at the top of your agent’s entry point:load_config() function reads from .agent_configs/ and returns an
OptimizationConfig object. When no optimization candidate is active, it
returns your baseline configuration. If no config source is found, it returns
None.
Parameters:
OptimizationConfig fields:
Use the config values
Use the model and composed instructions when calling the model:compose_instructions() method returns the system prompt with any discovered skills appended as a skill catalog.
Apply optimized tool descriptions
If your agent uses tools (functions), apply optimized descriptions to them:apply_tool_descriptions() method patches each tool function’s metadata with the improved descriptions from the optimization config. This improves the model’s accuracy when deciding which tool to call.
If your tools aren’t compatible with apply_tool_descriptions(), read the optimized definitions from config.tool_definitions and apply them to your own tool objects. Each definition includes both the optimized function description and the parameter descriptions, so map both onto your tools by function and parameter name.
Load skills from a directory
If your optimization config doesn’t include skills, you can load them from a local directory:Log the config source (recommended)
Add a log line to confirm where the config came from:Complete example
The following example shows a travel approval agent that uses the optimization config for instructions, tools, and skills:How it works
-
Normal operation: No optimization environment variables are set. The config loader reads
.agent_configs/baseline/and returns your baseline config. The agent works with your original instructions. -
During optimization: The optimizer sets
OPTIMIZATION_CONFIGwith the candidate’s configuration as inline JSON. Your agent uses the candidate’s instructions and tool descriptions during evaluation.
During evaluation, the optimizer invokes your agent against every task in your dataset, so any external tool calls run for real. For guidance on avoiding unintended side effects, see How the agent optimizer works.
- After applying a winner: You run
azd ai agent optimize apply --candidate <id>to write the optimized config files into.agent_configs/<candidate_id>/in your project. Thenazd deploydeploys the agent with the improved configuration. For the full apply and deploy steps, see Deploy the winner.
Configuration resolution order
Theload_config() function resolves configuration using a priority chain (first match wins):
Verify
Confirm that the package is importable and the configuration loads correctly:Related content
- Agent optimizer overview
- Create an evaluation dataset and evaluators
- Optimize agent instructions, skills, tools, and models
- Quickstart: Optimize a hosted agent
- Agent Skills format — open standard for portable agent skills