Skip to content

Commit 03905a7

Browse files
committed
Make use of the ChatId property of the Agent
1 parent 36396df commit 03905a7

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

MaIN.Core.IntegrationTests/ChatTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ public async Task Should_AnswerDifferences_BetweenDocuments_ChatWithFiles()
4747
public async Task Should_AnswerQuestion_FromExistingChat()
4848
{
4949
var result = AIHub.Chat()
50-
.WithModel(Models.Local.Qwen2_5_0_5b);
50+
.WithModel(Models.Local.Gemma2_2b);
5151

5252
await result.WithMessage("What do you think about math theories?")
5353
.CompleteAsync();
5454

55-
5655
await result.WithMessage("And about physics?")
5756
.CompleteAsync();
5857

src/MaIN.Domain/Entities/Agents/Agent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ public class Agent
1212
public bool Started { get; set; }
1313
public bool Flow { get; set; }
1414
public required AgentData Context { get; init; }
15-
public string ChatId => string.Empty;
15+
public string ChatId { get; set; } = string.Empty;
1616
public int Order { get; set; }
1717
public BackendType? Backend { get; set; }
1818
public Dictionary<string, string> Behaviours { get; set; } = [];
1919
public required string CurrentBehaviour { get; set; }
2020
public ToolsConfiguration? ToolsConfiguration { get; set; }
21-
}
21+
}

src/MaIN.Services/Services/AgentService.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ await notificationService.DispatchNotification(
7676
await agentRepository.UpdateAgent(agent.Id, agent);
7777

7878
await notificationService.DispatchNotification(
79-
NotificationMessageBuilder.ProcessingComplete(agentId, agent.CurrentBehaviour, "COMPLETED"), "ReceiveAgentUpdate");
79+
NotificationMessageBuilder.ProcessingComplete(
80+
agentId,
81+
agent.CurrentBehaviour,
82+
"COMPLETED"), "ReceiveAgentUpdate");
8083

8184
//normalize message before returning it to user
8285
chat.Messages.Last().Content = Replace(
@@ -90,7 +93,8 @@ await notificationService.DispatchNotification(
9093
catch (Exception ex)
9194
{
9295
await notificationService.DispatchNotification(
93-
NotificationMessageBuilder.ProcessingFailed(agentId, agent.CurrentBehaviour, ex.Message), "ReceiveAgentUpdate");
96+
NotificationMessageBuilder.ProcessingFailed(agentId, agent.CurrentBehaviour, ex.Message),
97+
"ReceiveAgentUpdate");
9498
throw;
9599
}
96100
}
@@ -128,15 +132,13 @@ public async Task<Agent> CreateAgent(Agent agent, bool flow = false, bool intera
128132

129133
agent.Started = true;
130134
agent.Flow = flow;
135+
agent.ChatId = chat.Id;
131136
agent.Behaviours ??= [];
132137
agent.Behaviours.Add("Default", agent.Context.Instruction!);
133138
agent.CurrentBehaviour = "Default";
134139

135-
var agentDocument = agent.ToDocument();
136-
agentDocument.ChatId = chat.Id;
137-
138140
await chatRepository.AddChat(chat.ToDocument());
139-
await agentRepository.AddAgent(agentDocument);
141+
await agentRepository.AddAgent(agent.ToDocument());
140142

141143
return agent;
142144
}

0 commit comments

Comments
 (0)