Skip to content

Commit 726db94

Browse files
committed
Multiple fixes and UI improvements based on feedback
1 parent bc98e6d commit 726db94

File tree

8 files changed

+53
-26
lines changed

8 files changed

+53
-26
lines changed

shell/AIShell.Abstraction/ILLMAgent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public interface ILLMAgent : IDisposable
138138

139139
/// <summary>
140140
/// Refresh the current chat or force starting a new chat session.
141-
/// This method allows an agent to reset chat states, interact with user for authentication, print welcome message, and more.
141+
/// This method allows an agent to reset chat states, refresh token or settings, interact with user for authentication, print welcome message, and more.
142142
/// </summary>
143143
/// <param name="shell">The interface for interacting with the shell.</param>
144144
/// <param name="force">Whether or not to force creating a new chat session.</param>

shell/AIShell.Kernel/LLMAgent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal LLMAgent(ILLMAgent agent, AgentAssemblyLoadContext loadContext)
1313
{
1414
Impl = agent;
1515
LoadContext = loadContext;
16-
Prompt = agent.Name;
16+
Prompt = $"@{agent.Name}";
1717
}
1818

1919
internal void Display(Host host, string description = null)

shell/AIShell.Kernel/Shell.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ private void LoadAvailableAgents()
285285
chosenAgent ??= _agents.Count is 1
286286
? _agents[0]
287287
: Host.PromptForSelectionAsync(
288-
title: "[orange1]Please select an [Blue]agent[/] to use[/]:",
288+
title: "[orange1]Please select an [Blue]agent[/] to use[/]:\n[grey](You can switch to another agent later by [Blue]@[/] tagging its name)[/]",
289289
choices: _agents,
290290
converter: static a => a.Impl.Name)
291291
.GetAwaiter().GetResult();
@@ -538,6 +538,18 @@ private async Task<string> ReadUserInput(string prompt, CancellationToken cancel
538538
return input;
539539
}
540540

541+
/// <summary>
542+
/// Give an agent the opportunity to refresh its chat session, in the unforced way.
543+
/// </summary>
544+
private async Task RefreshChatAsNeeded(LLMAgent agent)
545+
{
546+
if (_shouldRefresh)
547+
{
548+
_shouldRefresh = false;
549+
await agent?.Impl.RefreshChatAsync(this, force: false);
550+
}
551+
}
552+
541553
/// <summary>
542554
/// Run a chat REPL.
543555
/// </summary>
@@ -552,11 +564,7 @@ internal async Task RunREPLAsync()
552564

