AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

microsoft-foundry

Build, deploy, evaluate, optimize, fine-tune, and manage Microsoft Foundry agents, models, and resources end to end. USE FOR: foundry, azd ai agent, azd provision/deploy, hosted agent scaffold/develop/run/deploy/troubleshoot, prompt agent, managed harness agent, Copilot harness, voice agent, create/update/invoke/evaluate agent, add tool to agent, agent insights, batch/continuous eval, continuous monitoring, agent CI/CD, optimize/improve prompt, optimize agent instructions, Agent Optimizer, dataset curation from traces, deploy model, model fine-tuning (SFT/DPO/RFT), Foundry project, RBAC, role assignment, permissions, quota, capacity, region, deployment failure, AI Services, create Foundry resource, knowledge index, customize deployment, onboard, availability, training-data, grader, distillation, large file upload. DO NOT USE FOR: Azure Functions, App Service, general Azure deploy (use azure-deploy), general Azure prep (use azure-prepare).

Original source
microsoft
License
MIT
Pinned revision
3f5b461b2314e01c400564051e92469114c5b68f

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

This skill also requires local files or dependencies. Remote reading alone may not be enough.

Ask your assistant

Use Agentic Memory skills to read microsoft--microsoft-foundry at revision 3f5b461b2314e01c400564051e92469114c5b68f, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 151

foundry-agent/agent-optimizer/references/python-patterns.md

Python Agent Optimizer in Foundry Patterns

Use the Azure SDK optimization package and a local baseline folder. The baseline is file-based; call load_config() without code-level fallback parameters.

Install and Import

Add azure-ai-agentserver-optimization to requirements.txt or the project dependency file:

azure-ai-agentserver-optimization

Import from the SDK namespace:

from azure.ai.agentserver.optimization import load_config

Baseline Folder

Create .agent_configs/baseline/ in the agent's service source directory (beside the entry point):

<agent-root>/
  main.py
  .agent_configs/
    baseline/
      metadata.yaml
      instructions.md
      tools.json
      skills/<skill-name>/SKILL.md

Example metadata.yaml:

model: <existing-chat-model-deployment-name>
temperature: 0.7
instruction_file: instructions.md
skill_dir: skills
tool_file: tools.json

instructions.md contains the selected baseline system/developer instructions. Include only skill folders relevant to the optimization goal.

Choose a model value that already exists as a model deployment in the target Foundry project. Do not assume gpt-4o is available.

Tools File

Use OpenAI function-calling tool objects under top-level tools. Currently, only function tool definition optimization is supported:

{
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "lookup_policy",
        "description": "Look up the company travel policy.",
        "parameters": {
          "type": "object",
          "properties": {
            "dept": {
              "type": "string",
              "description": "Department name"
            }
          }
        }
      }
    }
  ]
}

Runtime Wiring

Call load_config() with no defaults:

config = load_config()
instructions = config.compose_instructions()
model = config.model

For Microsoft Agent Framework:

client = FoundryChatClient(
    project_endpoint=project_endpoint,
    model=config.model,
    credential=credential,
)

agent = Agent(
    client=client,
    instructions=config.compose_instructions(),
    tools=tools,
)

Patch optimized function tool definitions through the public helper. It updates matching function docs, descriptions, and parameter descriptions:

config.apply_tool_descriptions(tools)

Load skills on demand when the runtime has a safe skill/tool mechanism:

from pathlib import Path
from azure.ai.agentserver.optimization import load_skills_from_dir

skills = load_skills_from_dir(Path(config.skills_dir)) if config.skills_dir else []

Target Selection

Use evaluator and dataset goals to decide what belongs in the baseline:

| Signal | Prefer | | ------ | ------ | | relevance, task_adherence | primary instructions and model | | intent_resolution | router/orchestrator instructions | | builtin.tool_call_accuracy | tool-calling instructions and OpenAI function tool definitions | | safety/groundedness | safety, retrieval, citation, or answer-synthesis instructions |

For multi-agent apps, scaffold the target role's instructions and related skills/tools. Do not merge unrelated role prompts into one baseline.

Runtime Config

The SDK reads optimization context from supported runtime sources. Keep .agent_configs/baseline/ present so default load_config() startup has a local baseline. Use load_config(config_dir="my_configs") only for non-default local config directories, and load_config(required=False) only when the app can intentionally run without optimization config.

Verification Checklist

  • Dependency file includes azure-ai-agentserver-optimization
  • from azure.ai.agentserver.optimization import load_config succeeds
  • .agent_configs/baseline/metadata.yaml exists and points to existing files
  • load_config() is called without defaults unless using an intentional config_dir or required=False
  • Changed Python files compile and preserve the hosting adapter/protocol
  • User is asked to review before deployment