In
the previous post: Microsoft Agent Framework: Agents on Azure Functions with .NET, we had a look at hosting an Agent on Azure Functions using
Microsoft Agent Framework, backed by Azurite for local
Durable Functions state. In this post, let's swap that backend for
Durable Task Scheduler (DTS) and see what it brings.
If you haven't read my earlier posts on DTS, those cover the backend
itself in detail, well worth reading first:
- Migrating Azure Durable Function App to Use Durable Task Scheduler: Running Locally
- Migrating Azure Durable Function App to Use Durable Task Scheduler: Running in Azure
In short: DTS is a managed orchestration backend for
Durable Functions. Compared to the default Azure Storage backend, we
get a managed task hub, better throughput, a built-in dashboard for inspecting
orchestrations and their history, and new and especially relevant for us
an Agents tab for inspecting agent threads directly.
The only changes
The agent code from the previous post doesn't change at all. The HTTP
endpoint, the tools, all stay exactly the same.
We only touch three files (versions are the latest as of today, they will
change):
Add the DTS extension package to the .csproj:
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask.AzureManaged" Version="1.8.1" />
Point the durableTask extension at DTS in host.json:
{
"version": "2.0",
"extensions": {
"durableTask": {
"hubName": "%TASKHUB_NAME%",
"storageProvider": {
"type": "azureManaged",
"connectionStringName": "DTS_CONNECTION_STRING"
}
}
}
}
And add the two values in local.settings.json:
"DTS_CONNECTION_STRING": "Endpoint=http://localhost:8080;Authentication=None", "TASKHUB_NAME": "default",
For local development, I'm running the DTS emulator via Docker on port
8080, setting that up is covered in the first DTS post linked
above.
What we get
Run the Functions host and fire the same HTTP request from the previous post:
POST http://localhost:7099/api/agents/weekend-planner/run
Content-Type: application/json
{
"message": "What should I do this weekend in Auckland?"
}
The response and behavior is exactly what we had before.
But now, when we open the DTS emulator dashboard, we can see the
something like following.
|
|
| Entities |
In the Entities tab, behind the scenes, the framework stores each
agent thread as a Durable Entity, one entity per session, so the
conversation state survives restarts and can be picked up on the next turn.
We don't write any of this code ourselves; it's how the hosting package
persists state on top of DTS:
|
|
| Agents |
The more interesting view for us is the new Agents tab (currently in
preview). It lists each agent session on its own row, so the
same agent will appear multiple times if it has handled multiple
conversations, one row per session. From here we can jump into any session:
|
|
| Agents Detail |
Under Agents is where it really pays off. The dashboard shows the
token usage for the whole conversation, a Timeline with each
prompt and response, and the tool calls the agent made for each
exchange, GetCurrentDate, GetWeather,
GetActivities and each marked done. There's also a
Chat History tab if we prefer the linear message view. For debugging
agent flows, this is exactly the kind of view we'd previously have had to
build ourselves.
This is one of the nicer things about the Functions hosting story for
Microsoft Agent Framework, because agent conversations are
modeled as Durable Functions orchestrations, anything that improves the
Durable stack (like DTS) improves the agent experience for free.
Complete source code:
Read more:
Hope this helps.
Happy Coding.
Regards,
Jaliya
No comments:
Post a Comment