remove agents project

This commit is contained in:
Jack Gerrits 2025-01-27 16:35:22 -05:00 committed by Jack Gerrits
parent 20a47ebd43
commit e9d4dcae64
9 changed files with 0 additions and 459 deletions

View File

@ -130,8 +130,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.Core.Grpc
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.Runtime.Grpc", "src\Microsoft.AutoGen\Runtime.Grpc\Microsoft.AutoGen.Runtime.Grpc.csproj", "{8457B68C-CC86-4A3F-8559-C1AE199EC366}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.Agents", "src\Microsoft.AutoGen\Agents\Microsoft.AutoGen.Agents.csproj", "{3892C83E-7F5D-41DF-A88C-4854EAD38856}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.AgentHost", "src\Microsoft.AutoGen\AgentHost\Microsoft.AutoGen.AgentHost.csproj", "{4CB42139-DEE4-40B9-AA81-1E4CCAA2F338}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AutoGen.Runtime.Grpc.Tests", "test\Microsoft.AutoGen.Runtime.Grpc.Tests\Microsoft.AutoGen.Runtime.Grpc.Tests.csproj", "{0E7983BB-2602-421E-8B37-332E52870A10}"
@ -403,11 +401,6 @@ Global
{8457B68C-CC86-4A3F-8559-C1AE199EC366}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8457B68C-CC86-4A3F-8559-C1AE199EC366}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8457B68C-CC86-4A3F-8559-C1AE199EC366}.Release|Any CPU.Build.0 = Release|Any CPU
{3892C83E-7F5D-41DF-A88C-4854EAD38856}.CoreOnly|Any CPU.ActiveCfg = Debug|Any CPU
{3892C83E-7F5D-41DF-A88C-4854EAD38856}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3892C83E-7F5D-41DF-A88C-4854EAD38856}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3892C83E-7F5D-41DF-A88C-4854EAD38856}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3892C83E-7F5D-41DF-A88C-4854EAD38856}.Release|Any CPU.Build.0 = Release|Any CPU
{4CB42139-DEE4-40B9-AA81-1E4CCAA2F338}.CoreOnly|Any CPU.ActiveCfg = Debug|Any CPU
{4CB42139-DEE4-40B9-AA81-1E4CCAA2F338}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4CB42139-DEE4-40B9-AA81-1E4CCAA2F338}.Debug|Any CPU.Build.0 = Debug|Any CPU
@ -499,7 +492,6 @@ Global
{7F60934B-3E59-48D0-B26D-04A39FEC13EF} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{9653676C-147D-4CBE-BB53-A30FD3634F4C} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{8457B68C-CC86-4A3F-8559-C1AE199EC366} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{3892C83E-7F5D-41DF-A88C-4854EAD38856} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{4CB42139-DEE4-40B9-AA81-1E4CCAA2F338} = {18BF8DD7-0585-48BF-8F97-AD333080CE06}
{0E7983BB-2602-421E-8B37-332E52870A10} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}
{EAFFE339-26CB-4019-991D-BCCE8E7D33A1} = {F823671B-3ECA-4AE6-86DA-25E920D3FE64}

View File

@ -1,31 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// InferenceAgent.cs
using Google.Protobuf;
using Microsoft.AutoGen.Core;
using Microsoft.Extensions.AI;
namespace Microsoft.AutoGen.Agents;
public abstract class InferenceAgent<T>(
AgentsMetadata typeRegistry,
IChatClient client)
: Agent(typeRegistry)
where T : IMessage, new()
{
protected IChatClient ChatClient { get; } = client;
private Task<ChatCompletion> CompleteAsync(
IList<ChatMessage> chatMessages,
ChatOptions? options = null,
CancellationToken cancellationToken = default)
{
return ChatClient.CompleteAsync(chatMessages, options, cancellationToken);
}
private IAsyncEnumerable<StreamingChatCompletionUpdate> CompleteStreamingAsync(
IList<ChatMessage> chatMessages,
ChatOptions? options = null,
CancellationToken cancellationToken = default)
{
return ChatClient.CompleteStreamingAsync(chatMessages, options, cancellationToken);
}
}

View File

