mirror of
https://github.com/microsoft/autogen.git
synced 2026-04-20 03:02:16 -04:00
feat: Make the python interface more correct
This commit is contained in:
committed by
Jack Gerrits
parent
d6a83a2f7c
commit
51dbe6cd6d
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// PythonInterfaces.cs
|
||||
|
||||
using System.Diagnostics;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user