diff --git a/dotnet/src/Microsoft.AutoGen/Extensions/AgentInspector/AgentInspector.cs b/dotnet/src/Microsoft.AutoGen/Extensions/AgentInspector/AgentInspector.cs new file mode 100644 index 00000000000..d4b0de245e9 --- /dev/null +++ b/dotnet/src/Microsoft.AutoGen/Extensions/AgentInspector/AgentInspector.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Microsoft.AutoGen.Agents; + +namespace Microsoft.AutoGen.Extensions.AgentInspector; + +public class AgentInspector +{ + public class AgentInfo(ISubscriptionsGrain subscriptionsGrain) + { + public string AgentName { get; set; } + public List HandledEvents { get; set; } = new(); + public List EmittedEvents { get; set; } = new(); + } + public List InspectAgents() + { + var agents = new List(); + var _subscriptions = subscriptionsGrain.GetSubscriptions().Result; + foreach (var agent in _subscriptions) + { + var agentInfo = new AgentInfo + { + AgentName = agent.Key + HandledEvents = agent.Value + EmittedEvents = GetEmittedEvents(agent.Key) + }; + agents.Add(agentInfo); + } + return agents; + } + private List GetEmittedEvents(string agentName) + { + // we learn what events an agent can omit by scanning all its methods and looking for calls to PublishMessage or PublishEvent and determining hat types are passed to them. + var agentType = Type.GetType(agentName); + var emittedEvents = new List(); + foreach (var method in agentType.GetMethods()) + { + // does this method call PublishMessageAsync or PublishEventAsync? + + var body = method.GetMethodBody(); + + if (body != null) + { + // does the content of this method include a call to PublishMessageAsync or PublishEventAsync? + var il = body.GetILAsByteArray(); + + + } + + return emittedEvents; + } +} \ No newline at end of file