Skip to content

A programming framework for agentic AI

feat: Make the python interface more correct

Jacob Alber51dbe6cd6d56
diff --git a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/AgentId.cs b/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/AgentId.cs
index 440436c1e..0bd9f6d3e 100644
--- a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/AgentId.cs
+++ b/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/AgentId.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// PythonInterfaces.cs
using System.Diagnostics;
diff --git a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/AgentProxy.cs b/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/AgentProxy.cs
index 8c11214bf..4e174c8b9 100644
--- a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/AgentProxy.cs
+++ b/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/AgentProxy.cs
@@ -4,7 +4,7 @@
namespace Microsoft.AutoGen.Contracts.Python;
-public class AgentProxy(AgentId agentId, IAgentRuntime runtime) //: IAgent
+public class AgentProxy(AgentId agentId, IAgentRuntime runtime)
{
private IAgentRuntime runtime = runtime;
public AgentId Id = agentId;
@@ -16,18 +16,19 @@ public class AgentProxy(AgentId agentId, IAgentRuntime runtime) //: IAgent
public AgentMetadata Metadata => this.ExecuteAndUnwrap(runtime => runtime.GetAgentMetadataAsync(this.Id));
- public ValueTask LoadStateAsync(IDictionary<string, object> state)
+ // TODO: make this optional
+ public ValueTask<object> SendMessageAsync(object message, AgentId sender, string? messageId = null, CancellationToken? cancellationToken = default)
{
- throw new NotImplementedException();
+ return this.runtime.SendMessageAsync(message, this.Id, sender, messageId, cancellationToken);
}
- public ValueTask<object> OnMessageAsync(object message, MessageContext messageContext)
+ public ValueTask LoadStateAsync(IDictionary<string, object> state)
{
- throw new NotImplementedException();
+ return this.runtime.LoadAgentStateAsync(state);
}
public ValueTask<IDictionary<string, object>> SaveStateAsync()
{
- throw new NotImplementedException();
+ return this.runtime.SaveAgentStateAsync();
}
}
diff --git a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/IAgentRuntime.cs b/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/IAgentRuntime.cs
index d819cc4af..4c39cd872 100644
--- a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/IAgentRuntime.cs
+++ b/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/IAgentRuntime.cs
@@ -7,15 +7,16 @@ namespace Microsoft.AutoGen.Contracts.Python;
public interface IAgentRuntime : ISaveState<IAgentRuntime>
{
- public ValueTask<object> SendMessage(object message, AgentId recepient, AgentId? sender = null, string? messageId = null, CancellationToken? cancellationToken = default);
- public ValueTask<object> PublishMessage(object message, TopicId topic, AgentId? sender = null, string? messageId = null, CancellationToken? cancellationToken = default);
+ public ValueTask<object> SendMessageAsync(object message, AgentId recepient, AgentId? sender = null, string? messageId = null, CancellationToken? cancellationToken = default);
+ public ValueTask<object> PublishMessageAsync(object message, TopicId topic, AgentId? sender = null, string? messageId = null, CancellationToken? cancellationToken = default);
+ // TODO: Can we call this Resolve?
public ValueTask<AgentId> GetAgentAsync(AgentId agentId, string key = "default", bool lazy = true/*, CancellationToken? = default*/);
public ValueTask<AgentId> GetAgentAsync(AgentType agentType, string key = "default", bool lazy = true/*, CancellationToken? = default*/);
public ValueTask<AgentId> GetAgentAsync(string agent, string key = "default", bool lazy = true/*, CancellationToken? = default*/);
public ValueTask<StateDict> SaveAgentStateAsync(/*CancellationToken? cancellationToken = default*/);
- public ValueTask<StateDict> LoadAgentStateAsync(StateDict state/*, CancellationToken? cancellationToken = default*/);
+ public ValueTask LoadAgentStateAsync(StateDict state/*, CancellationToken? cancellationToken = default*/);
public ValueTask<AgentMetadata> GetAgentMetadataAsync(AgentId agentId/*, CancellationToken? cancellationToken = default*/);
@@ -25,8 +26,8 @@ public interface IAgentRuntime : ISaveState<IAgentRuntime>
public ValueTask<AgentType> RegisterAgentFactoryAsync<TAgent>(AgentType type, Func<ValueTask<TAgent>> factoryFunc) where TAgent : IHostableAgent;
// TODO:
- public ValueTask<TAgent> TryGetUnderlyingAgentInstanceAsync<TAgent>(AgentId agentId) where TAgent : IHostableAgent;
- public void AddMessageSerializer(params object[] serializers);
+ //public ValueTask<TAgent> TryGetUnderlyingAgentInstanceAsync<TAgent>(AgentId agentId) where TAgent : IHostableAgent;
+ //public void AddMessageSerializer(params object[] serializers);
// Extras
public ValueTask<IAgent> TryGetAgentProxyAsync(AgentId agentId);
diff --git a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/TopicId.cs b/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/TopicId.cs
index 89fbd0942..7a084fa3c 100644
--- a/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/TopicId.cs
+++ b/dotnet/src/Microsoft.AutoGen/Contracts/PythonEquiv/TopicId.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// PythonInterfaces.cs
using System.Diagnostics.CodeAnalysis;
@@ -40,5 +40,13 @@ public struct TopicId
}
public static explicit operator TopicId(string id) => FromStr(id);
+
+ // TODO: Implement < for wildcard matching (type, *)
+ // == => <
+ // Type == other.Type => <
+ public bool IsWildcardMatch(TopicId other)
+ {
+ return Type == other.Type;
+ }
}