azurefunctions-agents-runtime 0.0.0.dev1__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. azurefunctions_agents_runtime-0.0.0.dev1/LICENSE.md +21 -0
  2. azurefunctions_agents_runtime-0.0.0.dev1/PKG-INFO +386 -0
  3. azurefunctions_agents_runtime-0.0.0.dev1/README.md +369 -0
  4. azurefunctions_agents_runtime-0.0.0.dev1/pyproject.toml +26 -0
  5. azurefunctions_agents_runtime-0.0.0.dev1/setup.cfg +4 -0
  6. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/__init__.py +20 -0
  7. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/app.py +720 -0
  8. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/arm.py +95 -0
  9. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/client_manager.py +84 -0
  10. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/config.py +191 -0
  11. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/connector_tool_cache.py +124 -0
  12. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/connector_tools.py +267 -0
  13. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/connectors.py +460 -0
  14. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/mcp.py +87 -0
  15. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/public/index.html +1504 -0
  16. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/runner.py +406 -0
  17. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/sandbox.py +288 -0
  18. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/skills.py +24 -0
  19. azurefunctions_agents_runtime-0.0.0.dev1/src/azure_functions_agents/tools.py +316 -0
  20. azurefunctions_agents_runtime-0.0.0.dev1/src/azurefunctions_agents_runtime.egg-info/PKG-INFO +386 -0
  21. azurefunctions_agents_runtime-0.0.0.dev1/src/azurefunctions_agents_runtime.egg-info/SOURCES.txt +23 -0
  22. azurefunctions_agents_runtime-0.0.0.dev1/src/azurefunctions_agents_runtime.egg-info/dependency_links.txt +1 -0
  23. azurefunctions_agents_runtime-0.0.0.dev1/src/azurefunctions_agents_runtime.egg-info/requires.txt +7 -0
  24. azurefunctions_agents_runtime-0.0.0.dev1/src/azurefunctions_agents_runtime.egg-info/top_level.txt +2 -0
  25. azurefunctions_agents_runtime-0.0.0.dev1/src/copilot_functions/__init__.py +3 -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,386 @@
