mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.NET: Added support for polymorphic type as workflow output (#4485)
* Added support for polymorphic type as workflow output * Update Linq expression to avoid unnecessary allocations. * Added caching as per PR comment
This commit is contained in:
committed by
GitHub
Unverified
parent
09b3e2e4f0
commit
a3bfad4791
@@ -3,6 +3,7 @@
|
||||
#pragma warning disable CS0618 // Type or member is obsolete - Internal use of obsolete types for backward compatibility
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
@@ -133,7 +134,25 @@ internal sealed class ExecutorProtocol(MessageRouter router, ISet<Type> sendType
|
||||
|
||||
public bool CanHandle(Type type) => router.CanHandle(type);
|
||||
|
||||
public bool CanOutput(Type type) => this._yieldTypes.Contains(new(type));
|
||||
private readonly ConcurrentDictionary<Type, bool> _canOutputCache = new();
|
||||
|
||||
public bool CanOutput(Type type)
|
||||
{
|
||||
return this._canOutputCache.GetOrAdd(type, this.CanOutputCore);
|
||||
}
|
||||
|
||||
private bool CanOutputCore(Type type)
|
||||
{
|
||||
foreach (TypeId yieldType in this._yieldTypes)
|
||||
{
|
||||
if (yieldType.IsMatchPolymorphic(type))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public ProtocolDescriptor Describe() => new(this.Router.IncomingTypes, yieldTypes, sendTypes, this.Router.HasCatchAll);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user