1+ using MaIN . Core . Hub ;
2+
3+ namespace Examples . Agents ;
4+
5+ public class AgentConversationExample : IExample
6+ {
7+ private static readonly ConsoleColor UserColor = ConsoleColor . Magenta ;
8+ private static readonly ConsoleColor AgentColor = ConsoleColor . Green ;
9+ private static readonly ConsoleColor SystemColor = ConsoleColor . Yellow ;
10+
11+ public async Task Start ( )
12+ {
13+ PrintColored ( "Agent conversation example is running!" , SystemColor ) ;
14+
15+ PrintColored ( "Enter agent name: " , SystemColor , false ) ;
16+ var agentName = Console . ReadLine ( ) ;
17+
18+ PrintColored ( "Enter agent profile (example: 'Gentle and helpful assistant'): " , SystemColor , false ) ;
19+ var agentProfile = Console . ReadLine ( ) ;
20+
21+ PrintColored ( "Enter LLM model (ex: gemma3:4b, llama3.2:3b, yi:6b): " , SystemColor , false ) ;
22+ var model = Console . ReadLine ( ) ! ;
23+ var systemPrompt =
24+ $ """
25+ Your name is: { agentName }
26+ You are: { agentProfile }
27+ Always stay in your role.
28+ """ ;
29+
30+ PrintColored ( $ "Creating agent '{ agentName } ' with profile: '{ agentProfile } ' using model: '{ model } '", SystemColor ) ;
31+ AIHub . Extensions . DisableLLamaLogs ( ) ;
32+ AIHub . Extensions . DisableNotificationsLogs ( ) ;
33+ var context = await AIHub . Agent ( )
34+ . WithModel ( model )
35+ . WithInitialPrompt ( systemPrompt )
36+ . CreateAsync ( interactiveResponse : true ) ;
37+
38+ bool conversationActive = true ;
39+ while ( conversationActive )
40+ {
41+ PrintColored ( "You > " , UserColor , false ) ;
42+ string userMessage = Console . ReadLine ( ) ! ;
43+
44+ if ( userMessage . ToLower ( ) == "exit" || userMessage . ToLower ( ) == "quit" )
45+ {
46+ conversationActive = false ;
47+ continue ;
48+ }
49+
50+ PrintColored ( $ "{ agentName } > ", AgentColor , false ) ;
51+ await context . ProcessAsync ( userMessage ) ;
52+
53+ Console . WriteLine ( ) ;
54+ }
55+
56+ PrintColored ( "Conversation ended. Goodbye!" , SystemColor ) ;
57+ }
58+
59+ private static void PrintColored ( string message , ConsoleColor color , bool newLine = true )
60+ {
61+ Console . ForegroundColor = color ;
62+ if ( newLine )
63+ {
64+ Console . WriteLine ( message ) ;
65+ }
66+ else
67+ {
68+ Console . Write ( message ) ;
69+ }
70+ Console . ResetColor ( ) ;
71+ }
72+ }
0 commit comments