Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MaIN.Models.Rag;

public class AgentContextDto
public class AgentConfigDto
{
[JsonPropertyName("instruction")]
public string Instruction { get; set; }
Expand All @@ -13,4 +13,4 @@ public class AgentContextDto
[JsonPropertyName("relations")]
public List<string>? Relations { get; set; }

}
}
6 changes: 3 additions & 3 deletions Frontend/MainFE/Components/Models/AgentDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class AgentDto
public bool Started { get; set; }
[JsonPropertyName("flow")]
public bool Flow { get; set; }
[JsonPropertyName("context")]
public AgentContextDto Context { get; set; }
[JsonPropertyName("config")]
public AgentConfigDto Config { get; set; }
public AgentProcessingState State { get; set; }
public bool IsProcessing { get; set; }
public List<string>? AgentDependencies { get; set; } = [];
Expand All @@ -36,4 +36,4 @@ public string ProgressMessage
set => _progressMessage = value;
}
private string? _progressMessage;
}
}
10 changes: 5 additions & 5 deletions src/MaIN.Core.UnitTests/AgentContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void Constructor_ShouldInitializeNewAgent()
Assert.NotNull(agentId);
Assert.NotEmpty(agentId);
Assert.NotNull(agent);
Assert.NotNull(agent.Context);
Assert.NotNull(agent.Config);
Assert.NotNull(agent.Behaviours);
Assert.Equal("Agent created by MaIN", agent.Description);
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public void WithInitialPrompt_ShouldSetInstruction()
var result = _agentContext.WithInitialPrompt(expectedPrompt);

// Assert
Assert.Equal(expectedPrompt, _agentContext.GetAgent().Context.Instruction);
Assert.Equal(expectedPrompt, _agentContext.GetAgent().Config.Instruction);
Assert.Equal(result, _agentContext);
}

Expand All @@ -102,7 +102,7 @@ public void WithSteps_ShouldSetAgentSteps()
var result = _agentContext.WithSteps(expectedSteps);

// Assert
Assert.Equal(expectedSteps, _agentContext.GetAgent().Context.Steps);
Assert.Equal(expectedSteps, _agentContext.GetAgent().Config.Steps);
Assert.Equal(result, _agentContext);
}

Expand Down Expand Up @@ -132,7 +132,7 @@ public async Task CreateAsync_ShouldCallAgentServiceCreateAgent()
{
Id = Guid.NewGuid().ToString(),
CurrentBehaviour = "Default",
Context = new AgentData()
Config = new AgentConfig()
};
_mockAgentService
.Setup(s => s.CreateAgent(
Expand Down Expand Up @@ -224,7 +224,7 @@ public async Task FromExisting_ShouldCreateContextFromExistingAgent()
Id = existingAgentId,
Name = "Existing Agent",
CurrentBehaviour = "Default",
Context = new AgentData()
Config = new AgentConfig()
};

_mockAgentService
Expand Down
45 changes: 27 additions & 18 deletions src/MaIN.Core.UnitTests/FlowContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public FlowContextTests()
var testModel = new GenericLocalModel(_testModelId);
ModelRegistry.RegisterOrReplace(testModel);
}