@ -1,83 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// SKAiAgent.cs
using System.Globalization;
using System.Text;
using Microsoft.AutoGen.Core;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Memory;
namespace Microsoft.AutoGen.Agents;
public abstract class SKAiAgent<T>(
ISemanticTextMemory memory,
Kernel kernel,
AgentsMetadata typeRegistry) : Agent(
typeRegistry) where T : class, new()
{
protected AgentState<T> _state = new();
protected Kernel _kernel = kernel;
private readonly ISemanticTextMemory _memory = memory;
public void AddToHistory(string message, ChatUserType userType) => _state.History.Add(new ChatHistoryItem
{
Message = message,
Order = _state.History.Count + 1,
UserType = userType
});
public string AppendChatHistory(string ask)
{
AddToHistory(ask, ChatUserType.User);
return string.Join("\n", _state.History.Select(message => $"{message.UserType}: {message.Message}"));
}
public virtual async Task<string> CallFunction(string template, KernelArguments arguments, OpenAIPromptExecutionSettings? settings = null)
{
// TODO: extract this to be configurable
var promptSettings = settings ?? new OpenAIPromptExecutionSettings { MaxTokens = 4096, Temperature = 0.8, TopP = 1 };
var function = _kernel.CreateFunctionFromPrompt(template, promptSettings);
var result = (await _kernel.InvokeAsync(function, arguments).ConfigureAwait(true)).ToString();
AddToHistory(result, ChatUserType.Agent);
//await Store(_state.Data.ToAgentState(AgentId,""));//TODO add eTag
return result;
}
/// <summary>
/// Adds knowledge to the
/// </summary>
/// <param name="instruction">The instruction string that uses the value of !index! as a placeholder to inject the data. Example:"Consider the following architectural guidelines: {waf}" </param>
/// <param name="index">Knowledge index</param>
/// <param name="arguments">The sk arguments, "input" is the argument </param>
/// <returns></returns>
public async Task<KernelArguments> AddKnowledge(string instruction, string index, KernelArguments arguments)
{
var documents = _memory.SearchAsync(index, arguments["input"]?.ToString()!, 5);
var kbStringBuilder = new StringBuilder();
await foreach (var doc in documents)
{
kbStringBuilder.AppendLine(CultureInfo.InvariantCulture, $"{doc.Metadata.Text}");
}
arguments[index] = instruction.Replace($"!{index}!", $"{kbStringBuilder}");
return arguments;
}
}
public class AgentState<T> where T : class, new()
{
public List<ChatHistoryItem> History { get; set; } = [];
public T Data { get; set; } = new();
}
public class ChatHistoryItem
{
public required string Message { get; set; }
public ChatUserType UserType { get; set; }
public int Order { get; set; }
}
public enum ChatUserType
{
System,
User,
Agent
}

View File

@ -1,63 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// ConsoleAgent.cs
using Microsoft.AutoGen.Contracts;
using Microsoft.AutoGen.Core;
using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AutoGen.Agents;
public abstract class ConsoleAgent : IOAgent,
IUseConsole,
IHandle<Input>,
IHandle<Output>
{
// instead of the primary constructor above, make a constructr here that still calls the base constructor
public ConsoleAgent([FromKeyedServices("AgentsMetadata")] AgentsMetadata typeRegistry) : base(typeRegistry)
{
_route = "console";
}
public override async Task Handle(Input item, CancellationToken cancellationToken)
{
Console.WriteLine("Please enter input:");
string content = Console.ReadLine() ?? string.Empty;
await ProcessInput(content);
var evt = new InputProcessed
{
Route = _route
};
await PublishMessageAsync(evt);
}
public override async Task Handle(Output item, CancellationToken cancellationToken)
{
// Assuming item has a property `Content` that we want to write to the console
Console.WriteLine(item.Message);
await ProcessOutput(item.Message);
var evt = new OutputWritten
{
Route = _route
};
await PublishMessageAsync(evt);
}
public override Task<string> ProcessInput(string message)
{
// Implement your input processing logic here
return Task.FromResult(message);
}
public override Task ProcessOutput(string message)
{
// Implement your output processing logic here
return Task.CompletedTask;
}
}
public interface IUseConsole
{
public Task ProcessOutput(string message);
}

View File

@ -1,50 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// IHandleConsole.cs
using Google.Protobuf;
using Microsoft.AutoGen.Contracts;
using Microsoft.AutoGen.Core;
namespace Microsoft.AutoGen.Agents;
public interface IHandleConsole : IHandle<Output>, IHandle<Input>
{
AgentId AgentId { get; }
ValueTask PublishMessageAsync<T>(T message, CancellationToken token = default) where T : IMessage;
async Task IHandle<Output>.Handle(Output item, CancellationToken cancellationToken)
{
// Assuming item has a property `Message` that we want to write to the console
Console.WriteLine(item.Message);
await ProcessOutput(item.Message);
var evt = new OutputWritten
{
Route = "console"
};
await PublishMessageAsync(evt).ConfigureAwait(false);
}
async Task IHandle<Input>.Handle(Input item, CancellationToken cancellationToken)
{
Console.WriteLine("Please enter input:");
string content = Console.ReadLine() ?? string.Empty;
await ProcessInput(content);
var evt = new InputProcessed
{
Route = "console"
};
await PublishMessageAsync(evt).ConfigureAwait(false);
}
static Task ProcessOutput(string message)
{
// Implement your output processing logic here
return Task.CompletedTask;
}
static Task<string> ProcessInput(string message)
{
// Implement your input processing logic here
return Task.FromResult(message);
}
}

View File