553565
try
554566
{
555-
if (_shouldRefresh)
556-
{
557-
_shouldRefresh = false;
558-
await agent?.Impl.RefreshChatAsync(this, force: false);
559-
}
567+
await RefreshChatAsNeeded(agent);
560568

561569
if (Regenerate)
562570
{
@@ -595,6 +603,12 @@ internal async Task RunREPLAsync()
595603
{
596604
continue;
597605
}
606+
else
607+
{
608+
// We may be switching to an agent that hasn't setup its chat session yet.
609+
// So, give it a chance to do so in that case.
610+
await RefreshChatAsNeeded(agent);
611+
}
598612
}
599613

600614
string copiedText = await GetClipboardContent(input);

shell/agents/AIShell.Interpreter.Agent/Agent.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,15 @@ public void Initialize(AgentConfig config)
7474
/// <inheritdoc/>
7575
public Task RefreshChatAsync(IShell shell, bool force)
7676
{
77-
// Reload the setting file if needed.
78-
ReloadSettings();
79-
// Reset the history so the subsequent chat can start fresh.
80-
_chatService.RefreshChat();
81-
// Shut down the execution service to start fresh.
82-
_executionService.Terminate();
77+
if (force)
78+
{
79+
// Reload the setting file if needed.
80+
ReloadSettings();
81+
// Reset the history so the subsequent chat can start fresh.
82+
_chatService.RefreshChat();
83+
// Shut down the execution service to start fresh.
84+
_executionService.Terminate();
85+
}
8386

8487
return Task.CompletedTask;
8588
}

shell/agents/AIShell.OpenAI.Agent/Agent.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,13 @@ public void OnUserAction(UserActionPayload actionPayload) {}
7979
/// <inheritdoc/>
8080
public Task RefreshChatAsync(IShell shell, bool force)
8181
{
82-
// Reload the setting file if needed.
83-
ReloadSettings();
84-
// Reset the history so the subsequent chat can start fresh.
85-
_chatService.ChatHistory.Clear();
82+
if (force)
83+
{
84+
// Reload the setting file if needed.
85+
ReloadSettings();
86+
// Reset the history so the subsequent chat can start fresh.
87+
_chatService.ChatHistory.Clear();
88+
}
8689

8790
return Task.CompletedTask;
8891
}

shell/agents/Microsoft.Azure.Agent/AzureAgent.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public AzureAgent()
7777

7878
public void Dispose()
7979
{
80-
ArgPlaceholder?.DataRetriever?.Dispose();
80+
ResetArgumentPlaceholder();
8181
_chatSession.Dispose();
8282
_httpClient.Dispose();
8383

@@ -120,6 +120,7 @@ public async Task RefreshChatAsync(IShell shell, bool force)
120120
{
121121
IHost host = shell.Host;
122122
CancellationToken cancellationToken = shell.CancellationToken;
123+
ResetArgumentPlaceholder();
123124

124125
try
125126
{
@@ -179,8 +180,7 @@ public async Task<bool> ChatAsync(string input, IShell shell)
179180

180181
if (_copilotResponse.ChunkReader is null)
181182
{
182-
ArgPlaceholder?.DataRetriever?.Dispose();
183-
ArgPlaceholder = null;
183+
ResetArgumentPlaceholder();
184184

185185
// Process CLI handler response specially to support parameter injection.
186186
ResponseData data = null;
@@ -360,6 +360,12 @@ private ResponseData ParseCLIHandlerResponse(IShell shell)
360360
return data;
361361
}
362362

363+
internal void ResetArgumentPlaceholder()
364+
{
365+
ArgPlaceholder?.DataRetriever?.Dispose();
366+
ArgPlaceholder = null;
367+
}
368+
363369
internal void SaveUserValue(string phName, string value)
364370
{
365371
ArgumentException.ThrowIfNullOrEmpty(phName);
@@ -465,7 +471,9 @@ internal string GenerateAnswer(ResponseData data)
465471
_buffer.Append($"- `{phItem.Name}`: {phItem.Desc}\n");
466472
}
467473

468-
_buffer.Append("\nRun `/replace` to get assistance in placeholder replacement.\n");
474+
// Use green (0,195,0) on grey (48,48,48) for rendering the command '/replace'.
475+
// TODO: the color formatting should be exposed by the shell as utility method.
476+
_buffer.Append("\nRun \x1b[38;2;0;195;0;48;2;48;48;48m /replace \x1b[0m to get assistance in placeholder replacement.\n");
469477
}
470478
}
471479

shell/agents/Microsoft.Azure.Agent/ChatSession.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ internal async Task<string> RefreshAsync(IStatusContext context, bool force, Can
7070
if (force)
7171
{
7272
// End the existing conversation.
73-
context.Status("End current chat ...");
73+
context.Status("Ending current chat ...");
7474
EndConversation();
7575
Reset();
7676
}
7777
else
7878
{
7979
try
8080
{
81-
context.Status("Refresh DirectLine token ...");
81+
context.Status("Refreshing token ...");
8282
await RenewTokenAsync(cancellationToken);
8383
return null;
8484
}

shell/agents/Microsoft.Azure.Agent/Command.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ private async Task<string> RegenerateAsync()
238238

239239
if (data.PlaceholderSet is null)
240240
{
241-
_agent.ArgPlaceholder.DataRetriever.Dispose();
242-
_agent.ArgPlaceholder = null;
241+
_agent.ResetArgumentPlaceholder();
243242
}
244243

245244
return _agent.GenerateAnswer(data);

0 commit comments

Comments
 (0)