azure-ai-agentserver-optimization 1.0.0b1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. azure_ai_agentserver_optimization-1.0.0b1/CHANGELOG.md +24 -0
  2. azure_ai_agentserver_optimization-1.0.0b1/LICENSE +21 -0
  3. azure_ai_agentserver_optimization-1.0.0b1/MANIFEST.in +8 -0
  4. azure_ai_agentserver_optimization-1.0.0b1/PKG-INFO +247 -0
  5. azure_ai_agentserver_optimization-1.0.0b1/README.md +222 -0
  6. azure_ai_agentserver_optimization-1.0.0b1/azure/__init__.py +1 -0
  7. azure_ai_agentserver_optimization-1.0.0b1/azure/ai/__init__.py +1 -0
  8. azure_ai_agentserver_optimization-1.0.0b1/azure/ai/agentserver/__init__.py +1 -0
  9. azure_ai_agentserver_optimization-1.0.0b1/azure/ai/agentserver/optimization/__init__.py +37 -0
  10. azure_ai_agentserver_optimization-1.0.0b1/azure/ai/agentserver/optimization/_config.py +398 -0
  11. azure_ai_agentserver_optimization-1.0.0b1/azure/ai/agentserver/optimization/_models.py +289 -0
  12. azure_ai_agentserver_optimization-1.0.0b1/azure/ai/agentserver/optimization/_resolver.py +398 -0
  13. azure_ai_agentserver_optimization-1.0.0b1/azure/ai/agentserver/optimization/_version.py +6 -0
  14. azure_ai_agentserver_optimization-1.0.0b1/azure/ai/agentserver/optimization/py.typed +0 -0
  15. azure_ai_agentserver_optimization-1.0.0b1/azure_ai_agentserver_optimization.egg-info/PKG-INFO +247 -0
  16. azure_ai_agentserver_optimization-1.0.0b1/azure_ai_agentserver_optimization.egg-info/SOURCES.txt +23 -0
  17. azure_ai_agentserver_optimization-1.0.0b1/azure_ai_agentserver_optimization.egg-info/dependency_links.txt +1 -0
  18. azure_ai_agentserver_optimization-1.0.0b1/azure_ai_agentserver_optimization.egg-info/requires.txt +3 -0
  19. azure_ai_agentserver_optimization-1.0.0b1/azure_ai_agentserver_optimization.egg-info/top_level.txt +1 -0
  20. azure_ai_agentserver_optimization-1.0.0b1/pyproject.toml +62 -0
  21. azure_ai_agentserver_optimization-1.0.0b1/setup.cfg +4 -0
  22. azure_ai_agentserver_optimization-1.0.0b1/tests/conftest.py +23 -0
  23. azure_ai_agentserver_optimization-1.0.0b1/tests/test_config.py +1372 -0
  24. azure_ai_agentserver_optimization-1.0.0b1/tests/test_integration.py +469 -0
  25. azure_ai_agentserver_optimization-1.0.0b1/tests/test_resolver.py +826 -0
