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
47 changes: 24 additions & 23 deletions Examples/Examples/Agents/AgentConversationExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ namespace Examples.Agents;

public class AgentConversationExample : IExample
{
private static readonly ConsoleColor UserColor = ConsoleColor.Magenta;
private static readonly ConsoleColor AgentColor = ConsoleColor.Green;
private static readonly ConsoleColor SystemColor = ConsoleColor.Yellow;
private static readonly ConsoleColor _userColor = ConsoleColor.Magenta;
private static readonly ConsoleColor _agentColor = ConsoleColor.Green;
private static readonly ConsoleColor _systemColor = ConsoleColor.Yellow;

public async Task Start()
{
PrintColored("Agent conversation example is running!", SystemColor);
PrintColored("Enter agent name: ", SystemColor, false);
PrintColored("Agent conversation example is running!", _systemColor);

PrintColored("Enter agent name: ", _systemColor, false);
var agentName = Console.ReadLine();
PrintColored("Enter agent profile (example: 'Gentle and helpful assistant'): ", SystemColor, false);

PrintColored("Enter agent profile (example: 'Gentle and helpful assistant'): ", _systemColor, false);
var agentProfile = Console.ReadLine();
PrintColored("Enter LLM model (ex: gemma3:4b, llama3.2:3b, yi:6b): ", SystemColor, false);

PrintColored("Enter LLM model (ex: gemma3:4b, llama3.2:3b, yi:6b): ", _systemColor, false);
var model = Console.ReadLine()!;
var systemPrompt =
$"""
Expand All @@ -27,35 +27,35 @@ public async Task Start()
Always stay in your role.
""";

PrintColored($"Creating agent '{agentName}' with profile: '{agentProfile}' using model: '{model}'", SystemColor);
PrintColored($"Creating agent '{agentName}' with profile: '{agentProfile}' using model: '{model}'", _systemColor);
AIHub.Extensions.DisableLLamaLogs();
AIHub.Extensions.DisableNotificationsLogs();
var context = await AIHub.Agent()
.WithModel(model)
.WithInitialPrompt(systemPrompt)
.CreateAsync(interactiveResponse: true);

bool conversationActive = true;
while (conversationActive)
{
PrintColored("You > ", UserColor, false);
PrintColored("You > ", _userColor, false);
string userMessage = Console.ReadLine()!;
if (userMessage.ToLower() == "exit" || userMessage.ToLower() == "quit")

if (userMessage.ToLower() is "exit" or "quit")
{
conversationActive = false;
continue;
}
PrintColored($"{agentName} > ", AgentColor, false);

PrintColored($"{agentName} > ", _agentColor, false);
await context.ProcessAsync(userMessage);
Console.WriteLine();

Console.WriteLine();
}
PrintColored("Conversation ended. Goodbye!", SystemColor);

PrintColored("Conversation ended. Goodbye!", _systemColor);
}

private static void PrintColored(string message, ConsoleColor color, bool newLine = true)
{
Console.ForegroundColor = color;
Expand All @@ -67,6 +67,7 @@ private static void PrintColored(string message, ConsoleColor color, bool newLin
{
Console.Write(message);
}

Console.ResetColor();
}
}
}
7 changes: 4 additions & 3 deletions Examples/Examples/Agents/AgentExample.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MaIN.Core.Hub;
using MaIN.Domain.Models;

namespace Examples.Agents;

