Skip to content

Commit

Permalink
messing around
Browse files Browse the repository at this point in the history
  • Loading branch information
rysweet committed Nov 22, 2024
1 parent ed4a097 commit 72552a7
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<string> HandledEvents { get; set; } = new();
public List<string> EmittedEvents { get; set; } = new();
}
public List<AgentInfo> InspectAgents()
{
var agents = new List<AgentInfo>();
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<string> 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<string>();
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;
}
}

0 comments on commit 72552a7

Please sign in to comment.