feat: Make the python interface more correct

This commit is contained in:
Jacob Alber
2025-01-27 11:47:39 -05:00
committed by Jack Gerrits
parent d6a83a2f7c
commit 51dbe6cd6d
4 changed files with 23 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// PythonInterfaces.cs
using System.Diagnostics;

View File

@@ -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();
}
}

View File

@@ -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);

View File

@@ -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;
}
}