Skip to content

Commit eba1e7a

Browse files
authored
Update flight flags and make corresponding changes (#355)
1. Add the flag `pipelineorchestration` per the Azure Copilot team's request. 2. Update flag values based on the values used by Azure Portal, and remove 2 flags that are no longer used by Azure Portal. 3. Update the topic names for AzCLI handler and AzPS handler. They changed after adopting the new flag values. 4. Simplify the instruction prompt to save words for the input. Also include Azure PowerShell in the instruction. 5. Use better OS description for the instruction prompt. 6. Log the topic name for every response, for diagnostic purpose. We already send this information in telemetry. 7. Fix a bug in response parsing in the validation of the beginning of placeholder section. 8. Fix the status report to only report `ProgressTopic` status, which are progress reports only (fix #352). 9. Special case `TaskCanceledException` in AzCLI metadata query for logging and telemetry collection. This exception simply means the query action timed out after 1200 ms. Given that the metadata endpoint is an Azure Function, this could easily happen when the query hits a cold start of the function app. So, we don't want to log the exception object here.
1 parent e9bc956 commit eba1e7a

File tree

4 files changed

+64
-18
lines changed

4 files changed

+64
-18
lines changed

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

+42-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics;
2+
using System.Runtime.InteropServices;
23
using System.Text;
34

45
using AIShell.Abstraction;
@@ -22,11 +23,11 @@ public sealed class AzureAgent : ILLMAgent
2223
private const string SettingFileName = "az.config.json";
2324
private const string LoggingFileName = "log..txt";
2425
private const string InstructionPrompt = """
25-
NOTE: follow the below instructions when generating responses that include Azure CLI commands with placeholders:
26-
1. User's OS is `{0}`. Make sure the generated commands are suitable for the specified OS.
27-
2. DO NOT include the command for creating a new resource group unless the query explicitly asks for it. Otherwise, assume a resource group already exists.
28-
3. DO NOT include an additional example with made-up values unless it provides additional context or value beyond the initial command.
29-
4. DO NOT use the line continuation operator (backslash `\` in Bash) in the generated commands.
26+
NOTE: Follow the instructions below when generating Azure CLI or Azure PowerShell commands with placeholders:
27+
1. The targeting OS is '{0}'.
28+
2. Always assume the user has logged in Azure and a resource group already exists.
29+
3. DO NOT include any additional examples with made-up values.
30+
4. DO NOT use the line continuation operator (backslash `\`) in commands.
3031
5. Always represent a placeholder in the form of `<placeholder-name>` and enclose it within double quotes.
3132
6. Always use the consistent placeholder names across all your responses. For example, `<resourceGroupName>` should be used for all the places where a resource group name value is needed.
3233
7. When the commands contain placeholders, the placeholders should be summarized in markdown bullet points at the end of the response in the same order as they appear in the commands, following this format:
@@ -56,7 +57,9 @@ public AzureAgent()
5657

5758
_chatSession = new ChatSession(_httpClient);
5859
_valueStore = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
59-
_instructions = string.Format(InstructionPrompt, Environment.OSVersion.VersionString);
60+
_instructions = string.Format(
61+
InstructionPrompt,
62+
OperatingSystem.IsMacOS() ? $"Mac OS X {Environment.OSVersion.Version}" : RuntimeInformation.OSDescription);
6063

6164
Name = "azure";
6265
Company = "Microsoft";
@@ -326,6 +329,7 @@ public async Task<bool> ChatAsync(string input, IShell shell)
326329
}
327330
}
328331

332+
Log.Debug("[AzureAgent] TopicName: {0}", _copilotResponse.TopicName);
329333
Telemetry.Trace(AzTrace.Chat(_copilotResponse));
330334
}
331335
catch (Exception ex)
@@ -417,13 +421,8 @@ private ResponseData ParseCodeResponse(IShell shell)
417421
// - `<second-placeholder>`: <concise-description>
418422
const string pattern = "- `{0}`:";
419423
int index = text.IndexOf(string.Format(pattern, first), begin);
420-
if (index > 0 && text[index - 1] is '\n' && text[index - 2] is ':')
424+
if (index > 0 && IsInPlaceholderSection(text, index, out begin))
421425
{
422-
// Get the start index of the placeholder section.
423-
int n = index - 2;
424-
for (; text[n] is not '\n'; n--);
425-
begin = n + 1;
426-
427426
// For each placeholder, try to extract its description.
428427
foreach (var phItem in placeholders)
429428
{
@@ -453,6 +452,37 @@ private ResponseData ParseCodeResponse(IShell shell)
453452

454453
ReplaceKnownPlaceholders(data);
455454
return data;
455+
456+
static bool IsInPlaceholderSection(string text, int index, out int sectionStart)
457+
{
458+
// This section should immediately follow "Placeholders:" on the next line.
459+
// The "- `<xxx>`" part mostly starts at the beginning of the new line, but
460+
// sometimes starts after a few space characters.
461+
int firstNonSpaceCharBackward = -1;
462+
for (int i = index - 1; i >= 0; i--)
463+
{
464+
if (text[i] is not ' ')
465+
{
466+
firstNonSpaceCharBackward = i;
467+
break;
468+
}
469+
}
470+
471+
if (firstNonSpaceCharBackward > 0
472+
&& text[firstNonSpaceCharBackward] is '\n'
473+
&& text[firstNonSpaceCharBackward - 1] is ':')
474+
{
475+
// Get the start index of the placeholder section.
476+
int n = firstNonSpaceCharBackward - 1;
477+
for (; text[n] is not '\n'; n--);
478+
479+
sectionStart = n + 1;
480+
return true;
481+
}
482+
483+
sectionStart = -1;
484+
return false;
485+
}
456486
}
457487

458488
internal void ResetArgumentPlaceholder()

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal ChatSession(HttpClient httpClient)
3636
_flights = new Dictionary<string, object>()
3737
{
3838
["openAIModel"] = "gpt4optum",
39-
["openAIEndpointName"] = "norwayeast,australiaeast,swedencentral",
39+
["openAIEndpointName"] = "australiaeast,norwayeast",
4040
["docsHandlerEndpoint"] = "learnDocs",
4141
["unifiedcopilotdebug"] = false,
4242
["unifiedcopilottest"] = false,
@@ -52,11 +52,10 @@ internal ChatSession(HttpClient httpClient)
5252
["copilotmanageability"] = true,
5353
["gpt4tcsprompt"] = true,
5454
["copilotmanageabilityuimenu"] = true,
55-
["usenewchatinputcomponent"] = true, // not sure what this is for
5655
["getformstate"] = true,
57-
["notificationcopilotbuttonallerror"] = false,
5856
["chitchatprompt"] = true,
5957
["azurepluginstore"] = true,
58+
["pipelineorchestration"] = true,
6059
// TODO: the streaming is slow and not sending chunks, very clumsy for now.
6160
// ["streamresponse"] = true,
6261
};
@@ -315,7 +314,10 @@ internal async Task<CopilotResponse> GetChatResponseAsync(string input, IStatusC
315314

316315
if (activity.IsTyping)
317316
{
318-
context?.Status(activity.Text);
317+
if (activity.TopicName is CopilotActivity.ProgressTopic)
318+
{
319+
context?.Status(activity.Text);
320+
}
319321
continue;
320322
}
321323

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

+13
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,19 @@ private AzCLICommand QueryForMetadata(string azCommand)
885885
command = metadata.Deserialize<AzCLICommand>(Utils.JsonOptions);
886886
}
887887
}
888+
catch (TaskCanceledException)
889+
{
890+
Log.Error("[QueryForMetadata] Metadata query timed out (1200ms): {0}", azCommand);
891+
if (Telemetry.Enabled)
892+
{
893+
Dictionary<string, string> details = new()
894+
{
895+
["Command"] = azCommand,
896+
["Message"] = "AzCLI metadata query timed out (1200ms)."
897+
};
898+
Telemetry.Trace(AzTrace.Exception(details));
899+
}
900+
}
888901
catch (Exception e)
889902
{
890903
Log.Error(e, "[QueryForMetadata] Exception while processing command: {0}", azCommand);

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ internal class CopilotActivity
120120
{
121121
public const string ConversationStateName = "azurecopilot/conversationstate";
122122
public const string SuggestedResponseName = "azurecopilot/suggesteduserresponses";
123-
public const string CLIHandlerTopic = "generate_azure_cli_scripts";
124-
public const string PSHandlerTopic = "generate_powershell_script";
123+
public const string CLIHandlerTopic = "generate_azure_cli_scripts,Orchestrator_Respond";
124+
public const string PSHandlerTopic = "generate_powershell_script,Orchestrator_Respond";
125+
public const string ProgressTopic = "InProgressActivity";
125126

126127
public string Type { get; set; }
127128
public string Id { get; set; }

0 commit comments

Comments
 (0)