Skip to content

Commit

Permalink
Refresh chat when switching to another agent. Also send the refresh
Browse files Browse the repository at this point in the history
… user action to agent. (#104)
  • Loading branch information
daxian-dbw authored Mar 27, 2024
1 parent 463edf7 commit f440c50
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>ShellCopilot.Abstraction</AssemblyName>

<PackageId>ShellCopilot.Abstraction</PackageId>
<Version>0.1.0-beta.8</Version>
<Version>0.1.0-beta.9</Version>
<Company>Microsoft Corporation</Company>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
Expand Down
10 changes: 10 additions & 0 deletions shell/ShellCopilot.Abstraction/UserAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public enum UserAction
/// User ran the 'retry' command.
/// </summary>
Retry,

/// <summary>
/// User ran the 'refresh' command.
/// </summary>
Refresh,
}

public abstract class UserActionPayload
Expand Down Expand Up @@ -93,3 +98,8 @@ public RetryPayload(string lastQuery)
LastQuery = lastQuery;
}
}

public sealed class RefreshPayload : UserActionPayload
{
public RefreshPayload() : base(UserAction.Refresh) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.18.0" />
<PackageReference Include="ShellCopilot.Abstraction" Version="0.1.0-beta.8">
<PackageReference Include="ShellCopilot.Abstraction" Version="0.1.0-beta.9">
<ExcludeAssets>contentFiles</ExcludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
15 changes: 9 additions & 6 deletions shell/ShellCopilot.Kernel/Command/AgentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ public AgentCommand()
private void UseAgentAction(string name)
{
var shell = (Shell)Shell;
var host = shell.Host;

LLMAgent chosenAgent = string.IsNullOrEmpty(name)
? shell.Host.PromptForSelectionAsync(
? host.PromptForSelectionAsync(
title: "[orange1]Please select an [Blue]agent[/] to use[/]:",
choices: shell.Agents,
converter: AgentName).GetAwaiter().GetResult()
Expand All @@ -53,25 +55,26 @@ private void UseAgentAction(string name)
}

shell.SwitchActiveAgent(chosenAgent);
shell.Host.MarkupLine($"Using the agent [green]{chosenAgent.Impl.Name}[/]:");
chosenAgent.Display(shell.Host);
host.MarkupLine($"Using the agent [green]{chosenAgent.Impl.Name}[/]:");
chosenAgent.Display(host);
}

private void PopAgentAction()
{
var shell = (Shell)Shell;
var host = shell.Host;

try
{
shell.PopActiveAgent();

var current = shell.ActiveAgent;
shell.Host.MarkupLine($"Using the agent [green]{current.Impl.Name}[/]:");
current.Display(shell.Host);
host.MarkupLine($"Using the agent [green]{current.Impl.Name}[/]:");
current.Display(host);
}
catch (Exception ex)
{
shell.Host.WriteErrorLine(ex.Message);
host.WriteErrorLine(ex.Message);
}
}

Expand Down
1 change: 1 addition & 0 deletions shell/ShellCopilot.Kernel/Command/RefreshCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ private void RefreshAction()

var shell = (Shell)Shell;
shell.ActiveAgent.Impl.RefreshChat();
shell.OnUserAction(new RefreshPayload());
shell.ShowBanner();
shell.ShowLandingPage();
}
Expand Down
3 changes: 3 additions & 0 deletions shell/ShellCopilot.Kernel/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ internal void PushActiveAgent(LLMAgent agent)
if (loadCommands)
{
ILLMAgent impl = agent.Impl;
impl.RefreshChat();
CommandRunner.UnloadAgentCommands();
CommandRunner.LoadCommands(impl.GetCommands(), impl.Name);
}
Expand Down Expand Up @@ -330,13 +331,15 @@ internal void SwitchActiveAgent(LLMAgent agent)
_activeAgentStack.Push(agent);
if (current != agent)
{
impl.RefreshChat();
CommandRunner.UnloadAgentCommands();
CommandRunner.LoadCommands(impl.GetCommands(), impl.Name);
}
}
else
{
_activeAgentStack.Push(agent);
impl.RefreshChat();
CommandRunner.LoadCommands(impl.GetCommands(), impl.Name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.6" />
<PackageReference Include="Azure.Core" Version="1.34.0" />
<PackageReference Include="SharpToken" Version="1.2.2" />
<PackageReference Include="ShellCopilot.Abstraction" Version="0.1.0-beta.8">
<PackageReference Include="ShellCopilot.Abstraction" Version="0.1.0-beta.9">
<ExcludeAssets>contentFiles</ExcludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit f440c50

Please sign in to comment.