.NET: Friendly error message when durable agent isn't registered (#2214)

* .NET: Friendly error message when durable agent isn't registered

* Updates

* Fix file encoding

* Add validation for durable agent proxies

* Copilot PR feedback
This commit is contained in:
Chris Gillum
2025-11-14 19:28:07 +00:00
committed by GitHub
parent c1786b38a7
commit 939c2d69f9
7 changed files with 223 additions and 4 deletions
@@ -21,6 +21,12 @@ public static class DurableTaskClientExtensions
/// <returns>A durable agent proxy.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="durableClient"/> or <paramref name="context"/> is null.</exception>
/// <exception cref="ArgumentException">Thrown when <paramref name="agentName"/> is null or empty.</exception>
/// <exception cref="InvalidOperationException">
/// Thrown when durable agents have not been configured on the service collection.
/// </exception>
/// <exception cref="AgentNotRegisteredException">
/// Thrown when the agent has not been registered.
/// </exception>
public static AIAgent AsDurableAgentProxy(
this DurableTaskClient durableClient,
FunctionContext context,
@@ -30,6 +36,9 @@ public static class DurableTaskClientExtensions
ArgumentNullException.ThrowIfNull(context);
ArgumentException.ThrowIfNullOrEmpty(agentName);
// Validate that the agent is registered
DurableTask.ServiceCollectionExtensions.ValidateAgentIsRegistered(context.InstanceServices, agentName);
DefaultDurableAgentClient agentClient = ActivatorUtilities.CreateInstance<DefaultDurableAgentClient>(
context.InstanceServices,
durableClient);