@@ -0,0 +1,24 @@
1
+ # Release History
2
+
3
+ ## 1.0.0b1 (2026-05-24)
4
+
5
+ ### Features Added
6
+
7
+ - Initial beta release.
8
+ - `load_config(*, config_dir)` — single-call config loader with 4-priority resolution and graceful fallback.
9
+ - `load_skills_from_dir(path)` — load skills from a directory on demand (not loaded inline by `load_config`).
10
+ - `OptimizationConfig` with instructions, model, temperature, skills, skills_dir, tool_definitions, source, and candidate_id.
11
+ - `OptimizationConfig.apply_tool_descriptions(tools)` — patch `__doc__`, `.description`, and `input_model` parameter descriptions on @tool-decorated functions from optimized tool definitions.
12
+ - `OptimizationConfig.compose_instructions()` — append skill catalog to instructions.
13
+ - `CandidateConfig` — typed representation of the resolver API payload.
14
+ - `Skill` — learned skill model (name, description, body).
15
+ - 4-priority resolution order:
16
+ 1. Inline JSON via `OPTIMIZATION_CONFIG` env var.
17
+ 2. Resolver API via `OPTIMIZATION_CANDIDATE_ID` + `OPTIMIZATION_RESOLVE_ENDPOINT` (endpoint is the full job-scoped URL).
18
+ 3. Local directory layout (`OPTIMIZATION_LOCAL_DIR` or `config_dir` param, defaults to `.agent_configs/`).
19
+ 4. No config found → returns `None`.
20
+ - Local directory layout: `metadata.yaml` + `instructions.md` + `tools.json` + `skills/` per candidate, with `baseline/` fallback.
21
+ - Tool definitions use the OpenAI function-calling list format exclusively.
22
+ - Skill loading from `SKILL.md` files with YAML frontmatter.
23
+ - Resolver API persists fetched configs and skill files to local directory for offline use.
24
+ - Path traversal (zip-slip) protection on skill file downloads from the API.
@@ -0,0 +1,21 @@
1
+ Copyright (c) Microsoft Corporation.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ include *.md
2
+ include LICENSE
3
+ recursive-include tests *.py
4
+ recursive-include samples *.py *.md
5
+ include azure/__init__.py
6
+ include azure/ai/__init__.py
7
+ include azure/ai/agentserver/__init__.py
8
+ include azure/ai/agentserver/optimization/py.typed
@@ -0,0 +1,247 @@
1
+ Metadata-Version: 2.4
2
+ Name: azure-ai-agentserver-optimization
3
+ Version: 1.0.0b1
4
+ Summary: Optimization config loader for Azure AI Hosted Agents
5
+ Author-email: Microsoft Corporation <azpysdkhelp@microsoft.com>
6
+ License-Expression: MIT
7
+ Project-URL: repository, https://github.com/Azure/azure-sdk-for-python
8
+ Keywords: azure,azure sdk,agent,agentserver,optimization
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Programming Language :: Python
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: pyyaml>=6.0
22
+ Requires-Dist: azure-core>=1.31.0
23
+ Requires-Dist: azure-identity>=1.15.0
24
+ Dynamic: license-file
25
+
26
+ # Azure AI Agent Server Optimization client library for Python
27
+
28
+ The `azure-ai-agentserver-optimization` package provides a drop-in config loader for optimization-ready Azure AI Hosted Agents. A single `load_config()` call resolves optimization parameters (instructions, model, temperature, skills, tool definitions) from multiple sources with graceful fallback — your agent works unchanged when not running under optimization.
29
+
30
+ ## Getting started
31
+
32
+ ### Install the package
33
+
34
+ ```bash
35
+ pip install azure-ai-agentserver-optimization
36
+ ```
37
+
38
+ ### Prerequisites
39
+
40
+ - Python 3.10 or later
41
+
42
+ ## Key concepts
43
+
44
+ ### Resolution Order
45
+
46
+ `load_config()` resolves from four sources in order — first match wins:
47
+
48
+ | Priority | Source | Env vars required | Description |
49
+ |----------|--------|-------------------|-------------|
50
+ | 1 | **Inline JSON** | `OPTIMIZATION_CONFIG` | Full config as a JSON string. Used by temporary agent versions during evaluation. |
51
+ | 2 | **Resolver API** | `OPTIMIZATION_CANDIDATE_ID`, `OPTIMIZATION_RESOLVE_ENDPOINT` | Fetches the candidate config from the remote optimization service and persists it to the local directory. The endpoint should be the full job-scoped URL. |
52
+ | 3 | **Local directory** | `OPTIMIZATION_LOCAL_DIR` (optional, defaults to `.agent_configs/`) | Reads from `<local_dir>/<candidate_id>/` or `baseline/` as fallback. |
53
+ | 4 | **No config** | *(none)* | Returns `None`. |
54
+
55
+ When `load_config()` encounters an invalid config source (e.g. malformed JSON env var, unreadable metadata), it raises `ValueError`. Other exceptions (e.g. network errors from the resolver API) propagate to the caller.
56
+
57
+ ### Environment Variables
58
+
59
+ | Variable | Description |
60
+ |----------|-------------|
61
+ | `OPTIMIZATION_CONFIG` | Inline JSON config (Priority 1). |
62
+ | `OPTIMIZATION_CANDIDATE_ID` | Candidate ID for resolver API or local folder lookup. |
63
+ | `OPTIMIZATION_RESOLVE_ENDPOINT` | Full job-scoped URL of the optimization service (e.g. `https://host/api/projects/proj/agents_optimization_job/job-1`). |
64
+ | `OPTIMIZATION_LOCAL_DIR` | Path to the local config directory (default: `.agent_configs/`). |
65
+
66
+ ### Local Directory Layout
67
+
68
+ The local config directory **must** exist with at least a `baseline/` folder before the agent can start to do optimization. When running under optimization, the resolver API (Priority 2) persists candidate configs into the same layout. If a `<candidate_id>/` folder exists it takes precedence; otherwise `baseline/` is used as the fallback.
69
+
70
+ ```
71
+ .agent_configs/
72
+ ├── baseline/ # required — default candidate used at startup
73
+ │ ├── metadata.yaml # model, temperature, file pointers
74
+ │ ├── instructions.md # system prompt
75
+ │ ├── tools.json # tool definitions (OpenAI function-calling list format)
76
+ │ └── skills/ # learned skills
77
+ │ └── <skill_name>/
78
+ │ └── SKILL.md
79
+ └── <candidate_id>/ # optional — created by resolver API, same layout as baseline/
80
+ ├── metadata.yaml
81
+ ├── instructions.md
82
+ ├── tools.json
83
+ └── skills/
84
+ └── <skill_name>/
85
+ └── SKILL.md
86
+ ```
87
+
88
+ #### `metadata.yaml`
89
+
90
+ Points to the other files and sets model parameters. All fields are optional:
91
+
92
+ ```yaml
93
+ model: gpt-4o
94
+ temperature: 0.7
95
+ instruction_file: instructions.md
96
+ skill_dir: skills
97
+ tool_file: tools.json
98
+ ```
99
+
100
+ #### `instructions.md`
101
+
102
+ The system prompt for the agent — plain text or Markdown:
103
+
104
+ ```markdown
105
+ You are a travel assistant. Help users search flights, book hotels,
106
+ and answer questions about company travel policy.
107
+ ```
108
+
109
+ #### `tools.json`
110
+
111
+ Tool definitions in the OpenAI function-calling list format:
112
+
113
+ ```json
114
+ [
115
+ {
116
+ "type": "function",
117
+ "function": {
118
+ "name": "lookup_policy",
119
+ "description": "Look up the company travel policy.",
120
+ "parameters": {
121
+ "type": "object",
122
+ "properties": {
123
+ "dept": {"type": "string", "description": "Department name"}
124
+ }
125
+ }
126
+ }
127
+ }
128
+ ]
129
+ ```
130
+
131
+ #### `skills/*/SKILL.md`
132
+
133
+ Each skill lives in its own subfolder with a `SKILL.md` file. An optional YAML frontmatter block provides the name and description; the rest is the skill body:
134
+
135
+ ```markdown
136
+ ---
137
+ name: budget-checker
138
+ description: Check whether a trip is within budget.
139
+ ---
140
+
141
+ Compare the trip cost against the department's remaining travel budget
142
+ and return APPROVED or DENIED with a reason.
143
+ ```
144
+
145
+ ### OptimizationConfig Properties
146
+
147
+ | Property | Type | Description |
148
+ |----------|------|-------------|
149
+ | `instructions` | `str \| None` | System prompt (optimized or default). |
150
+ | `model` | `str \| None` | Model deployment name. |
151
+ | `temperature` | `float \| None` | Sampling temperature. |
152
+ | `skills` | `list[Skill]` | Learned skills (from inline config). |
153
+ | `skills_dir` | `str \| None` | Path to skills directory (for on-demand loading). |
154
+ | `tool_definitions` | `list[dict]` | Optimized tool definitions (OpenAI function-calling format). |
155
+ | `source` | `str` | Where the config was loaded from. |
156
+ | `candidate_id` | `str \| None` | Candidate ID (when resolved via API or local folder). |
157
+ | `has_skills` | `bool` | Whether skills are available (inline or via skills_dir). |
158
+
159
+ ### Public API
160
+
161
+ | Export | Type | Description |
162
+ |--------|------|-------------|
163
+ | `load_config(*, config_dir)` | function | Load optimization config with 4-priority resolution. |
164
+ | `load_skills_from_dir(path)` | function | Load skills from a directory of `SKILL.md` files. |
165
+ | `OptimizationConfig` | class | Resolved config with instructions, model, temperature, skills_dir, tool_definitions. |
166
+ | `OptimizationConfig.apply_tool_descriptions(tools)` | method | Patch `__doc__`, `.description`, and parameter descriptions on tool functions. |
167
+ | `OptimizationConfig.compose_instructions()` | method | Return instructions with skill catalog appended. |
168
+ | `CandidateConfig` | class | Typed representation of the resolver API response. |
169
+ | `Skill` | class | A learned skill (name, description, body). |
170
+
171
+ ## Examples
172
+
173
+ ### Basic usage
174
+
175
+ ```python
176
+ from azure.ai.agentserver.optimization import load_config
177
+
178
+ config = load_config() # uses .agent_configs/baseline/
179
+ config = load_config(config_dir="my_configs") # custom directory
180
+
181
+ if config is None:
182
+ print("No optimization config found")
183
+ else:
184
+ print(config.instructions) # optimized system prompt
185
+ print(config.model) # optimized model name
186
+ print(config.temperature) # optimized temperature
187
+ print(config.tool_definitions) # optimized tool definitions (list)
188
+ print(config.source) # "env:OPTIMIZATION_CONFIG", "api:candidate:abc", "local:...", etc.
189
+ ```
190
+
191
+ ### Apply optimized tool descriptions
192
+
193
+ ```python
194
+ from azure.ai.agentserver.optimization import load_config
195
+
196
+ config = load_config()
197
+
198
+ # Your @tool-decorated functions
199
+ def search_flights(origin: str, destination: str):
200
+ """Search for flights."""
201
+ ...
202
+
203
+ def book_hotel(city: str):
204
+ """Book a hotel room."""
205
+ ...
206
+
207
+ # Patches __doc__ and .description on matching tools with optimized descriptions
208
+ config.apply_tool_descriptions([search_flights, book_hotel])
209
+ ```
210
+
211
+ ### Load skills on demand
212
+
213
+ ```python
214
+ from pathlib import Path
215
+ from azure.ai.agentserver.optimization import load_config, load_skills_from_dir
216
+
217
+ config = load_config()
218
+
219
+ # Skills are not loaded inline — load them when needed
220
+ if config.skills_dir:
221
+ skills = load_skills_from_dir(Path(config.skills_dir))
222
+ for skill in skills:
223
+ print(f"{skill.name}: {skill.description}")
224
+ ```
225
+
226
+ ## Troubleshooting
227
+
228
+ Enable debug logging to see resolution details:
229
+
230
+ ```python
231
+ import logging
232
+ logging.getLogger("azure.ai.agentserver.optimization").setLevel(logging.DEBUG)
233
+ ```
234
+
235
+ Common issues:
236
+ - **Config not loading from resolver API** — ensure both env vars are set: `OPTIMIZATION_CANDIDATE_ID` and `OPTIMIZATION_RESOLVE_ENDPOINT`.
237
+ - **Local directory not found** — check that `OPTIMIZATION_LOCAL_DIR` points to an existing directory, or ensure `.agent_configs/` exists relative to your main script.
238
+ - **`load_config()` returns `None`** — no config source was found; set up a baseline folder or set the appropriate env vars.
239
+
240
+ ## Next steps
241
+
242
+ - [Azure SDK for Python documentation](https://learn.microsoft.com/azure/developer/python/)
243
+ - [Contributing guide](https://github.com/Azure/azure-sdk-for-python/blob/main/CONTRIBUTING.md)
244
+
245
+ ## Contributing
246
+
247
+ This project welcomes contributions and suggestions. See [CONTRIBUTING.md](https://github.com/Azure/azure-sdk-for-python/blob/main/CONTRIBUTING.md) for details.
@@ -0,0 +1,222 @@
1
+ # Azure AI Agent Server Optimization client library for Python
2
+
3
+ The `azure-ai-agentserver-optimization` package provides a drop-in config loader for optimization-ready Azure AI Hosted Agents. A single `load_config()` call resolves optimization parameters (instructions, model, temperature, skills, tool definitions) from multiple sources with graceful fallback — your agent works unchanged when not running under optimization.
4
+
5
+ ## Getting started
6
+
7
+ ### Install the package
8
+
9
+ ```bash
10
+ pip install azure-ai-agentserver-optimization
11
+ ```
12
+
13
+ ### Prerequisites
14
+
15
+ - Python 3.10 or later
16
+
17
+ ## Key concepts
18
+
19
+ ### Resolution Order
20
+
21
+ `load_config()` resolves from four sources in order — first match wins:
22
+
23
+ | Priority | Source | Env vars required | Description |
24
+ |----------|--------|-------------------|-------------|
25
+ | 1 | **Inline JSON** | `OPTIMIZATION_CONFIG` | Full config as a JSON string. Used by temporary agent versions during evaluation. |
26
+ | 2 | **Resolver API** | `OPTIMIZATION_CANDIDATE_ID`, `OPTIMIZATION_RESOLVE_ENDPOINT` | Fetches the candidate config from the remote optimization service and persists it to the local directory. The endpoint should be the full job-scoped URL. |
27
+ | 3 | **Local directory** | `OPTIMIZATION_LOCAL_DIR` (optional, defaults to `.agent_configs/`) | Reads from `<local_dir>/<candidate_id>/` or `baseline/` as fallback. |
28
+ | 4 | **No config** | *(none)* | Returns `None`. |
29
+
30
+ When `load_config()` encounters an invalid config source (e.g. malformed JSON env var, unreadable metadata), it raises `ValueError`. Other exceptions (e.g. network errors from the resolver API) propagate to the caller.
31
+
32
+ ### Environment Variables
33
+
34
+ | Variable | Description |
35
+ |----------|-------------|
36
+ | `OPTIMIZATION_CONFIG` | Inline JSON config (Priority 1). |
37
+ | `OPTIMIZATION_CANDIDATE_ID` | Candidate ID for resolver API or local folder lookup. |
38
+ | `OPTIMIZATION_RESOLVE_ENDPOINT` | Full job-scoped URL of the optimization service (e.g. `https://host/api/projects/proj/agents_optimization_job/job-1`). |
39
+ | `OPTIMIZATION_LOCAL_DIR` | Path to the local config directory (default: `.agent_configs/`). |
40
+
41
+ ### Local Directory Layout
42
+
43
+ The local config directory **must** exist with at least a `baseline/` folder before the agent can start to do optimization. When running under optimization, the resolver API (Priority 2) persists candidate configs into the same layout. If a `<candidate_id>/` folder exists it takes precedence; otherwise `baseline/` is used as the fallback.
44
+
45
+ ```
46
+ .agent_configs/
47
+ ├── baseline/ # required — default candidate used at startup
48
+ │ ├── metadata.yaml # model, temperature, file pointers
49
+ │ ├── instructions.md # system prompt
50
+ │ ├── tools.json # tool definitions (OpenAI function-calling list format)
51
+ │ └── skills/ # learned skills
52
+ │ └── <skill_name>/
53
+ │ └── SKILL.md
54
+ └── <candidate_id>/ # optional — created by resolver API, same layout as baseline/
55
+ ├── metadata.yaml
56
+ ├── instructions.md
57
+ ├── tools.json
58
+ └── skills/
59
+ └── <skill_name>/
60
+ └── SKILL.md
61
+ ```
62
+
63
+ #### `metadata.yaml`
64
+
65
+ Points to the other files and sets model parameters. All fields are optional:
66
+
67
+ ```yaml
68
+ model: gpt-4o
69
+ temperature: 0.7
70
+ instruction_file: instructions.md
71
+ skill_dir: skills
72
+ tool_file: tools.json
73
+ ```
74
+
75
+ #### `instructions.md`
76
+
77
+ The system prompt for the agent — plain text or Markdown:
78
+
79
+ ```markdown
80
+ You are a travel assistant. Help users search flights, book hotels,
81
+ and answer questions about company travel policy.
82
+ ```
83
+
84
+ #### `tools.json`
85
+
86
+ Tool definitions in the OpenAI function-calling list format:
87
+
88
+ ```json
89
+ [
90
+ {
91
+ "type": "function",
92
+ "function": {
93
+ "name": "lookup_policy",
94
+ "description": "Look up the company travel policy.",
95
+ "parameters": {
96
+ "type": "object",
97
+ "properties": {
98
+ "dept": {"type": "string", "description": "Department name"}
99
+ }
100
+ }
101
+ }
102
+ }
103
+ ]
104
+ ```
105
+
106
+ #### `skills/*/SKILL.md`
107
+
108
+ Each skill lives in its own subfolder with a `SKILL.md` file. An optional YAML frontmatter block provides the name and description; the rest is the skill body:
109
+
110
+ ```markdown
111
+ ---
112
+ name: budget-checker
113
+ description: Check whether a trip is within budget.
114
+ ---
115
+
116
+ Compare the trip cost against the department's remaining travel budget
117
+ and return APPROVED or DENIED with a reason.
118
+ ```
119
+
120
+ ### OptimizationConfig Properties
121
+
122
+ | Property | Type | Description |
123
+ |----------|------|-------------|
124
+ | `instructions` | `str \| None` | System prompt (optimized or default). |
125
+ | `model` | `str \| None` | Model deployment name. |
126
+ | `temperature` | `float \| None` | Sampling temperature. |
127
+ | `skills` | `list[Skill]` | Learned skills (from inline config). |
128
+ | `skills_dir` | `str \| None` | Path to skills directory (for on-demand loading). |
129
+ | `tool_definitions` | `list[dict]` | Optimized tool definitions (OpenAI function-calling format). |
130
+ | `source` | `str` | Where the config was loaded from. |
131
+ | `candidate_id` | `str \| None` | Candidate ID (when resolved via API or local folder). |
132
+ | `has_skills` | `bool` | Whether skills are available (inline or via skills_dir). |
133
+
134
+ ### Public API
135
+
136
+ | Export | Type | Description |
137
+ |--------|------|-------------|
138
+ | `load_config(*, config_dir)` | function | Load optimization config with 4-priority resolution. |
139
+ | `load_skills_from_dir(path)` | function | Load skills from a directory of `SKILL.md` files. |
140
+ | `OptimizationConfig` | class | Resolved config with instructions, model, temperature, skills_dir, tool_definitions. |
141
+ | `OptimizationConfig.apply_tool_descriptions(tools)` | method | Patch `__doc__`, `.description`, and parameter descriptions on tool functions. |
142
+ | `OptimizationConfig.compose_instructions()` | method | Return instructions with skill catalog appended. |
143
+ | `CandidateConfig` | class | Typed representation of the resolver API response. |
144
+ | `Skill` | class | A learned skill (name, description, body). |
145
+
146
+ ## Examples
147
+
148
+ ### Basic usage
149
+
150
+ ```python
151
+ from azure.ai.agentserver.optimization import load_config
152
+
153
+ config = load_config() # uses .agent_configs/baseline/
154
+ config = load_config(config_dir="my_configs") # custom directory
155
+
156
+ if config is None:
157
+ print("No optimization config found")
158
+ else:
159
+ print(config.instructions) # optimized system prompt
160
+ print(config.model) # optimized model name
161
+ print(config.temperature) # optimized temperature
162
+ print(config.tool_definitions) # optimized tool definitions (list)
163
+ print(config.source) # "env:OPTIMIZATION_CONFIG", "api:candidate:abc", "local:...", etc.
164
+ ```
165
+
166
+ ### Apply optimized tool descriptions
167
+
168
+ ```python
169
+ from azure.ai.agentserver.optimization import load_config
170
+
171
+ config = load_config()
172
+
173
+ # Your @tool-decorated functions
174
+ def search_flights(origin: str, destination: str):
175
+ """Search for flights."""
176
+ ...
177
+
178
+ def book_hotel(city: str):
179
+ """Book a hotel room."""
180
+ ...
181
+
182
+ # Patches __doc__ and .description on matching tools with optimized descriptions
183
+ config.apply_tool_descriptions([search_flights, book_hotel])
184
+ ```
185
+
186
+ ### Load skills on demand
187
+
188
+ ```python
189
+ from pathlib import Path
190
+ from azure.ai.agentserver.optimization import load_config, load_skills_from_dir
191
+
192
+ config = load_config()
193
+
194
+ # Skills are not loaded inline — load them when needed
195
+ if config.skills_dir:
196
+ skills = load_skills_from_dir(Path(config.skills_dir))
197
+ for skill in skills:
198
+ print(f"{skill.name}: {skill.description}")
199
+ ```
200
+
201
+ ## Troubleshooting
202
+
203
+ Enable debug logging to see resolution details:
204
+
205
+ ```python
206
+ import logging
207
+ logging.getLogger("azure.ai.agentserver.optimization").setLevel(logging.DEBUG)
208
+ ```
209
+
210
+ Common issues:
211
+ - **Config not loading from resolver API** — ensure both env vars are set: `OPTIMIZATION_CANDIDATE_ID` and `OPTIMIZATION_RESOLVE_ENDPOINT`.
212
+ - **Local directory not found** — check that `OPTIMIZATION_LOCAL_DIR` points to an existing directory, or ensure `.agent_configs/` exists relative to your main script.
213
+ - **`load_config()` returns `None`** — no config source was found; set up a baseline folder or set the appropriate env vars.
214
+
215
+ ## Next steps
216
+
217
+ - [Azure SDK for Python documentation](https://learn.microsoft.com/azure/developer/python/)
218
+ - [Contributing guide](https://github.com/Azure/azure-sdk-for-python/blob/main/CONTRIBUTING.md)
219
+
220
+ ## Contributing
221
+
222
+ This project welcomes contributions and suggestions. See [CONTRIBUTING.md](https://github.com/Azure/azure-sdk-for-python/blob/main/CONTRIBUTING.md) for details.
@@ -0,0 +1 @@
1
+ __path__ = __import__("pkgutil").extend_path(__path__, __name__)
@@ -0,0 +1 @@
1
+ __path__ = __import__("pkgutil").extend_path(__path__, __name__)
@@ -0,0 +1 @@
1
+ __path__ = __import__("pkgutil").extend_path(__path__, __name__)
@@ -0,0 +1,37 @@
1
+ # ---------------------------------------------------------
2
+ # Copyright (c) Microsoft Corporation. All rights reserved.
3
+ # ---------------------------------------------------------
4
+
5
+ """Agent Optimization — Config loader for optimization-ready hosted agents.
6
+
7
+ One import, one call::
8
+
9
+ from azure.ai.agentserver.optimization import load_config
10
+
11
+ config = load_config() # uses .agent_configs/baseline/
12
+ config = load_config(config_dir="my_configs") # custom directory
13
+
14
+ Resolution order (first match wins):
15
+ 1. OPTIMIZATION_CONFIG env var → inline JSON (used by temp agent versions)
16
+ 2. OPTIMIZATION_CANDIDATE_ID + ENDPOINT → resolver API → full config + skills
17
+ 3. Local directory (config_dir or .agent_configs/)
18
+ → metadata.yaml + instructions.md + tools.json + skills/
19
+ 4. No config found → returns ``None``.
20
+ """
21
+
22
+ from azure.ai.agentserver.optimization._config import load_config, load_skills_from_dir
23
+ from azure.ai.agentserver.optimization._models import (
24
+ CandidateConfig,
25
+ OptimizationConfig,
26
+ Skill,
27
+ )
28
+ from azure.ai.agentserver.optimization._version import VERSION
29
+
30
+ __all__ = [
31
+ "CandidateConfig",
32
+ "OptimizationConfig",
33
+ "Skill",
34
+ "load_config",
35
+ "load_skills_from_dir",
36
+ ]
37
+ __version__ = VERSION