Skip to main content
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.
Adding support for the agent optimizer to your agent requires a few lines of code. No framework changes or conditional logic are needed. You install the optimization package, set up a configuration directory, and call 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:
  1. Install the optimization package.
  2. Set up a baseline configuration directory with your instructions and, optionally, tools and skills.
  3. Load the config at startup with load_config() and use the values it returns.
The rest of this article gives a complete example and explains how configuration resolution works. After an optimization run finishes, you apply the winning candidate and deploy—see Deploy the winner.

Prerequisites

Install the optimization package

Install the azure-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.
The baseline requires 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:
The optimizer improves this prompt during optimization runs. After you apply an optimized candidate, this file contains the improved version.

tools.json

Declare the tools your agent can call using the OpenAI function-calling format:
The optimizer can improve tool descriptions to help the model call tools more accurately. After optimization, you apply improved descriptions back into this file.

skills/ (Agent Skills format)

Skills use the open Agent Skills format. Each skill is a folder containing a SKILL.md file:
A SKILL.md file has YAML frontmatter for metadata and markdown body for instructions:
The YAML frontmatter (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:
The 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:
The 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:
The 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:
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

  1. 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.
  2. During optimization: The optimizer sets OPTIMIZATION_CONFIG with 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.
  1. 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. Then azd deploy deploys the agent with the improved configuration. For the full apply and deploy steps, see Deploy the winner.
Your code never changes between these states. The config resolution is fully automatic.

Configuration resolution order

The load_config() function resolves configuration using a priority chain (first match wins):

Verify

Confirm that the package is importable and the configuration loads correctly: