azurefunctions-agents-runtime 0.0.0a2__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.
- azurefunctions_agents_runtime-0.0.0a2/LICENSE.md +21 -0
- azurefunctions_agents_runtime-0.0.0a2/PKG-INFO +510 -0
- azurefunctions_agents_runtime-0.0.0a2/README.md +481 -0
- azurefunctions_agents_runtime-0.0.0a2/pyproject.toml +109 -0
- azurefunctions_agents_runtime-0.0.0a2/setup.cfg +4 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/__init__.py +51 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/_blob_history.py +368 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/_credential.py +79 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/_function_tool.py +97 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/_logger.py +14 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/app.py +97 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/client_manager.py +243 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/config/__init__.py +78 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/config/env.py +102 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/config/loader.py +109 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/config/merge.py +146 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/config/paths.py +42 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/config/schema.py +162 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/config/validation.py +109 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/discovery/__init__.py +0 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/discovery/mcp.py +196 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/discovery/skills.py +102 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/discovery/tools.py +133 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/public/index.html +1523 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/registration/__init__.py +13 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/registration/_handlers.py +351 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/registration/_naming.py +84 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/registration/capabilities.py +70 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/registration/endpoints.py +373 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/registration/triggers.py +151 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/runner.py +611 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/system_tools/__init__.py +0 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azure_functions_agents/system_tools/sandbox.py +357 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azurefunctions_agents_runtime.egg-info/PKG-INFO +510 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azurefunctions_agents_runtime.egg-info/SOURCES.txt +57 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azurefunctions_agents_runtime.egg-info/dependency_links.txt +1 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azurefunctions_agents_runtime.egg-info/requires.txt +20 -0
- azurefunctions_agents_runtime-0.0.0a2/src/azurefunctions_agents_runtime.egg-info/top_level.txt +1 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_app.py +224 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_blob_history.py +487 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_client_manager.py +122 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_config_env.py +235 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_config_fixtures.py +479 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_config_loader.py +418 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_config_merge.py +308 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_config_paths.py +52 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_config_schema.py +92 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_config_validation.py +304 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_discovery_mcp.py +585 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_discovery_skills.py +148 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_discovery_tools.py +121 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_package_imports.py +46 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_registration_capabilities.py +141 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_registration_endpoints.py +443 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_registration_handlers.py +371 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_registration_triggers.py +665 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_runner_streaming.py +158 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_sandbox_session_id.py +117 -0
- azurefunctions_agents_runtime-0.0.0a2/tests/test_system_tools_sandbox.py +30 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
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,510 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: azurefunctions-agents-runtime
|
|
3
|
+
Version: 0.0.0a2
|
|
4
|
+
Summary: A markdown-first programming model for building AI agents on Azure Functions, powered by the Microsoft Agent Framework.
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.13
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE.md
|
|
9
|
+
Requires-Dist: azure-functions==2.1.*
|
|
10
|
+
Requires-Dist: agent-framework-core==1.3.*
|
|
11
|
+
Requires-Dist: agent-framework-openai==1.3.*
|
|
12
|
+
Requires-Dist: agent-framework-foundry==1.3.*
|
|
13
|
+
Requires-Dist: pydantic==2.13.*
|
|
14
|
+
Requires-Dist: python-frontmatter==1.1.*
|
|
15
|
+
Requires-Dist: azurefunctions-extensions-http-fastapi==1.0.*
|
|
16
|
+
Requires-Dist: aiohttp==3.13.*
|
|
17
|
+
Requires-Dist: azure-identity==1.25.*
|
|
18
|
+
Requires-Dist: azure-storage-blob==12.28.*
|
|
19
|
+
Requires-Dist: jsonschema==4.26.*
|
|
20
|
+
Requires-Dist: mcp==1.27.*
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: ruff==0.15.*; extra == "dev"
|
|
23
|
+
Requires-Dist: mypy==2.1.*; extra == "dev"
|
|
24
|
+
Requires-Dist: pydantic==2.13.*; extra == "dev"
|
|
25
|
+
Requires-Dist: pytest==9.0.*; extra == "dev"
|
|
26
|
+
Requires-Dist: types-jsonschema==4.26.*; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-cov==7.1.*; extra == "dev"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# azurefunctions-agents-runtime (Preview)
|
|
31
|
+
|
|
32
|
+
> **Public preview.** The features described here are available for preview use and may change before general availability.
|
|
33
|
+
|
|
34
|
+
A markdown-first programming model for building AI agents on Azure Functions, powered by the [Microsoft Agent Framework (MAF)](https://github.com/microsoft/agent-framework).
|
|
35
|
+
|
|
36
|
+
- **Build agents with markdown** — write instructions, configure triggers, and bind tools in `.agent.md` files
|
|
37
|
+
- **Run on any Azure Functions trigger** — trigger agents on timer, queue, blob, HTTP, Event Hub, Service Bus, Cosmos DB, and more
|
|
38
|
+
- **Connect to 1,400+ services** — use connector-backed MCP servers to let agents act through Office 365, Teams, SQL, Salesforce, SAP, and hundreds of other connectors
|
|
39
|
+
- **Extend with MCP servers** — plug in remote HTTP MCP servers, including MCP servers backed by connectors
|
|
40
|
+
- **Build custom tools in plain Python** — drop a `.py` file in `tools/`, decorate functions with `@tool`, and pull in any package you need
|
|
41
|
+
- **Automatic HTTP and MCP endpoints** — optionally expose your agent as an HTTP chat API and MCP server with no extra code
|
|
42
|
+
- **Serverless with built-in session management** — scales to zero, persists multi-turn conversations in Azure Blob Storage
|
|
43
|
+
- **Pluggable model providers** — bring OpenAI, Azure OpenAI, or Microsoft Foundry credentials and the runtime auto-detects the right client
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
The package is published on PyPI as **`azurefunctions-agents-runtime`**.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install azurefunctions-agents-runtime
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Add it to your function app's `requirements.txt`:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
azurefunctions-agents-runtime
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Model Provider Configuration
|
|
60
|
+
|
|
61
|
+
The runtime uses Microsoft Agent Framework, which supports Microsoft Foundry, Azure OpenAI, and OpenAI as inference back-ends. The public preview quickstart and samples use **Microsoft Foundry** as the primary path, pinned with `AZURE_FUNCTIONS_AGENTS_PROVIDER=foundry`.
|
|
62
|
+
|
|
63
|
+
| Provider | `AZURE_FUNCTIONS_AGENTS_PROVIDER` | Required env vars | Notes |
|
|
64
|
+
| --- | --- | --- | --- |
|
|
65
|
+
| Microsoft Foundry | `foundry` | `FOUNDRY_PROJECT_ENDPOINT`, `FOUNDRY_MODEL` | Recommended quickstart/sample path. Uses `DefaultAzureCredential`; run `az login` locally and set `AZURE_CLIENT_ID` in multi-identity Function Apps. |
|
|
66
|
+
| Azure OpenAI | `azure_openai` | `AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_DEPLOYMENT`, optional `AZURE_OPENAI_API_VERSION` | Alternative Azure-hosted provider. `AZURE_OPENAI_DEPLOYMENT` takes precedence over `AZURE_FUNCTIONS_AGENTS_MODEL`. If `AZURE_OPENAI_API_KEY` is omitted the SDK uses `DefaultAzureCredential` (AAD). |
|
|
67
|
+
| OpenAI | `openai` | `OPENAI_API_KEY`, optional `AZURE_FUNCTIONS_AGENTS_MODEL` (default `gpt-4o-mini`) | Alternative non-Azure provider. `AZURE_FUNCTIONS_AGENTS_MODEL` applies directly for OpenAI. |
|
|
68
|
+
|
|
69
|
+
If `AZURE_FUNCTIONS_AGENTS_PROVIDER` is unset, auto-detection picks the first provider whose env vars are set, in this order: `AZURE_OPENAI_ENDPOINT` → `FOUNDRY_PROJECT_ENDPOINT` → `OPENAI_API_KEY`. Set `AZURE_FUNCTIONS_AGENTS_PROVIDER` to make the provider choice intentional.
|
|
70
|
+
|
|
71
|
+
Model resolution precedence is: explicit requested model > provider-specific env (`FOUNDRY_MODEL` for Foundry, `AZURE_OPENAI_DEPLOYMENT` for Azure OpenAI) > `AZURE_FUNCTIONS_AGENTS_MODEL` > provider default.
|
|
72
|
+
|
|
73
|
+
## Quick Start
|
|
74
|
+
|
|
75
|
+
### 1. Create the agent file
|
|
76
|
+
|
|
77
|
+
Create `main.agent.md`:
|
|
78
|
+
|
|
79
|
+
```markdown
|
|
80
|
+
---
|
|
81
|
+
name: My Agent
|
|
82
|
+
description: A helpful assistant
|
|
83
|
+
|
|
84
|
+
builtin_endpoints: true
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
You are a helpful assistant. Answer questions concisely.
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 2. Create the function app entry point
|
|
91
|
+
|
|
92
|
+
Create `function_app.py`:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from azure_functions_agents import create_function_app
|
|
96
|
+
|
|
97
|
+
app = create_function_app()
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
> The app root is auto-detected from `AzureWebJobsScriptRoot` (set by `func start` and the Azure Functions host). You can override it with `create_function_app(app_root=Path(__file__).parent)` or the `AZURE_FUNCTIONS_AGENTS_APP_ROOT` env var.
|
|
101
|
+
|
|
102
|
+
### 3. Create `agents.config.yaml`
|
|
103
|
+
|
|
104
|
+
```yaml
|
|
105
|
+
# Default runtime configuration
|
|
106
|
+
model: $FOUNDRY_MODEL
|
|
107
|
+
timeout: 900
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 4. Create `host.json`
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"version": "2.0",
|
|
115
|
+
"extensions": {
|
|
116
|
+
"http": {
|
|
117
|
+
"routePrefix": ""
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"extensionBundle": {
|
|
121
|
+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
|
|
122
|
+
"version": "[4.*, 5.0.0)"
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 5. Create `requirements.txt`
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
azurefunctions-agents-runtime
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Connector-backed tools are exposed through MCP servers in `mcp.json`, and connector-triggered apps use the Azure Functions Connector Extension through the Functions extension bundle. No package extra is required.
|
|
134
|
+
|
|
135
|
+
### 6. Set the model provider
|
|
136
|
+
|
|
137
|
+
For local development with Microsoft Foundry, sign in with `az login`, then create `local.settings.json`:
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"IsEncrypted": false,
|
|
142
|
+
"Values": {
|
|
143
|
+
"FUNCTIONS_WORKER_RUNTIME": "python",
|
|
144
|
+
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
|
|
145
|
+
"AZURE_FUNCTIONS_AGENTS_PROVIDER": "foundry",
|
|
146
|
+
"FOUNDRY_PROJECT_ENDPOINT": "https://<project-name>.<region>.services.ai.azure.com/api/projects/<project-name>",
|
|
147
|
+
"FOUNDRY_MODEL": "gpt-5.4"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 7. Start Azurite (local storage emulator)
|
|
153
|
+
|
|
154
|
+
The MCP server endpoint and non-HTTP triggers (timer, queue, blob, etc.) require a storage account. Locally, use [Azurite](https://learn.microsoft.com/azure/storage/common/storage-use-azurite) via Docker:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
docker run -d --name azurite -p 10000:10000 -p 10001:10001 -p 10002:10002 \
|
|
158
|
+
mcr.microsoft.com/azure-storage/azurite \
|
|
159
|
+
azurite --skipApiVersionCheck --blobHost 0.0.0.0 --queueHost 0.0.0.0 --tableHost 0.0.0.0
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### 8. Run locally
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
func start
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Your agent is now running at `http://localhost:7071/agents/main/` with a built-in chat UI, HTTP API (`/agents/main/chat`, `/agents/main/chatstream`), and MCP tool exposed through the Functions MCP endpoint (`/runtime/webhooks/mcp`).
|
|
169
|
+
|
|
170
|
+
## Features
|
|
171
|
+
|
|
172
|
+
**Architecture overview:** see [`docs/architecture.md`](docs/architecture.md) for the module map and data flow pipeline.
|
|
173
|
+
|
|
174
|
+
### Built-in endpoints
|
|
175
|
+
|
|
176
|
+
Any `.agent.md` file can opt into built-in endpoints with `builtin_endpoints`. The route slug comes from the `.agent.md` filename after sanitization, not from the display `name:` field.
|
|
177
|
+
|
|
178
|
+
- **Debug chat UI** — built-in single-page web interface at `/agents/{slug}/`
|
|
179
|
+
- **HTTP APIs** — `POST /agents/{slug}/chat` (JSON) and `POST /agents/{slug}/chatstream` (SSE)
|
|
180
|
+
- **MCP tool** — optional tool exposed through `/runtime/webhooks/mcp` for VS Code, Claude Desktop, etc.
|
|
181
|
+
- **Session persistence** — multi-turn conversations stored in Azure Blob Storage via the runtime's `BlobHistoryProvider`, reusing the function app's `AzureWebJobsStorage` account
|
|
182
|
+
|
|
183
|
+
If any built-in endpoint is enabled, `trigger` is optional. This allows endpoint-only agents as well as triggered agents that also expose a chat UI or API. `builtin_endpoints.debug_chat_ui: true` automatically enables the backing chat APIs. `builtin_endpoints: true` is shorthand for enabling all built-in endpoints, including the MCP tool. See [`docs/front-matter-spec.md#builtin_endpoints`](docs/front-matter-spec.md#builtin_endpoints).
|
|
184
|
+
|
|
185
|
+
### Event-driven agents (`<name>.agent.md`)
|
|
186
|
+
|
|
187
|
+
Define event-triggered agents with `.agent.md` files. Each file corresponds to a single Azure Function. Supported trigger types:
|
|
188
|
+
|
|
189
|
+
- **Event triggers** — timer, queue, blob, Event Hub, Service Bus, Cosmos DB, Teams, Office 365, etc.
|
|
190
|
+
- **HTTP triggers** — expose agents as REST API endpoints; add `response_example` or `response_schema` for validated JSON responses
|
|
191
|
+
|
|
192
|
+
### Shared capabilities
|
|
193
|
+
- **Markdown-first** — agent instructions, trigger config, and tool bindings in `.agent.md` files
|
|
194
|
+
- **Skills** — progressive-disclosure prompt modules under `skills/<name>/SKILL.md` (loaded on demand via MAF's `SkillsProvider`)
|
|
195
|
+
- **Custom tools** — drop a `.py` file in `tools/`, decorate functions with `@tool`, and they become callable
|
|
196
|
+
- **Connector-backed MCP tools** — call Office 365, Teams, SQL, Salesforce, SAP, and other connectors through HTTP MCP servers
|
|
197
|
+
- **MCP servers** — connect to external remote HTTP MCP servers for additional tools
|
|
198
|
+
- **Sandbox** — Python code execution via Azure Container Apps dynamic sessions; if no explicit sandbox session id is supplied, each invocation gets a fresh GUID-backed session
|
|
199
|
+
|
|
200
|
+
## Agent File Format (`.agent.md`)
|
|
201
|
+
|
|
202
|
+
Agent files use YAML frontmatter + markdown body:
|
|
203
|
+
|
|
204
|
+
```yaml
|
|
205
|
+
---
|
|
206
|
+
name: Agent Name
|
|
207
|
+
description: What this agent does
|
|
208
|
+
|
|
209
|
+
# Optional: system tools (code execution)
|
|
210
|
+
system_tools:
|
|
211
|
+
dynamic_sessions_code_interpreter:
|
|
212
|
+
endpoint: $ACA_SESSION_POOL_ENDPOINT
|
|
213
|
+
|
|
214
|
+
# Optional when builtin_endpoints is enabled; required otherwise:
|
|
215
|
+
trigger:
|
|
216
|
+
type: timer_trigger # or queue_trigger, connector_trigger, etc.
|
|
217
|
+
args:
|
|
218
|
+
schedule: "0 0 9 * * *" # trigger-specific params passed as kwargs
|
|
219
|
+
|
|
220
|
+
logger: true # optional, default true
|
|
221
|
+
substitute_variables: true # optional, default true — env-var replacement in frontmatter + body
|
|
222
|
+
|
|
223
|
+
# For HTTP-triggered agents: expected response format
|
|
224
|
+
response_example: | # optional — agent returns structured JSON matching this example
|
|
225
|
+
{
|
|
226
|
+
"summary": "A brief summary",
|
|
227
|
+
"keywords": ["keyword1", "keyword2"]
|
|
228
|
+
}
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
Agent instructions in markdown...
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
> **Note**: Earlier preview releases supported a `runtime: copilot|maf` frontmatter field. As of 1.0.0 only Microsoft Agent Framework is used and the field is ignored (with a one-time warning per agent file). Remove it from your `.agent.md` files.
|
|
235
|
+
|
|
236
|
+
### Multiple functions from markdown
|
|
237
|
+
|
|
238
|
+
- **`*.agent.md` with `trigger`** — creates an event-triggered Azure Function. Exactly one trigger per file.
|
|
239
|
+
- **`*.agent.md` with `builtin_endpoints`** — also serves `/agents/{slug}/`, `/agents/{slug}/chat`, and `/agents/{slug}/chatstream` when chat endpoints are enabled, and can expose an MCP tool when `builtin_endpoints: true` or `builtin_endpoints.mcp: true`. The sanitized filename stem becomes the base Azure Function name and endpoint slug. If two agent files sanitize to the same name (for example, `daily-report.agent.md` and `daily_report.agent.md`), the runtime auto-suffixes both the Azure Function name and the built-in endpoint slug (`_2`, `_3`, ...), keeping them paired in practice (`daily_report_2` ↔ `/agents/daily_report_2/`). The frontmatter `name:` field is display-only. See [`docs/front-matter-spec.md#function-name-resolution`](docs/front-matter-spec.md#function-name-resolution) and [`docs/front-matter-spec.md#builtin_endpoints`](docs/front-matter-spec.md#builtin_endpoints).
|
|
240
|
+
|
|
241
|
+
When a triggered function runs, the agent's markdown body is used as the system instructions. The prompt sent to the agent includes the trigger type and the serialized binding data:
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
Triggered by: service_bus_queue_trigger
|
|
245
|
+
|
|
246
|
+
Trigger data:
|
|
247
|
+
```json
|
|
248
|
+
{"body": "...", "message_id": "...", ...}
|
|
249
|
+
```
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
This applies to all trigger types, including timers (whose data includes fields like `past_due`).
|
|
253
|
+
|
|
254
|
+
For a complete reference of all supported triggers and their parameters, see [docs/triggers.md](docs/triggers.md).
|
|
255
|
+
|
|
256
|
+
### Trigger type resolution
|
|
257
|
+
|
|
258
|
+
| Format | Resolves to | Example |
|
|
259
|
+
|---|---|---|
|
|
260
|
+
| `http_trigger` | Runtime HTTP adapter over `app.route(...)` | `http_trigger` |
|
|
261
|
+
| No dots | `app.<type>(...)` | `timer_trigger`, `queue_trigger` |
|
|
262
|
+
| `connector_trigger` | `app.connector_trigger(...)` | `connector_trigger` |
|
|
263
|
+
|
|
264
|
+
### HTTP-triggered agents
|
|
265
|
+
|
|
266
|
+
HTTP-triggered agents expose REST API endpoints that accept JSON input and return structured JSON output. Use `response_example` in the frontmatter to define the expected response format:
|
|
267
|
+
|
|
268
|
+
```yaml
|
|
269
|
+
---
|
|
270
|
+
name: Summarize
|
|
271
|
+
trigger:
|
|
272
|
+
type: http_trigger
|
|
273
|
+
args:
|
|
274
|
+
route: summarize
|
|
275
|
+
methods: ["POST"]
|
|
276
|
+
auth_level: FUNCTION # ANONYMOUS | FUNCTION | ADMIN (default: FUNCTION)
|
|
277
|
+
response_example: |
|
|
278
|
+
{
|
|
279
|
+
"summary": "A brief summary of the content",
|
|
280
|
+
"keywords": ["keyword1", "keyword2"],
|
|
281
|
+
"sentiment": "positive"
|
|
282
|
+
}
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
Analyze the provided content and return a structured summary.
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
The agent receives the HTTP request body as input and is instructed to return JSON matching the example. If `response_example` is omitted, the raw agent text is returned as `text/plain`.
|
|
289
|
+
|
|
290
|
+
`response_schema` (JSON Schema) is also supported as an alternative to `response_example` for advanced use cases.
|
|
291
|
+
|
|
292
|
+
### Environment variable substitution
|
|
293
|
+
|
|
294
|
+
`docs/front-matter-spec.md#environment-variable-substitution` is the authoritative reference. In short, the runtime resolves `$VAR` and `%VAR%` placeholders inline in every string value in `agents.config.yaml`, `mcp.json`, agent frontmatter values, and the markdown body (outside fenced code blocks). Missing variables are left as literal placeholders.
|
|
295
|
+
|
|
296
|
+
#### Agent instructions (markdown body)
|
|
297
|
+
|
|
298
|
+
Variable references are resolved inline at load time anywhere string values are supported. Both `$VAR_NAME` and `%VAR_NAME%` syntaxes are supported, where the identifier must match `[A-Za-z_][A-Za-z0-9_]*`:
|
|
299
|
+
|
|
300
|
+
```markdown
|
|
301
|
+
---
|
|
302
|
+
name: Notifier
|
|
303
|
+
description: Sends updates to $TEAM_NAME
|
|
304
|
+
system_tools:
|
|
305
|
+
dynamic_sessions_code_interpreter:
|
|
306
|
+
endpoint: "https://$HOST/api"
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
Send a daily summary email to $TO_EMAIL.
|
|
310
|
+
Post a message to the %TEAM_NAME% team's General channel.
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
If `HOST=contoso.internal`, `TO_EMAIL=alice@example.com`, and `TEAM_NAME=Engineering` are set in the environment, those values resolve inline:
|
|
314
|
+
|
|
315
|
+
> `endpoint: "https://contoso.internal/api"`
|
|
316
|
+
>
|
|
317
|
+
> Send a daily summary email to alice@example.com.
|
|
318
|
+
>
|
|
319
|
+
> Post a message to the Engineering team's General channel.
|
|
320
|
+
|
|
321
|
+
If a referenced variable is not set, the original `$VAR_NAME` or `%VAR_NAME%` text is left unchanged.
|
|
322
|
+
|
|
323
|
+
The runtime does **not** substitute dictionary keys, `${FOO}` brace syntax, identifiers starting with a digit such as `$9PORT`, or text inside fenced code blocks (`` ``` ``), so documentation examples in your instructions are preserved.
|
|
324
|
+
|
|
325
|
+
For the `$IDENT` syntax, identifiers that include characters outside `[A-Za-z0-9_]` (for example `$VAR-NAME`) are matched greedily up to the first invalid character — so `$VAR-NAME` resolves to `<value-of-VAR>-NAME` when `VAR` is set, and stays `$VAR-NAME` when `VAR` is unset. The `%IDENT%` syntax requires a closing `%` immediately after the identifier, so tokens like `%VAR-NAME%` remain fully literal. Quote or escape the surrounding text if you need a `$IDENT` token to remain literal.
|
|
326
|
+
|
|
327
|
+
To disable substitution for an agent's frontmatter values and markdown body, set `substitute_variables: false` in the frontmatter:
|
|
328
|
+
|
|
329
|
+
```yaml
|
|
330
|
+
---
|
|
331
|
+
name: My Agent
|
|
332
|
+
substitute_variables: false
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
Instructions with literal $VAR references that should not be replaced.
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
> **Note**: `substitute_variables` itself is read before env-var substitution. It must be a literal boolean (`true` or `false`). Setting `substitute_variables: $MY_FLAG` will not be resolved and defaults to `true`.
|
|
339
|
+
|
|
340
|
+
## Custom Python tools
|
|
341
|
+
|
|
342
|
+
Drop a `.py` file in `tools/` and decorate functions with `@tool`. The runtime auto-discovers them at import time and adds them to every agent.
|
|
343
|
+
|
|
344
|
+
```python
|
|
345
|
+
# tools/my_tools.py
|
|
346
|
+
from azure_functions_agents import tool
|
|
347
|
+
|
|
348
|
+
@tool
|
|
349
|
+
def reverse_string(text: str) -> str:
|
|
350
|
+
"""Reverse the input string."""
|
|
351
|
+
return text[::-1]
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
`@tool` is re-exported from `agent_framework`. Functions can be sync or async; types in the signature feed MAF's automatic JSON-Schema generation. Tools that need richer schemas can be declared with `agent_framework.FunctionTool` directly.
|
|
355
|
+
|
|
356
|
+
## Built-in Endpoint Routes
|
|
357
|
+
|
|
358
|
+
Built-in endpoints are explicit per agent. The filename stem determines `{slug}`; for example, `main.agent.md` uses `main` and `daily_azure_report.agent.md` uses `daily_azure_report`.
|
|
359
|
+
|
|
360
|
+
### Chat UI
|
|
361
|
+
|
|
362
|
+
A built-in single-page chat interface served at `/agents/{slug}/` when `builtin_endpoints.debug_chat_ui: true` (or `builtin_endpoints: true`). No frontend code needed — just open `http://localhost:7071/agents/main/` locally for `main.agent.md`, or `https://<your-app>.azurewebsites.net/agents/{slug}/` when deployed. See [`docs/front-matter-spec.md#function-name-resolution`](docs/front-matter-spec.md#function-name-resolution).
|
|
363
|
+
|
|
364
|
+
On first load, you'll be prompted for the base URL and a function key (for deployed apps). These are stored in browser local storage and can be changed via the gear icon.
|
|
365
|
+
|
|
366
|
+
### HTTP Chat API
|
|
367
|
+
|
|
368
|
+
POST endpoints for programmatic access:
|
|
369
|
+
|
|
370
|
+
- **Any agent with `builtin_endpoints.chat_api: true`:** `POST /agents/{slug}/chat` and `POST /agents/{slug}/chatstream`
|
|
371
|
+
|
|
372
|
+
The JSON endpoint returns `session_id`, `response`, and `tool_calls`. The streaming endpoint uses Server-Sent Events (SSE) with `session`, `delta`, `intermediate`, `tool_start`, `tool_end`, `done`, and `error` events.
|
|
373
|
+
|
|
374
|
+
Pass `x-ms-session-id` header to continue a conversation across requests. If omitted, a new session is created automatically.
|
|
375
|
+
|
|
376
|
+
### MCP Server
|
|
377
|
+
|
|
378
|
+
When `builtin_endpoints: true` or `builtin_endpoints.mcp: true`, the agent is exposed as an MCP tool named after its slug through the shared MCP-compatible endpoint at `/runtime/webhooks/mcp`. Requires the MCP extension system key in the `x-functions-key` header when deployed.
|
|
379
|
+
|
|
380
|
+
### Without built-in endpoints
|
|
381
|
+
|
|
382
|
+
If no agent enables built-in endpoints, no chat UI, chat API, chatstream, or agent MCP tool is registered. The app still runs triggered functions. See [`docs/front-matter-spec.md#builtin_endpoints`](docs/front-matter-spec.md#builtin_endpoints).
|
|
383
|
+
|
|
384
|
+
## MCP Server Configuration
|
|
385
|
+
|
|
386
|
+
You can give your agent access to external MCP servers by creating an `mcp.json` file in the app root. Only remote HTTP MCP servers are supported. The `type` field is optional — when omitted, an entry with a `url` is treated as HTTP. When `type` is specified it must be `"http"` or `"streamable-http"`; any other transport (e.g. `stdio`, `sse`) is rejected with a warning.
|
|
387
|
+
|
|
388
|
+
String values in `mcp.json` support inline environment-variable substitution with both `$VAR` and `%VAR%`. Eligible fields include `url`, `headers` values, `type`, `tools` entries, and Azure identity auth values such as `auth.scope` and `auth.client_id`. Dictionary keys such as server names, environment-variable names, and header names are not substituted.
|
|
389
|
+
|
|
390
|
+
```json
|
|
391
|
+
{
|
|
392
|
+
"servers": {
|
|
393
|
+
"microsoft-learn": {
|
|
394
|
+
"type": "http",
|
|
395
|
+
"url": "https://$MCP_HOST/api",
|
|
396
|
+
"headers": {
|
|
397
|
+
"Authorization": "Bearer $LEARN_MCP_TOKEN"
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
"custom-api": {
|
|
401
|
+
"type": "streamable-http",
|
|
402
|
+
"url": "https://example.com/mcp",
|
|
403
|
+
"headers": {
|
|
404
|
+
"Authorization": "Bearer $MCP_TOKEN"
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
"office365-outlook": {
|
|
408
|
+
"type": "http",
|
|
409
|
+
"url": "$O365_MCP_SERVER_URL",
|
|
410
|
+
"tools": ["office365_SendEmailV2"],
|
|
411
|
+
"auth": {
|
|
412
|
+
"scope": "https://apihub.azure.com/.default",
|
|
413
|
+
"client_id": "$O365_MCP_CLIENT_ID"
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
Tools from configured MCP servers are automatically available to the agent at runtime. Each server entry supports:
|
|
421
|
+
|
|
422
|
+
- **`type`** — optional. When set, must be `"http"` or `"streamable-http"`. When omitted, an entry with a `url` is treated as HTTP.
|
|
423
|
+
- **`url`** — the MCP server endpoint URL (required)
|
|
424
|
+
- **`headers`** — optional HTTP headers (e.g. for authentication)
|
|
425
|
+
- **`tools`** — optional array of tool name patterns to allow (default: `["*"]`)
|
|
426
|
+
- **`auth`** — optional Azure Identity authentication configuration. Set `auth.scope` to the token scope required by the MCP server. The runtime uses `DefaultAzureCredential` to acquire the token.
|
|
427
|
+
|
|
428
|
+
The runtime loads MCP tools and skips MCP prompts. This avoids startup/runtime failures from connector-backed MCP servers that support tools but reject `prompts/list`.
|
|
429
|
+
|
|
430
|
+
By default, MCP auth follows the app-wide identity selection: `AZURE_CLIENT_ID` when set, otherwise the system-assigned identity/default Azure credential chain. To choose a user-assigned managed identity for a single MCP server without changing the app-wide identity, set `auth.client_id` in that server's `mcp.json` entry. If the configured client ID is empty or an unresolved placeholder, the runtime falls back to the app-wide identity selection.
|
|
431
|
+
|
|
432
|
+
> **Note**: Entries without a `url`, with unresolved placeholders in `url`, or with a `type` other than `"http"` / `"streamable-http"`, are ignored with a warning. Use the remote HTTP transport instead.
|
|
433
|
+
|
|
434
|
+
## Session storage
|
|
435
|
+
|
|
436
|
+
Multi-turn conversations are persisted as JSON Lines, one record per message:
|
|
437
|
+
|
|
438
|
+
- **Deployed apps (recommended).** When `AzureWebJobsStorage` is configured —
|
|
439
|
+
as either a connection string or the identity-based
|
|
440
|
+
`AzureWebJobsStorage__blobServiceUri` setting that `azd` provisions —
|
|
441
|
+
history is written to **Azure Blob Storage** via the runtime's
|
|
442
|
+
`BlobHistoryProvider`. One Append Blob per session is stored under
|
|
443
|
+
`agent-sessions/{session_id}.jsonl` inside the
|
|
444
|
+
`azure-functions-agents` container (override with
|
|
445
|
+
`AZURE_FUNCTIONS_AGENTS_SESSION_CONTAINER`). No file share, no storage
|
|
446
|
+
account key, no mount path; the same identity that the function app
|
|
447
|
+
already uses for `AzureWebJobsStorage` reads and writes sessions. In
|
|
448
|
+
multi-identity Function Apps, set `AZURE_CLIENT_ID` so
|
|
449
|
+
`DefaultAzureCredential` selects the intended managed identity.
|
|
450
|
+
- **Local dev fallback.** When neither `AzureWebJobsStorage` nor
|
|
451
|
+
`AzureWebJobsStorage__blobServiceUri` is set, history falls back to MAF's
|
|
452
|
+
`FileHistoryProvider` writing to
|
|
453
|
+
`{AZURE_FUNCTIONS_AGENTS_SESSION_DIR}/agent-sessions/{session_id}.jsonl`,
|
|
454
|
+
defaulting to `~/.azure-functions-agents/agent-sessions/`.
|
|
455
|
+
|
|
456
|
+
Session ids must match `^[A-Za-z0-9._-]{1,128}$` — anything else is rejected at the API boundary.
|
|
457
|
+
|
|
458
|
+
> **Single-process scope**: A per-session `asyncio.Lock` serializes concurrent turns within a single Function instance. The contract is "one active turn per session id". Multi-instance distributed locking is intentionally out of scope.
|
|
459
|
+
|
|
460
|
+
## Samples
|
|
461
|
+
|
|
462
|
+
See the [`samples/`](samples/) directory for complete, deployable example apps:
|
|
463
|
+
|
|
464
|
+
- [`basic-chat`](samples/basic-chat) — minimal chat agent with sandbox
|
|
465
|
+
- [`daily-azure-report`](samples/daily-azure-report) — timer-triggered agent that emails a daily Azure status report
|
|
466
|
+
- [`daily-tech-news-email`](samples/daily-tech-news-email) — timer-triggered agent that scrapes news and emails a digest
|
|
467
|
+
- [`outlook-reply-agent`](samples/outlook-reply-agent) — connector-triggered agent that drafts replies to incoming Office 365 Outlook email
|
|
468
|
+
|
|
469
|
+
## Deployment Notes
|
|
470
|
+
|
|
471
|
+
### Required Azure App Settings
|
|
472
|
+
|
|
473
|
+
Set the model provider env vars described above. The preview samples use Microsoft Foundry (`AZURE_FUNCTIONS_AGENTS_PROVIDER=foundry`, `FOUNDRY_PROJECT_ENDPOINT`, and `FOUNDRY_MODEL`). Azure OpenAI (`AZURE_OPENAI_ENDPOINT` + `AZURE_OPENAI_DEPLOYMENT`) and OpenAI (`OPENAI_API_KEY` and optionally `AZURE_FUNCTIONS_AGENTS_MODEL`) are supported alternatives. For Microsoft Foundry and Azure OpenAI, the provider-specific model/deployment setting takes precedence over `AZURE_FUNCTIONS_AGENTS_MODEL`.
|
|
474
|
+
|
|
475
|
+
When the agent uses connector-backed MCP servers, connector triggers, or `dynamic_sessions_code_interpreter`, the function app's **system-assigned or user-assigned Managed Identity** must be enabled and granted access to the target resource — otherwise `DefaultAzureCredential` will fail to obtain a token. In multi-identity Function Apps, set `AZURE_CLIENT_ID` so the runtime uses the intended managed identity for Azure OpenAI, Foundry, blob-backed session storage, ACA Dynamic Sessions, and ARM/data-plane connector calls. For an individual MCP server, set `auth.client_id` in `mcp.json` to choose a different managed identity just for that server. For an individual code interpreter pool, set `system_tools.dynamic_sessions_code_interpreter.client_id`.
|
|
476
|
+
|
|
477
|
+
### Optional config overrides
|
|
478
|
+
|
|
479
|
+
| Setting | Purpose |
|
|
480
|
+
|---|---|
|
|
481
|
+
| `AZURE_FUNCTIONS_AGENTS_APP_ROOT` | Override the app root used to discover `*.agent.md`, `tools/`, `skills/`, and `mcp.json` |
|
|
482
|
+
| `AZURE_FUNCTIONS_AGENTS_SESSION_DIR` | Override the directory used for local session storage |
|
|
483
|
+
| `AZURE_FUNCTIONS_AGENTS_TIMEOUT_SECONDS` | Per-call timeout in seconds (default `900`) |
|
|
484
|
+
| `AZURE_FUNCTIONS_AGENTS_PROVIDER` | Pin the model provider (`openai`/`azure_openai`/`foundry`) and skip auto-detection |
|
|
485
|
+
| `AZURE_FUNCTIONS_AGENTS_MODEL` | Runtime-owned model fallback when no provider-specific model/deployment is set |
|
|
486
|
+
| `AZURE_FUNCTIONS_AGENTS_REASONING_EFFORT` | Optional reasoning effort for supported reasoning models (valid values include `none`, `low`, `medium`, `high`, `xhigh`) |
|
|
487
|
+
| `AZURE_FUNCTIONS_AGENTS_REASONING_SUMMARY` | Optional reasoning summary mode for supported reasoning models (valid values are `auto`, `concise`, `detailed`) |
|
|
488
|
+
|
|
489
|
+
## Development
|
|
490
|
+
|
|
491
|
+
```bash
|
|
492
|
+
# Clone the repo
|
|
493
|
+
git clone https://github.com/Azure/azure-functions-agents-runtime.git
|
|
494
|
+
cd azure-functions-agents-runtime
|
|
495
|
+
|
|
496
|
+
# Install in development mode
|
|
497
|
+
pip install -e .
|
|
498
|
+
|
|
499
|
+
# Build a wheel
|
|
500
|
+
pip install build
|
|
501
|
+
python -m build --wheel
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
## Contributing
|
|
505
|
+
|
|
506
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
507
|
+
|
|
508
|
+
## License
|
|
509
|
+
|
|
510
|
+
MIT — see [LICENSE.md](LICENSE.md).
|