1
+ Metadata-Version: 2.4
2
+ Name: azurefunctions-agents-runtime
3
+ Version: 0.0.0.dev1
4
+ Summary: A markdown-first programming model for building AI agents on Azure Functions with the GitHub Copilot SDK.
5
+ License: MIT
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE.md
9
+ Requires-Dist: azure-functions>=1.24.0
10
+ Requires-Dist: github-copilot-sdk>=0.2.1
11
+ Requires-Dist: pydantic>=2.0.0
12
+ Requires-Dist: python-frontmatter>=1.1.0
13
+ Requires-Dist: azurefunctions-extensions-http-fastapi
14
+ Requires-Dist: aiohttp>=3.9.0
15
+ Requires-Dist: azure-identity>=1.15.0
16
+ Dynamic: license-file
17
+
18
+ # azure-functions-agents (Experimental)
19
+
20
+ > **⚠️ This is an experimental package.** The APIs described here are under active development and subject to change.
21
+
22
+ A markdown-first programming model for building AI agents on Azure Functions with the [GitHub Copilot SDK](https://github.com/github/copilot-sdk).
23
+
24
+ - **Build agents with markdown** — write instructions, configure triggers, and bind tools in `.agent.md` files
25
+ - **Run on any Azure Functions trigger** — trigger agents on timer, queue, blob, HTTP, Event Hub, Service Bus, Cosmos DB, and more
26
+ - **Connect to 1,400+ services** — Azure API Connections let agents trigger on and perform actions across Office 365, Teams, SQL, Salesforce, SAP, and hundreds of other connectors — no custom code required
27
+ - **Extend with MCP servers** — plug in remote HTTP MCP servers for additional capabilities
28
+ - **Build custom tools in plain Python** — when connectors and MCP aren't enough, drop a `.py` file in `tools/` and pull in any package you need
29
+ - **Automatic HTTP and MCP endpoints** — optionally expose your agent as an HTTP chat API and MCP server with no extra code
30
+ - **Serverless with built-in session management** — scales to zero, persists multi-turn conversations across instances on Azure Files
31
+
32
+ ## Installation
33
+
34
+ ### From a GitHub release (`.whl`)
35
+
36
+ Install directly from the release URL:
37
+
38
+ ```bash
39
+ pip install https://github.com/anthonychu/azure-functions-agents/releases/download/v0.7.1/azure_functions_agents-0.7.1-py3-none-any.whl
40
+ ```
41
+
42
+ ### From the GitHub repo
43
+
44
+ ```bash
45
+ pip install azure-functions-agents @ git+https://github.com/anthonychu/azure-functions-agents.git
46
+ ```
47
+
48
+ ### With connector tools support
49
+
50
+ Connector tools (Teams, Office 365, SQL, Salesforce, etc.) require an optional extra:
51
+
52
+ ```bash
53
+ # From release URL
54
+ pip install "azure-functions-agents[connectors] @ https://github.com/anthonychu/azure-functions-agents/releases/download/v0.7.1/azure_functions_agents-0.7.1-py3-none-any.whl"
55
+
56
+ # From repo
57
+ pip install "azure-functions-agents[connectors] @ git+https://github.com/anthonychu/azure-functions-agents.git"
58
+ ```
59
+
60
+ ## GitHub Token
61
+
62
+ The Copilot SDK requires a GitHub Personal Access Token (PAT) to authenticate with the GitHub Copilot API.
63
+
64
+ 1. Go to [github.com/settings/tokens](https://github.com/settings/tokens?type=beta) and click **Generate new token** (fine-grained)
65
+ 2. Give the token a name (e.g. `azure-functions-agents`)
66
+ 3. Under **Permissions**, select **Add permissions**, then select **Copilot requests**, and set it to **Read-only**
67
+ 4. Click **Generate token** and copy the value
68
+
69
+ Set it as the `GITHUB_TOKEN` environment variable (or pass it via `local.settings.json` / `azd env set` when deploying).
70
+
71
+ ## Quick Start
72
+
73
+ ### 1. Create the agent file
74
+
75
+ Create `main.agent.md`:
76
+
77
+ ```markdown
78
+ ---
79
+ name: My Agent
80
+ description: A helpful assistant
81
+ ---
82
+
83
+ You are a helpful assistant. Answer questions concisely.
84
+ ```
85
+
86
+ ### 2. Create the function app entry point
87
+
88
+ Create `function_app.py`:
89
+
90
+ ```python
91
+ from azure_functions_agents import create_function_app
92
+
93
+ app = create_function_app()
94
+ ```
95
+
96
+ > 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 `COPILOT_APP_ROOT` env var.
97
+
98
+ ### 3. Create `host.json`
99
+
100
+ ```json
101
+ {
102
+ "version": "2.0",
103
+ "extensions": {
104
+ "http": {
105
+ "routePrefix": ""
106
+ }
107
+ },
108
+ "extensionBundle": {
109
+ "id": "Microsoft.Azure.Functions.ExtensionBundle",
110
+ "version": "[4.*, 5.0.0)"
111
+ }
112
+ }
113
+ ```
114
+
115
+ ### 4. Create `requirements.txt`
116
+
117
+ ```
118
+ https://github.com/anthonychu/azure-functions-agents/releases/download/v0.7.1/azure_functions_agents-0.7.1-py3-none-any.whl
119
+ ```
120
+
121
+ Or use any other install method from the [Installation](#installation) section.
122
+
123
+ ### 5. Start Azurite (local storage emulator)
124
+
125
+ 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:
126
+
127
+ ```bash
128
+ docker run -d --name azurite -p 10000:10000 -p 10001:10001 -p 10002:10002 \
129
+ mcr.microsoft.com/azure-storage/azurite \
130
+ azurite --skipApiVersionCheck --blobHost 0.0.0.0 --queueHost 0.0.0.0 --tableHost 0.0.0.0
131
+ ```
132
+
133
+ Then set the storage connection string in `local.settings.json`:
134
+
135
+ ```json
136
+ {
137
+ "IsEncrypted": false,
138
+ "Values": {
139
+ "FUNCTIONS_WORKER_RUNTIME": "python",
140
+ "AzureWebJobsStorage": "UseDevelopmentStorage=true"
141
+ }
142
+ }
143
+ ```
144
+
145
+ ### 6. Run locally
146
+
147
+ ```bash
148
+ func start
149
+ ```
150
+
151
+ Your agent is now running at `http://localhost:7071/` with a built-in chat UI, HTTP API (`/agent/chat`, `/agent/chatstream`), and MCP server (`/runtime/webhooks/mcp`).
152
+
153
+ ## Features
154
+
155
+ ### `main.agent.md`
156
+
157
+ Define an agent with a markdown file. When `main.agent.md` is present, the runtime automatically registers:
158
+
159
+ - **Chat UI** — built-in single-page web interface at the app root
160
+ - **HTTP APIs** — `POST /agent/chat` (JSON) and `POST /agent/chatstream` (SSE)
161
+ - **MCP server** — `/runtime/webhooks/mcp` for VS Code, Claude Desktop, etc.
162
+ - **Session persistence** — multi-turn conversations stored on Azure Files
163
+
164
+ ### Event-driven agents (`<name>.agent.md`)
165
+
166
+ Define event-triggered agents with `.agent.md` files. Each file corresponds to a single Azure Function. Supported trigger types:
167
+
168
+ - **Event triggers** — timer, queue, blob, Event Hub, Service Bus, Cosmos DB, Teams, Office 365, etc.
169
+ - **HTTP triggers** — expose agents as REST API endpoints with structured JSON responses via `response_example`
170
+
171
+ ### Shared capabilities
172
+ - **Markdown-first** — agent instructions, trigger config, and tool bindings in `.agent.md` files
173
+ - **Skills** — reusable prompt modules from `SKILL.md` files
174
+ - **Custom tools** — drop a `.py` file in `tools/` and it becomes a callable tool
175
+ - **Connector tools** — dynamically generated tools from Azure API Connections
176
+ - **MCP servers** — connect to external MCP servers for additional tools
177
+ - **Sandbox** — code execution via Azure Container Apps dynamic sessions with Playwright web browsing support
178
+
179
+ ## Agent File Format (`.agent.md`)
180
+
181
+ Agent files use YAML frontmatter + markdown body:
182
+
183
+ ```yaml
184
+ ---
185
+ name: Agent Name
186
+ description: What this agent does
187
+
188
+ # Optional: connector tools
189
+ tools_from_connections:
190
+ - connection_id: $SQL_CONNECTION_ID
191
+ prefix: sales_db # optional
192
+
193
+ # Optional: code interpreter
194
+ execution_sandbox:
195
+ session_pool_management_endpoint: $ACA_SESSION_POOL_ENDPOINT
196
+
197
+ # For triggered agents only (not `main.agent.md`):
198
+ trigger:
199
+ type: timer_trigger # or queue_trigger, teams.new_channel_message_trigger, etc.
200
+ schedule: "0 0 9 * * *" # trigger-specific params passed as kwargs
201
+
202
+ logger: true # optional, default true
203
+ substitute_variables: true # optional, default true — inline $VAR / %VAR% replacement in body
204
+
205
+ # For HTTP-triggered agents: expected response format
206
+ response_example: | # optional — agent returns structured JSON matching this example
207
+ {
208
+ "summary": "A brief summary",
209
+ "keywords": ["keyword1", "keyword2"]
210
+ }
211
+ ---
212
+
213
+ Agent instructions in markdown...
214
+ ```
215
+
216
+ ### Multiple functions from markdown
217
+
218
+ - **`main.agent.md`** — creates HTTP chat, MCP, and UI endpoints. No other triggers are supported in this file.
219
+ - **`<name>.agent.md`** — creates an event-triggered Azure Function. Exactly one trigger per file. The filename (minus `.agent.md`) becomes the function name.
220
+
221
+ 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:
222
+
223
+ ```
224
+ Triggered by: service_bus_queue_trigger
225
+
226
+ Trigger data:
227
+ ```json
228
+ {"body": "...", "message_id": "...", ...}
229
+ ```​
230
+ ```
231
+
232
+ This applies to all trigger types, including timers (whose data includes fields like `past_due`).
233
+
234
+ For a complete reference of all supported triggers and their parameters, see [docs/triggers.md](docs/triggers.md).
235
+
236
+ ### Trigger type resolution
237
+
238
+ | Format | Resolves to | Example |
239
+ |---|---|---|
240
+ | `http_trigger` | `app.route(...)` with structured JSON response | `http_trigger` |
241
+ | No dots | `app.<type>(...)` | `timer_trigger`, `queue_trigger` |
242
+ | Dots | Connector library method | `teams.new_channel_message_trigger` |
243
+ | `connectors.` prefix | Explicit connector method | `connectors.generic_trigger` |
244
+
245
+ ### HTTP-triggered agents
246
+
247
+ 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:
248
+
249
+ ```yaml
250
+ ---
251
+ name: Summarize
252
+ trigger:
253
+ type: http_trigger
254
+ route: summarize
255
+ methods: ["POST"]
256
+ auth_level: FUNCTION # ANONYMOUS | FUNCTION | ADMIN (default: FUNCTION)
257
+ response_example: |
258
+ {
259
+ "summary": "A brief summary of the content",
260
+ "keywords": ["keyword1", "keyword2"],
261
+ "sentiment": "positive"
262
+ }
263
+ ---
264
+
265
+ Analyze the provided content and return a structured summary.
266
+ ```
267
+
268
+ 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`.
269
+
270
+ `response_schema` (JSON Schema) is also supported as an alternative to `response_example` for advanced use cases.
271
+
272
+ ### Environment variable substitution
273
+
274
+ #### Frontmatter values
275
+
276
+ String values in `trigger.*` (except `type`), `tools_from_connections[].connection_id`, and `execution_sandbox.session_pool_management_endpoint` support `$VAR` or `%VAR%` syntax (full-string match only).
277
+
278
+ #### Agent instructions (markdown body)
279
+
280
+ Variable references in the agent's markdown body are replaced **inline** with environment variable values at load time. Both `$VAR_NAME` and `%VAR_NAME%` syntaxes are supported:
281
+
282
+ ```markdown
283
+ ---
284
+ name: Notifier
285
+ ---
286
+
287
+ Send a daily summary email to $TO_EMAIL.
288
+ Post a message to the %TEAM_NAME% team's General channel.
289
+ ```
290
+
291
+ If `TO_EMAIL=alice@example.com` and `TEAM_NAME=Engineering` are set in the environment, the agent instructions become:
292
+
293
+ > Send a daily summary email to alice@example.com.
294
+ > Post a message to the Engineering team's General channel.
295
+
296
+ If a referenced variable is not set, the original `$VAR_NAME` or `%VAR_NAME%` text is left unchanged.
297
+
298
+ Text inside fenced code blocks (`` ``` ``) is **not** substituted, so documentation examples in your instructions are preserved.
299
+
300
+ To disable substitution for an agent, set `substitute_variables: false` in the frontmatter:
301
+
302
+ ```yaml
303
+ ---
304
+ name: My Agent
305
+ substitute_variables: false
306
+ ---
307
+
308
+ Instructions with literal $VAR references that should not be replaced.
309
+ ```
310
+
311
+ ## What `main.agent.md` Enables
312
+
313
+ When a `main.agent.md` file exists in your app root, the runtime automatically registers:
314
+
315
+ ### Chat UI
316
+
317
+ A built-in single-page chat interface served at the app root (`/`). No frontend code needed — just open `http://localhost:7071/` locally or `https://<your-app>.azurewebsites.net/` when deployed.
318
+
319
+ 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.
320
+
321
+ ### HTTP Chat API
322
+
323
+ Two POST endpoints for programmatic access:
324
+
325
+ - **`POST /agent/chat`** — JSON request/response. Returns `session_id`, `response`, and `tool_calls`.
326
+ - **`POST /agent/chatstream`** — streaming Server-Sent Events (SSE). Returns incremental text chunks, tool execution events, and a final message.
327
+
328
+ Pass `x-ms-session-id` header to continue a conversation across requests. If omitted, a new session is created automatically.
329
+
330
+ ### MCP Server
331
+
332
+ An MCP-compatible endpoint at `/runtime/webhooks/mcp` that any MCP client (VS Code, Claude Desktop, etc.) can connect to. Requires the MCP extension system key in the `x-functions-key` header when deployed.
333
+
334
+ ### Without `main.agent.md`
335
+
336
+ If there's no `main.agent.md`, the HTTP chat, MCP, and UI endpoints are all disabled. The app only runs triggered functions.
337
+
338
+ ## MCP Server Configuration
339
+
340
+ You can give your agent access to external MCP servers by creating an `mcp.json` file in the app root. Only **HTTP remote servers** are supported.
341
+
342
+ ```json
343
+ {
344
+ "servers": {
345
+ "microsoft-learn": {
346
+ "type": "http",
347
+ "url": "https://learn.microsoft.com/api/mcp"
348
+ }
349
+ }
350
+ }
351
+ ```
352
+
353
+ Tools from configured MCP servers are automatically available to the agent at runtime. Each server entry supports:
354
+
355
+ - **`type`** — `"http"` (required)
356
+ - **`url`** — the MCP server endpoint URL
357
+ - **`headers`** — optional HTTP headers (e.g. for authentication)
358
+ - **`tools`** — optional array of tool name patterns to allow (default: `["*"]`)
359
+
360
+ ## Samples
361
+
362
+ See the [`samples/`](samples/) directory for complete, deployable example apps.
363
+
364
+ ## Development
365
+
366
+ ```bash
367
+ # Clone the repo
368
+ git clone https://github.com/anthonychu/azure-functions-agents.git
369
+ cd azure-functions-agents
370
+
371
+ # Install in development mode
372
+ pip install -e ".[connectors]"
373
+
374
+ # Build a wheel
375
+ pip install build
376
+ python -m build --wheel
377
+ # Output: dist/azure_functions_agents-0.7.1-py3-none-any.whl
378
+ ```
379
+
380
+ ## Contributing
381
+
382
+ See [CONTRIBUTING.md](CONTRIBUTING.md).
383
+
384
+ ## License
385
+
386
+ MIT — see [LICENSE.md](LICENSE.md).