mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.NET: Improve Todo multithreading and inject todos into message list (#5655)
* Improve Todo multithreading and inject todos into message list * Address PR comments
This commit is contained in:
@@ -24,5 +24,5 @@ public interface ICommandHandler
|
||||
/// <param name="input">The raw user input string.</param>
|
||||
/// <param name="session">The current agent session.</param>
|
||||
/// <returns><see langword="true"/> if this handler handled the input; <see langword="false"/> otherwise.</returns>
|
||||
bool TryHandle(string input, AgentSession session);
|
||||
ValueTask<bool> TryHandleAsync(string input, AgentSession session);
|
||||
}
|
||||
|
||||
+5
-5
@@ -27,17 +27,17 @@ internal sealed class ModeCommandHandler : ICommandHandler
|
||||
public string? GetHelpText() => this._modeProvider is not null ? "/mode [plan|execute] (show or switch mode)" : null;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool TryHandle(string input, AgentSession session)
|
||||
public ValueTask<bool> TryHandleAsync(string input, AgentSession session)
|
||||
{
|
||||
if (!input.StartsWith("/mode ", StringComparison.OrdinalIgnoreCase) && !input.Equals("/mode", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
return ValueTask.FromResult(false);
|
||||
}
|
||||
|
||||
if (this._modeProvider is null)
|
||||
{
|
||||
System.Console.WriteLine("AgentModeProvider is not available.");
|
||||
return true;
|
||||
return ValueTask.FromResult(true);
|
||||
}
|
||||
|
||||
string[] parts = input.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
@@ -45,7 +45,7 @@ internal sealed class ModeCommandHandler : ICommandHandler
|
||||
{
|
||||
string current = this._modeProvider.GetMode(session);
|
||||
System.Console.WriteLine($"\n Current mode: {current}\n");
|
||||
return true;
|
||||
return ValueTask.FromResult(true);
|
||||
}
|
||||
|
||||
string newMode = parts[1];
|
||||
@@ -64,6 +64,6 @@ internal sealed class ModeCommandHandler : ICommandHandler
|
||||
System.Console.ResetColor();
|
||||
}
|
||||
|
||||
return true;
|
||||
return ValueTask.FromResult(true);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ internal sealed class TodoCommandHandler : ICommandHandler
|
||||
public string? GetHelpText() => this._todoProvider is not null ? "/todos (show todo list)" : null;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool TryHandle(string input, AgentSession session)
|
||||
public async ValueTask<bool> TryHandleAsync(string input, AgentSession session)
|
||||
{
|
||||
if (!input.Equals("/todos", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
@@ -37,7 +37,7 @@ internal sealed class TodoCommandHandler : ICommandHandler
|
||||
return true;
|
||||
}
|
||||
|
||||
var todos = this._todoProvider.GetAllTodos(session);
|
||||
var todos = await this._todoProvider.GetAllTodosAsync(session).ConfigureAwait(false);
|
||||
if (todos.Count == 0)
|
||||
{
|
||||
System.Console.WriteLine("\n No todos yet.\n");
|
||||
|
||||
@@ -69,7 +69,7 @@ public static class HarnessConsole
|
||||
bool handled = false;
|
||||
foreach (var handler in commandHandlers)
|
||||
{
|
||||
if (handler.TryHandle(userInput, session))
|
||||
if (await handler.TryHandleAsync(userInput, session).ConfigureAwait(false))
|
||||
{
|
||||
handled = true;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user