Skip to content

Commit 3ceb914

Browse files
[feat] new azure-ai-agentserver-optimization package for load_config
1 parent b0873ba commit 3ceb914

19 files changed

Lines changed: 2654 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Release History
2+
3+
## 0.1.0b1 (Unreleased)
4+
5+
### Features Added
6+
7+
- Initial beta release.
8+
- `load_config()` — single-call config loader with graceful fallback.
9+
- `OptimizationConfig` dataclass with instructions, model, temperature, skills, and tool definitions.
10+
- Candidate resolution via `OPTIMIZATION_CANDIDATE_ID` env var and remote resolver API.
11+
- Inline JSON config via `OPTIMIZATION_CONFIG` env var.
12+
- Local directory layout support (`metadata.yaml` + `instructions.md` + `skills/`).
13+
- Skill loading from `SKILL.md` files with YAML frontmatter.
14+
- Tool definition loading from `tools.json`.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# azure-ai-agentserver-optimization
2+
3+
Optimization config loader for Azure AI Hosted Agents.
4+
5+
Provides a single `load_config()` call that resolves optimization parameters (instructions, model, temperature, skills, tool definitions) from multiple sources with graceful fallback — your agent works unchanged when not running under optimization.
6+
7+
## Installation
8+
9+
```bash
10+
pip install azure-ai-agentserver-optimization
11+
```
12+
13+
## Quick Start
14+
15+
```python
16+
from azure.ai.agentserver.optimization import load_config
17+
18+
config = load_config(default_instructions="You are a helpful assistant.")
19+
20+
# Use config in your agent
21+
print(config.instructions) # optimized or default
22+
print(config.model) # optimized or default
23+
print(config.temperature) # optimized or default
24+
print(config.skills) # learned skills (empty list if none)
25+
print(config.tool_descriptions) # optimized tool descriptions (empty dict if none)
26+
print(config.source) # "api:candidate:abc", "env:OPTIMIZATION_CONFIG", "local:...", or "defaults"
27+
```
28+
29+
## Resolution Order
30+
31+
`load_config()` resolves from four sources in order — first match wins:
32+
33+
| Priority | Source | Env vars required | Description |
34+
|----------|--------|-------------------|-------------|
35+
| 1 | **Inline JSON** | `OPTIMIZATION_CONFIG` | Full config as a JSON string. Used by temporary agent versions during evaluation. |
36+
| 2 | **Resolver API** | `OPTIMIZATION_CANDIDATE_ID`, `OPTIMIZATION_JOB_ID`, `OPTIMIZATION_RESOLVE_ENDPOINT` | Fetches the candidate config from the remote optimization service and persists it to the local directory. |
37+
| 3 | **Local directory** | `OPTIMIZATION_LOCAL_DIR` (optional, defaults to `.agent_configs/`) | Reads from `<local_dir>/<candidate_id>/` or `baseline/` as fallback. |
38+
| 4 | **Defaults** | *(none)* | Returns the caller-supplied defaults unchanged — the agent works normally. |
39+
40+
Any unexpected error is caught and logged — `load_config()` always returns a valid `OptimizationConfig`.
41+
42+
## Environment Variables
43+
44+
| Variable | Description |
45+
|----------|-------------|
46+
| `OPTIMIZATION_CONFIG` | Inline JSON config (Priority 1). |
47+
| `OPTIMIZATION_CANDIDATE_ID` | Candidate ID for resolver API or local folder lookup. |
48+
| `OPTIMIZATION_JOB_ID` | Job ID for the resolver API. |
49+
| `OPTIMIZATION_RESOLVE_ENDPOINT` | Base URL of the optimization service. |
50+
| `OPTIMIZATION_LOCAL_DIR` | Path to the local config directory (default: `.agent_configs/`). |
51+
| `MODEL_DEPLOYMENT_NAME` | Fallback model name when no model is resolved or specified. |
52+
53+
## Local Directory Layout
54+
55+
When using the local directory (Priority 3) or after the resolver API persists a candidate (Priority 2), the directory uses the following structure:
56+
57+
```
58+
.agent_configs/
59+
├── baseline/ # fallback candidate
60+
│ ├── metadata.yaml # model, temperature, file pointers
61+
│ ├── instructions.md # system prompt
62+
│ ├── tools.json # tool descriptions (dict or OpenAI list format)
63+
│ └── skills/ # learned skills
64+
│ └── <skill_name>/
65+
│ └── SKILL.md
66+
└── <candidate_id>/ # same layout as baseline/
67+
├── metadata.yaml
68+
├── instructions.md
69+
├── tools.json
70+
└── skills/
71+
└── <skill_name>/
72+
└── SKILL.md
73+
```
74+
75+
## Tool Description Formats
76+
77+
`tools.json` and the inline JSON config support three formats:
78+
79+
**Dict format** (`tool_descriptions`):
80+
```json
81+
{
82+
"lookup_policy": {
83+
"description": "Look up the company travel policy.",
84+
"parameters": {"dept": "Department name"}
85+
}
86+
}
87+
```
88+
89+
**Legacy camelCase** (`toolDescriptions`) — same structure, different key. `tool_descriptions` takes priority when both are present.
90+
91+
**OpenAI function-calling list** (`tools`):
92+
```json
93+
[
94+
{
95+
"type": "function",
96+
"function": {
97+
"name": "lookup_policy",
98+
"description": "Look up the company travel policy.",
99+
"parameters": {
100+
"type": "object",
101+
"properties": {
102+
"dept": {"type": "string", "description": "Department name"}
103+
}
104+
}
105+
}
106+
}
107+
]
108+
```
109+
110+
## OptimizationConfig Properties
111+
112+
| Property | Type | Description |
113+
|----------|------|-------------|
114+
| `instructions` | `str` | System prompt (optimized or default). |
115+
| `model` | `str \| None` | Model deployment name. |
116+
| `temperature` | `float \| None` | Sampling temperature. |
117+
| `skills` | `list[Skill]` | Learned skills. |
118+
| `skills_dir` | `str \| None` | Path to skills directory. |
119+
| `tool_descriptions` | `dict[str, ToolDescription]` | Optimized tool descriptions. |
120+
| `source` | `str` | Where the config was loaded from. |
121+
| `candidate_id` | `str \| None` | Candidate ID (when resolved via API). |
122+
| `job_id` | `str \| None` | Job ID (when resolved via API). |
123+
| `has_skills` | `bool` | Whether skills are available. |
124+
| `has_tool_descriptions` | `bool` | Whether tool descriptions are available. |
125+
126+
## Contributing
127+
128+
This project welcomes contributions and suggestions. See [CONTRIBUTING.md](https://github.com/Azure/azure-sdk-for-python/blob/main/CONTRIBUTING.md) for details.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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(default_instructions="You are a helpful assistant.")
12+
# config.instructions — optimized or default
13+
# config.model — optimized or default
14+
# config.temperature — optimized or default
15+
# config.skills — learned skills (empty if none)
16+
# config.tool_definitions — optimized tool definitions (empty if none)
17+
# config.source — "api:candidate:abc", "env:config", or "defaults"
18+
19+
Resolution order (first match wins):
20+
1. OPTIMIZATION_CONFIG env var → inline JSON (used by temp agent versions)
21+
2. OPTIMIZATION_CANDIDATE_ID + JOB_ID + ENDPOINT → resolver API → full config + skills
22+
3. Local directory (.agent_configs/) → metadata.yaml + instructions.md + tools.json + skills/
23+
4. Defaults → your hardcoded values (agent works normally)
24+
"""
25+
26+
from azure.ai.agentserver.optimization._config import load_config
27+
from azure.ai.agentserver.optimization._models import (
28+
CandidateConfig,
29+
OptimizationConfig,
30+
Skill,
31+
ToolDescription,
32+
)
33+
from azure.ai.agentserver.optimization._version import VERSION
34+
35+
__all__ = [
36+
"CandidateConfig",
37+
"OptimizationConfig",
38+
"Skill",
39+
"ToolDescription",
40+
"load_config",
41+
]
42+
__version__ = VERSION

0 commit comments

Comments
 (0)