Expand All @@ -24,13 +25,13 @@ has the best possible counsel as she seeks to reclaim the Iron Throne.
""";

var context = AIHub.Agent()
.WithModel("llama3.2:3b")
.WithModel(Models.Local.Llama3_2_3b)
.WithInitialPrompt(systemPrompt)
.Create();

var result = await context
.ProcessAsync("Where is the Iron Throne located? I need this information for Lady Princess");

Console.WriteLine(result.Message.Content);
}
}
}
3 changes: 2 additions & 1 deletion Examples/Examples/Agents/AgentExampleTools.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Examples.Utils;
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Models;

namespace Examples.Agents;

Expand All @@ -12,7 +13,7 @@ public async Task Start()
Console.WriteLine("(Anthropic) Tool example is running!");

var context = await AIHub.Agent()
.WithModel("claude-sonnet-4-5-20250929")
.WithModel(Models.Anthropic.ClaudeSonnet4_5)
.WithSteps(StepBuilder.Instance
.Answer()
.Build())
Expand Down
9 changes: 5 additions & 4 deletions Examples/Examples/Agents/AgentWithApiDataSourceExample.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Entities.Agents.AgentSource;
using MaIN.Domain.Models;

namespace Examples.Agents;

Expand All @@ -9,9 +10,9 @@ public class AgentWithApiDataSourceExample : IExample
public async Task Start()
{
Console.WriteLine("Agent with api source");

var context = AIHub.Agent()
.WithModel("llama3.2:3b")
.WithModel(Models.Local.Llama3_2_3b)
.WithInitialPrompt("Extract at least 4 jobs offers (try to include title, company name, salary and location if possible)")
.WithSource(new AgentApiSourceDetails()
{
Expand All @@ -24,9 +25,9 @@ public async Task Start()
.FetchData()
.Build())
.Create();

var result = await context
.ProcessAsync("I am looking for work as javascript developer");
Console.WriteLine(result.Message.Content);
}
}
}
5 changes: 3 additions & 2 deletions Examples/Examples/Agents/AgentWithBecomeExample.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Entities.Agents.AgentSource;
using MaIN.Domain.Models;

namespace Examples.Agents;

Expand All @@ -9,7 +10,7 @@ public class AgentWithBecomeExample : IExample
public async Task Start()
{
var becomeAgent = AIHub.Agent()
.WithModel("llama3.1:8b")
.WithModel(Models.Local.Llama3_1_8b)
.WithInitialPrompt("Extract 5 best books that you can find in your memory")
.WithSource(new AgentFileSourceDetails
{
Expand Down Expand Up @@ -41,4 +42,4 @@ public async Task Start()
await becomeAgent
.ProcessAsync("I am looking for good fantasy book to buy");
}
}
}
26 changes: 14 additions & 12 deletions Examples/Examples/Agents/AgentWithKnowledgeFileExample.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Models;

namespace Examples.Agents;

Expand All @@ -10,16 +11,17 @@ public async Task Start()
Console.WriteLine("Agent with knowledge base example");
AIHub.Extensions.DisableLLamaLogs();
var context = await AIHub.Agent()
.WithModel("gemma3:4b")
.WithInitialPrompt("""
You are a helpful assistant that answers questions about a company. Try to
help employees find answers to their questions. Company you work for is TechVibe Solutions.
""")
.WithModel(Models.Local.Gemma3_4b)
.WithInitialPrompt(
"""
You are a helpful assistant that answers questions about a company. Try to
help employees find answers to their questions. Company you work for is TechVibe Solutions.
""")
.WithKnowledge(KnowledgeBuilder.Instance
.AddFile("people.md", "./Files/Knowledge/people.md",
.AddFile("people.md", "./Files/Knowledge/people.md",
tags: ["workers", "employees", "company"])
.AddFile("organization.md", "./Files/Knowledge/organization.md",
tags:["company structure", "company policy", "company culture", "company overview"])
tags: ["company structure", "company policy", "company culture", "company overview"])
.AddFile("events.md", "./Files/Knowledge/events.md",
tags: ["company events", "company calendar", "company agenda"])
.AddFile("office_layout.md", "./Files/Knowledge/office_layout.md",
Expand All @@ -28,10 +30,10 @@ You are a helpful assistant that answers questions about a company. Try to
.AnswerUseKnowledge()
.Build())
.CreateAsync();
var result = await context
.ProcessAsync("Hey! Where I can find some printer paper?");
Console.WriteLine(result.Message.Content);;

var result = await context.ProcessAsync("Hey! Where I can find some printer paper?");
Console.WriteLine(result.Message.Content);
;

}
}
}
23 changes: 12 additions & 11 deletions Examples/Examples/Agents/AgentWithKnowledgeWebExample.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Entities;
using MaIN.Domain.Models;

namespace Examples.Agents;

Expand All @@ -12,14 +13,15 @@ public async Task Start()

AIHub.Extensions.DisableLLamaLogs();
var context = await AIHub.Agent()
.WithModel("llama3.2:3b")
.WithMemoryParams(new MemoryParams(){ContextSize = 4096})
.WithInitialPrompt("""
You are an expert piano instructor specializing in teaching specific pieces,
techniques, and solving common playing problems. Help students learn exact
fingerings, chord progressions, and troubleshoot technical issues with
detailed, step-by-step guidance for both classical and popular music.
""")
.WithModel(Models.Local.Llama3_2_3b)
.WithMemoryParams(new MemoryParams() { ContextSize = 4096 })
.WithInitialPrompt(
"""
You are an expert piano instructor specializing in teaching specific pieces,
techniques, and solving common playing problems. Help students learn exact
fingerings, chord progressions, and troubleshoot technical issues with
detailed, step-by-step guidance for both classical and popular music.
""")
.WithKnowledge(KnowledgeBuilder.Instance
.AddUrl("piano_scales_major", "https://www.pianoscales.org/major.html",
tags: ["scale_fingerings", "c_major_scale", "d_major_scale", "fingering_patterns"])
Expand All @@ -43,9 +45,8 @@ public async Task Start()
.Build())
.CreateAsync();

var result = await context
.ProcessAsync("I want to learn the C major scale. What's the exact fingering pattern for both hands?" + "I want short and concrete answer");
var result = await context.ProcessAsync("I want to learn the C major scale. What's the exact fingering pattern for both hands?" + "I want short and concrete answer");

Console.WriteLine(result.Message.Content);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Entities.Agents.AgentSource;
using MaIN.Domain.Models;

namespace Examples.Agents;

Expand All @@ -10,11 +11,11 @@ public class AgentWithWebDataSourceOpenAiExample : IExample
public async Task Start()
{
Console.WriteLine("Agent with web source (OpenAi)");

OpenAiExample.Setup(); //We need to provide OpenAi API key

var context = await AIHub.Agent()
.WithModel("gpt-4o-mini")
.WithModel(Models.OpenAi.Gpt4oMini)
.WithInitialPrompt($"Find useful information about daily news, try to include title, description and link.")
.WithBehaviour("Journalist", $"Base on data provided in chat find useful information about what happen today. Build it in form of newsletter - Name of newsletter is MaIN_Letter and today`s date is {DateTime.UtcNow}")
.WithSource(new AgentWebSourceDetails()
Expand All @@ -27,9 +28,9 @@ public async Task Start()
.Answer()
.Build())
.CreateAsync(interactiveResponse: true);

await context
.ProcessAsync("Provide today's newsletter");

}
}
}
15 changes: 8 additions & 7 deletions Examples/Examples/Agents/AgentsTalkingToEachOther.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MaIN.Core.Hub;
using MaIN.Core.Hub.Utils;
using MaIN.Domain.Models;

namespace Examples.Agents;

Expand All @@ -15,7 +16,7 @@ public async Task Start()
You prioritize kindness, patience, and understanding in every interaction. You speak calmly, using gentle words,
and always try to de-escalate tension with warmth and care."
""";

var systemPromptSecond =
"""
You are intense, blunt, and always on edge. Your tone is sharp, impatient, and confrontational.
Expand All @@ -24,28 +25,28 @@ and always try to de-escalate tension with warmth and care."
""";

var idFirst = Guid.NewGuid().ToString();

var contextSecond = AIHub.Agent()
.WithModel("gemma2:2b")
.WithModel(Models.Local.Gemma2_2b)
.WithInitialPrompt(systemPromptSecond)
.WithSteps(StepBuilder.Instance
.Answer()
.Redirect(agentId: idFirst, mode: "USER")
.Build())
.Create(interactiveResponse: true);

var context = AIHub.Agent()
.WithModel("llama3.2:3b")
.WithModel(Models.Local.Llama3_2_3b)
.WithId(idFirst)
.WithInitialPrompt(systemPrompt)
.WithSteps(StepBuilder.Instance
.Answer()
.Redirect(agentId: contextSecond.GetAgentId(), mode: "USER")
.Build())
.Create(interactiveResponse: true);

await context
.ProcessAsync("Introduce yourself, and start conversation!");

}
}
}
Loading
Loading