Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion dotnet/src/Microsoft.Agents.AI.A2A/A2AAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private A2AAgentThread GetA2AThread(AgentThread? thread, AgentRunOptions? option

if (thread is not A2AAgentThread typedThread)
{
throw new InvalidOperationException("The provided thread is not compatible with the agent. Only threads created by the agent can be used.");
throw new InvalidOperationException($"The provided thread type {thread.GetType()} is not compatible with the agent. Only A2A agent created threads are supported.");
}

return typedThread;
Expand Down
19 changes: 3 additions & 16 deletions dotnet/tests/Microsoft.Agents.AI.A2A.UnitTests/A2AAgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -839,16 +839,11 @@ await Assert.ThrowsAsync<InvalidOperationException>(async () =>
public async Task RunAsync_WithInvalidThreadType_ThrowsInvalidOperationExceptionAsync()
{
// Arrange
var inputMessages = new List<ChatMessage>
{
new(ChatRole.User, "Test message")
};

// Create a thread from a different agent type
var invalidThread = new CustomAgentThread();

// Act & Assert
await Assert.ThrowsAsync<InvalidOperationException>(() => this._agent.RunAsync(inputMessages, invalidThread));
await Assert.ThrowsAsync<InvalidOperationException>(() => this._agent.RunAsync(invalidThread));
}

[Fact]
Expand All @@ -864,13 +859,7 @@ public async Task RunStreamingAsync_WithInvalidThreadType_ThrowsInvalidOperation
var invalidThread = new CustomAgentThread();

// Act & Assert
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
{
await foreach (var _ in this._agent.RunStreamingAsync(inputMessages, invalidThread))
{
// Just iterate through to trigger the exception
}
});
await Assert.ThrowsAsync<InvalidOperationException>(async () => await this._agent.RunStreamingAsync(inputMessages, invalidThread).ToListAsync());
}

public void Dispose()
Expand All @@ -882,9 +871,7 @@ public void Dispose()
/// <summary>
/// Custom agent thread class for testing invalid thread type scenario.
/// </summary>
private sealed class CustomAgentThread : AgentThread
{
}
private sealed class CustomAgentThread : AgentThread;

internal sealed class A2AClientHttpMessageHandlerStub : HttpMessageHandler
{
Expand Down