Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</FluentGridItem>
<FluentGridItem xs="11">
<div>
@((MarkupString)Markdown.ToHtml(agentChatMessage.Message.Content))
@((MarkupString)Markdown.ToHtml(agentChatMessage.Message.Item.Content))
</div>
<div>
使用されたエージェント: @string.Join(", ", agentChatMessage.Message.CalledAgentNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,8 @@ static string createStatusMessage(AgentOrchestratorStatus status)
var getAgentResponseTask = agentChatService.GetAgentResponseAsync(new AgentRequestDto(
Messages: [.. _messages.Where(x => x.IsRequestTarget).Select(x => x switch
{
UserChatMessage userChatMessage => new AgentRequestMessageItem(
userChatMessage.Role.ToRoleName(),
userChatMessage.Message),
AgentChatMessage agentChatMessage => new AgentRequestMessageItem(
agentChatMessage.Role.ToRoleName(),
agentChatMessage.Message.Content),
UserChatMessage userChatMessage => (MessageItem)new UserMessageItem(userChatMessage.Message),
AgentChatMessage agentChatMessage => agentChatMessage.Message.Item,
_ => throw new InvalidOperationException()
})],
RequireAdditionalInfo: _chatInput.RequireAdditionalInfo),
Expand Down
9 changes: 0 additions & 9 deletions DurableMultiAgentTemplate.Client/Model/ChatMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,3 @@ public enum Role
Info
}

public static class RoleExtensions
{
public static string ToRoleName(this Role role) => role switch
{
Role.User => "user",
Role.Assistant => "assistant",
_ => throw new InvalidOperationException()
};
}
7 changes: 5 additions & 2 deletions DurableMultiAgentTemplate.Shared/Model/AgentCall.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
namespace DurableMultiAgentTemplate.Shared.Model;
using System.Text.Json;
using System.Text.Json.Nodes;

namespace DurableMultiAgentTemplate.Shared.Model;


/// <summary>
/// Represents a call to an agent with a specified name and arguments.
/// </summary>
/// <param name="AgentName">The name of the agent being called.</param>
/// <param name="Arguments">The arguments to be passed to the agent.</param>
public record AgentCall(string AgentName, object Arguments);
public record AgentCall(string AgentName, JsonElement Arguments);
46 changes: 46 additions & 0 deletions DurableMultiAgentTemplate.Shared/Model/AgentMessageItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Text.Json.Serialization;

namespace DurableMultiAgentTemplate.Shared.Model;

/// <summary>
/// Represents a message item for an agent request.
/// </summary>
/// <param name="Role">The role of the agent.</param>
/// <param name="Content">The content of the message.</param>
[JsonDerivedType(typeof(UserMessageItem), typeDiscriminator: "user")]
[JsonDerivedType(typeof(AgentMessageItem), typeDiscriminator: "agent")]
public abstract record MessageItem(
AgentRole Role,
string Content);

public record UserMessageItem(string Content) : MessageItem(AgentRole.User, Content);

/// <summary>
/// Represents a message item for an agent response.
/// </summary>
/// <param name="Content">The content of the message.</param>
/// <param name="NextAgentCall">Represents the next agent to be called.</param>
[method: JsonConstructor]
public record AgentMessageItem(string Content,
AgentCall? NextAgentCall) : MessageItem(AgentRole.Agent, Content)
{
public AgentMessageItem(string content) : this(content, null)
{
}
}

/// <summary>
/// Represents the role of an agent.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum AgentRole
{
/// <summary>
/// Represents a user role.
/// </summary>
User,
/// <summary>
/// Represents a agent role.
/// </summary>
Agent
}
2 changes: 1 addition & 1 deletion DurableMultiAgentTemplate.Shared/Model/AgentRequestDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
/// <param name="Messages">A list of messages associated with the agent request.</param>
/// <param name="RequireAdditionalInfo">Indicates whether additional information is required for the agent request.</param>
public record AgentRequestDto(
List<AgentRequestMessageItem> Messages,
List<MessageItem> Messages,
bool RequireAdditionalInfo = false);
10 changes: 0 additions & 10 deletions DurableMultiAgentTemplate.Shared/Model/AgentRequestMessageItem.cs

This file was deleted.

6 changes: 3 additions & 3 deletions DurableMultiAgentTemplate.Shared/Model/AgentResponseDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace DurableMultiAgentTemplate.Shared.Model;
/// <summary>
/// Represents the response from an agent.
/// </summary>
/// <param name="Content">The content of the response.</param>
/// <param name="Item">The content of the response.</param>
/// <param name="CalledAgentNames">The list of names of the agents that were called.</param>
[method: JsonConstructor]
public record AgentResponseDto(
string Content,
AgentMessageItem Item,
List<string> CalledAgentNames)
{
public AgentResponseDto(string content) : this(content, [])
public AgentResponseDto(AgentMessageItem content) : this(content, [])
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace DurableMultiAgentTemplate.Shared.Model;
/// <param name="CalledAgentNames">The list of names of the agents that were called.</param>
/// <param name="AdditionalInfo">The additional information related to the response.</param>
[method: JsonConstructor]
public record AgentResponseWithAdditionalInfoDto(string Content,
public record AgentResponseWithAdditionalInfoDto(AgentMessageItem Content,
List<string> CalledAgentNames,
List<IAdditionalInfo> AdditionalInfo) : AgentResponseDto(Content, CalledAgentNames)
{
public AgentResponseWithAdditionalInfoDto(string content) : this(content, [], [])
public AgentResponseWithAdditionalInfoDto(AgentMessageItem content) : this(content, [], [])
{
}
}
Loading
Loading