Files
agent-framework/python/samples/01-get-started/06_host_your_agent.py
T
Evan Mattson d8b9409e96 Python: (ag-ui): Add Workflow Support, Harden Streaming Semantics, and add Dynamic Handoff Demo (#3911)
* fix Workflow.as_agent() streaming regression in ag-ui

* Address PR feedback

* workflows wip

* wip

* wip

* Workflow AG-UI demo

* Fixes for handoff workflow demo

* Fixes to workflows support in AG-UI

* Fixes

* Add headers to some demo files

* Fix comment

* Fixes for store

* Make _input_schema lazy-loaded

* fix mypy

* revert session change to handoff only for now

---------

Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com>
2026-02-23 11:59:56 +00:00

47 lines
1.2 KiB
Python

# Copyright (c) Microsoft. All rights reserved.
from typing import Any
from agent_framework.azure import AgentFunctionApp, AzureOpenAIChatClient
from azure.identity import AzureCliCredential
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
"""Host your agent with Azure Functions.
This sample shows the Python hosting pattern used in docs:
- Create an agent with `AzureOpenAIChatClient`
- Register it with `AgentFunctionApp`
- Run with Azure Functions Core Tools (`func start`)
Prerequisites:
pip install agent-framework-azurefunctions --pre
Environment variables:
AZURE_OPENAI_ENDPOINT
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME
"""
# <create_agent>
def _create_agent() -> Any:
"""Create a hosted agent backed by Azure OpenAI."""
return AzureOpenAIChatClient(credential=AzureCliCredential()).as_agent(
name="HostedAgent",
instructions="You are a helpful assistant hosted in Azure Functions.",
)
# </create_agent>
# <host_agent>
app = AgentFunctionApp(agents=[_create_agent()], enable_health_check=True, max_poll_retries=50)
# </host_agent>
if __name__ == "__main__":
print("Start the Functions host with: func start")
print("Then call: POST /api/agents/HostedAgent/run")