[Fact]
public async Task WithId_ShouldSetFlowId()
{
Expand All @@ -34,7 +34,7 @@ public async Task WithId_ShouldSetFlowId()

// Act
var result = _flowContext.WithId(expectedId);

// Setup mock to return flow with the set ID
_mockFlowService
.Setup(s => s.GetFlowById(expectedId))
Expand All @@ -55,13 +55,14 @@ public async Task WithName_ShouldSetFlowName()

// Act
var result = _flowContext.WithName(expectedName);

// Setup mock to return flow with the set name
_mockFlowService
.Setup(s => s.GetFlowById(It.IsAny<string>()))
.ReturnsAsync(new AgentFlow {
Id = It.IsAny<string>(),
Name = expectedName
.ReturnsAsync(new AgentFlow
{
Id = It.IsAny<string>(),
Name = expectedName
});

var flow = await _flowContext.GetCurrentFlow();
Expand Down Expand Up @@ -92,24 +93,32 @@ public async Task CreateAsync_ShouldCallFlowService()
public async Task ProcessAsync_WithStringMessage_ShouldReturnChatResult()
{
// Arrange
var firstAgent = new Agent { Id = "first-agent", Order = 0, CurrentBehaviour = It.IsAny<string>(), Context = new AgentData()};
var firstAgent = new Agent
{
Id = "first-agent",
Order = 0,
CurrentBehaviour = It.IsAny<string>(),
Config = new AgentConfig()
};
_flowContext.AddAgent(firstAgent);

var message = "Hello, flow!";
var chat = new Chat { Id = firstAgent.Id, Messages = new List<Message>(), ModelId = _testModelId, Name = "test"};
var chat = new Chat { Id = firstAgent.Id, Messages = [], ModelId = _testModelId, Name = "test" };

_mockAgentService
.Setup(s => s.GetChatByAgent(firstAgent.Id))
.ReturnsAsync(chat);

_mockAgentService
.Setup(s => s.Process(It.IsAny<Chat>(), firstAgent.Id, It.IsAny<Knowledge>(), It.IsAny<bool>(), null, null))
.ReturnsAsync(new Chat {
ModelId = _testModelId,
.ReturnsAsync(new Chat
{
ModelId = _testModelId,
Name = "test",
Messages = new List<Message> {
new() { Content = "Response", Role = "Assistant", Type = MessageType.LocalLLM}
}
Messages =
[
new() { Content = "Response", Role = "Assistant", Type = MessageType.LocalLLM}
]
});

// Act
Expand Down Expand Up @@ -165,17 +174,17 @@ public async Task FromExisting_ShouldCreateFlowContextFromExistingFlow()
{
// Arrange
var existingFlowId = "existing-flow-id";
var existingFlow = new AgentFlow
{
Id = existingFlowId,
var existingFlow = new AgentFlow
{
Id = existingFlowId,
Name = "Existing Flow",
Agents =
[
new Agent
{
Id = "agent1",
CurrentBehaviour = It.IsAny<string>(),
Context = new AgentData()
Config = new AgentConfig()
}
]
};
Expand Down Expand Up @@ -203,4 +212,4 @@ public async Task FromExisting_ShouldThrowArgumentExceptionWhenFlowNotFound()
// Act & Assert
await Assert.ThrowsAsync<FlowNotFoundException>(() => _flowContext.FromExisting(nonExistentFlowId));
}
}
}
2 changes: 2 additions & 0 deletions src/MaIN.Core/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MaIN.Core.Interfaces;
using MaIN.Core.Services;
using MaIN.Domain.Configuration;
using MaIN.Infrastructure;
using MaIN.Services;
using MaIN.Services.Services;
using MaIN.Services.Services.Abstract;
Expand All @@ -18,6 +19,7 @@ public static IServiceCollection AddMaIN(
Action<MaINSettings>? configureSettings = null)
{
services.ConfigureMaIN(configuration, configureSettings);
services.ConfigureInfrastructure(configuration);
services.AddAIHub();
return services;
}
Expand Down
11 changes: 5 additions & 6 deletions src/MaIN.Core/Hub/Contexts/AgentContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal AgentContext(IAgentService agentService)
Description = "Agent created by MaIN",
CurrentBehaviour = "Default",
Flow = false,
Context = new AgentData()
Config = new AgentConfig()
{
Instruction = "Hello, I'm your personal assistant. How can I assist you today?",
Relations = [],
Expand Down Expand Up @@ -84,7 +84,7 @@ public async Task<IAgentContextExecutor> FromExisting(string agentId)

public IAgentConfigurationBuilder WithInitialPrompt(string prompt)
{
_agent.Context.Instruction = prompt;
_agent.Config.Instruction = prompt;
return this;
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public IAgentConfigurationBuilder EnsureModelDownloaded()

public IAgentConfigurationBuilder WithSource(IAgentSource source, AgentSourceType type)
{
_agent.Context.Source = new AgentSource()
_agent.Config.Source = new AgentSource()
{
Details = source,
Type = type
Expand All @@ -134,8 +134,7 @@ public IAgentConfigurationBuilder WithMcpConfig(Mcp mcpConfig)
{
mcpConfig.Backend = ModelRegistry.GetById(_agent.Model).Backend;
}

_agent.Context.McpConfig = mcpConfig;
_agent.Config.McpConfig = mcpConfig;
return this;
}

Expand All @@ -153,7 +152,7 @@ public IAgentConfigurationBuilder WithMemoryParams(MemoryParams memoryParams)

public IAgentConfigurationBuilder WithSteps(List<string>? steps)
{
_agent.Context.Steps = steps;
_agent.Config.Steps = steps;
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/MaIN.Domain/Entities/Agents/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Agent
public string? Description { get; init; }
public bool Started { get; set; }
public bool Flow { get; set; }
public required AgentData Context { get; init; }
public required AgentConfig Config { get; init; }
public string ChatId { get; set; } = string.Empty;
public int Order { get; set; }
public BackendType? Backend { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace MaIN.Domain.Entities.Agents;

public class AgentData
public class AgentConfig
{
public string? Instruction { get; set; }
public AgentSource.AgentSource? Source { get; set; }
public Mcp? McpConfig { get; set; }
public List<string>? Steps { get; set; }
public List<string>? Relations { get; set; }

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Net;
using System.Net;

namespace MaIN.Domain.Exceptions.Agents;

public class AgentContextNotFoundException(string agentId) : MaINCustomException($"Context of agent with id: '{agentId}' not found.")
public class AgentConfigNotFoundException(string agentId) : MaINCustomException($"Context of agent with id: '{agentId}' not found.")
{
public override string PublicErrorMessage => "Agent context not found.";
public override HttpStatusCode HttpStatusCode => HttpStatusCode.NotFound;
Expand Down
12 changes: 12 additions & 0 deletions src/MaIN.Domain/Repositories/IAgentFlowRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using MaIN.Domain.Entities.Agents.AgentSource;

namespace MaIN.Domain.Repositories;

public interface IAgentFlowRepository
{
Task<IEnumerable<AgentFlow>> GetAllFlows();
Task<AgentFlow?> GetFlowById(string id);
Task AddFlow(AgentFlow flow);
Task UpdateFlow(string id, AgentFlow flow);
Task DeleteFlow(string id);
}
13 changes: 13 additions & 0 deletions src/MaIN.Domain/Repositories/IAgentRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using MaIN.Domain.Entities.Agents;

namespace MaIN.Domain.Repositories;

public interface IAgentRepository
{
Task<IEnumerable<Agent>> GetAllAgents();
Task<Agent?> GetAgentById(string id);
Task AddAgent(Agent agent);
Task UpdateAgent(string id, Agent agent);
Task DeleteAgent(string id);
Task<bool> Exists(string id);
}
12 changes: 12 additions & 0 deletions src/MaIN.Domain/Repositories/IChatRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using MaIN.Domain.Entities;

namespace MaIN.Domain.Repositories;

public interface IChatRepository
{
Task<IEnumerable<Chat>> GetAllChats();
Task<Chat?> GetChatById(string id);
Task AddChat(Chat chat);
Task UpdateChat(string id, Chat chat);
Task DeleteChat(string id);
}
2 changes: 1 addition & 1 deletion src/MaIN.Infrastructure/Bootstrapper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using MaIN.Domain.Configuration;
using MaIN.Infrastructure.Configuration;
using MaIN.Infrastructure.Repositories;
using MaIN.Infrastructure.Repositories.Abstract;
using MaIN.Domain.Repositories;
using MaIN.Infrastructure.Repositories.FileSystem;
using MaIN.Infrastructure.Repositories.Mongo;
using Microsoft.Extensions.Configuration;
Expand Down
2 changes: 1 addition & 1 deletion src/MaIN.Infrastructure/Configuration/SqlExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Dapper;
using MaIN.Infrastructure.Repositories.Abstract;
using MaIN.Domain.Repositories;
using MaIN.Infrastructure.Repositories.Sql;
using Microsoft.Data.SqlClient;
using Microsoft.Extensions.DependencyInjection;
Expand Down
2 changes: 1 addition & 1 deletion src/MaIN.Infrastructure/Configuration/SqliteExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Dapper;
using MaIN.Infrastructure.Repositories.Abstract;
using MaIN.Domain.Repositories;
using MaIN.Infrastructure.Repositories.Sqlite;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.DependencyInjection;
Expand Down
Loading