@ -1,77 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// FileAgent.cs
using Microsoft.AutoGen.Contracts;
using Microsoft.AutoGen.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Microsoft.AutoGen.Agents;
[TopicSubscription("FileIO")]
public abstract class FileAgent(
[FromKeyedServices("AgentsMetadata")] AgentsMetadata typeRegistry,
string inputPath = "input.txt",
string outputPath = "output.txt"
) : IOAgent(typeRegistry),
IUseFiles,
IHandle<Input>,
IHandle<Output>
{
public override async Task Handle(Input item, CancellationToken cancellationToken = default)
{
// validate that the file exists
if (!File.Exists(inputPath))
{
var errorMessage = $"File not found: {inputPath}";
_logger.LogError(errorMessage);
//publish IOError event
var err = new IOError
{
Message = errorMessage
};
await PublishMessageAsync(err);
return;
}
string content;
using (var reader = new StreamReader(item.Message))
{
content = await reader.ReadToEndAsync();
}
await ProcessInput(content);
var evt = new InputProcessed
{
Route = _route
};
await PublishMessageAsync(evt);
}
public override async Task Handle(Output item, CancellationToken cancellationToken = default)
{
using (var writer = new StreamWriter(outputPath, append: true))
{
await writer.WriteLineAsync(item.Message);
}
var evt = new OutputWritten
{
Route = _route
};
await PublishMessageAsync(evt);
}
public override async Task<string> ProcessInput(string message)
{
var evt = new InputProcessed
{
Route = _route,
};
await PublishMessageAsync(evt);
return message;
}
public override Task ProcessOutput(string message)
{
// Implement your output processing logic here
return Task.CompletedTask;
}
}
public interface IUseFiles
{
}

View File

@ -1,34 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// IOAgent.cs
using Microsoft.AutoGen.Contracts;
using Microsoft.AutoGen.Core;
namespace Microsoft.AutoGen.Agents;
public abstract class IOAgent(AgentsMetadata eventTypes) : Agent(eventTypes)
{
public string _route = "base";
public virtual async Task Handle(Input item, CancellationToken cancellationToken)
{
var evt = new InputProcessed
{
Route = _route
};
await PublishMessageAsync(evt);
}
public virtual async Task Handle(Output item, CancellationToken cancellationToken)
{
var evt = new OutputWritten
{
Route = _route
};
await PublishMessageAsync(evt);
}
public abstract Task ProcessInput(string message);
public abstract Task ProcessOutput(string message);
}

View File

@ -1,92 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// WebAPIAgent.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AutoGen.Contracts;
using Microsoft.AutoGen.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Microsoft.AutoGen.Agents;
public abstract class WebAPIAgent : IOAgent,
IUseWebAPI,
IHandle<Input>,
IHandle<Output>
{
private readonly string _url = "/agents/webio";
public WebAPIAgent(
IAgentRuntime worker,
[FromKeyedServices("AgentsMetadata")] AgentsMetadata typeRegistry,
ILogger<WebAPIAgent> logger,
string url = "/agents/webio") : base(
typeRegistry)
{
_url = url;
var builder = WebApplication.CreateBuilder();
var app = builder.Build();
app.MapPost(_url, async (HttpContext httpContext) =>
{
var input = await httpContext.Request.ReadFromJsonAsync<Input>();
if (input != null)
{
await Handle(input);
await httpContext.Response.WriteAsync("Input processed");
}
else
{
httpContext.Response.StatusCode = 400;
await httpContext.Response.WriteAsync("Invalid input");
}
});
app.MapGet(_url, async (HttpContext httpContext) =>
{
var output = new Output(); // Replace with actual output retrieval logic
await Handle(output);
await httpContext.Response.WriteAsJsonAsync(output);
});
app.Run();
}
public override async Task Handle(Input item, CancellationToken cancellationToken = default)
{
// Process the input (this is a placeholder, replace with actual processing logic)
await ProcessInput(item.Message);
var evt = new InputProcessed
{
Route = _route
};
await PublishMessageAsync(evt);
}
public override async Task Handle(Output item, CancellationToken cancellationToken = default)
{
// Assuming item has a property `Content` that we want to return in the response
var evt = new OutputWritten
{
Route = _route
};
await PublishMessageAsync(evt);
}
public override Task<string> ProcessInput(string message)
{
// Implement your input processing logic here
return Task.FromResult(message);
}
public override Task ProcessOutput(string message)
{
// Implement your output processing logic here
return Task.CompletedTask;
}
}
public interface IUseWebAPI
{
}

View File

@ -1,21 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<Import Project="$(RepoRoot)/nuget/nuget-package.props" />
<ItemGroup>
<ProjectReference Include="..\Contracts\Microsoft.AutoGen.Contracts.csproj" />
<ProjectReference Include="..\Core\Microsoft.AutoGen.Core.csproj" />
<ProjectReference Include="..\Extensions\Aspire\Microsoft.AutoGen.Extensions.Aspire.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SemanticKernel" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" />
</ItemGroup>
</Project>