-
Notifications
You must be signed in to change notification settings - Fork 4k
.Net: Add a common agent invoke api. #11069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
westey-m
merged 12 commits into
microsoft:feature-common-agent-api
from
westey-m:common-agent-api
Mar 21, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f67a35f
Add a common agent invoke api.
westey-m f13b570
Fix typos and formatting.
westey-m a01628b
Merge branch 'main' into common-agent-api
westey-m af82b81
Fix ambiguous reference in xml docs
westey-m 3e0802f
Adding InvokeAsync signature to Agent class and updating it with new …
westey-m b544879
Naming update related to PR feedback
westey-m cc99661
Add streaming method and implementations
westey-m 68b5b60
Add integration tests for ChatCompletion and AzureOpenAIAssistant
westey-m 04a6f76
Add integration tests for Azure AI Agent.
westey-m 05fa6d8
Merge branch 'main' into common-agent-api
westey-m baba29a
Remove IsActive and rename Start and End
westey-m 0c2217e
Fix spelling error.
westey-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace Microsoft.SemanticKernel.Agents; | ||
|
||
/// <summary> | ||
/// Optional parameters for agent invocation. | ||
/// </summary> | ||
public class AgentInvokeOptions | ||
westey-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
/// <summary> | ||
/// Gets or sets any instructions, in addition to those that were provided to the agent | ||
/// initially, that need to be added to the prompt for this invocation only. | ||
/// </summary> | ||
public string AdditionalInstructions { get; init; } = string.Empty; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace Microsoft.SemanticKernel.Agents; | ||
|
||
/// <summary> | ||
/// Container class that holds a <see cref="ChatMessageContent"/> or <see cref="StreamingChatMessageContent"/> and an <see cref="AgentThread"/>. | ||
/// </summary> | ||
public class AgentResponseItem<TMessage> | ||
westey-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
private readonly TMessage _message; | ||
private readonly AgentThread _thread; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AgentResponseItem{T}"/> class. | ||
/// </summary> | ||
/// <param name="message">The chat message content.</param> | ||
/// <param name="thread">The conversation thread associated with the response.</param> | ||
public AgentResponseItem(TMessage message, AgentThread thread) | ||
{ | ||
Verify.NotNull(message); | ||
Verify.NotNull(thread); | ||
|
||
this._message = message; | ||
this._thread = thread; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the chat message content. | ||
/// </summary> | ||
public TMessage Message => this._message; | ||
westey-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/// <summary> | ||
/// Gets the conversation thread associated with the response. | ||
/// </summary> | ||
public AgentThread Thread => this._thread; | ||
} | ||
westey-m marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.SemanticKernel.Agents; | ||
|
||
/// <summary> | ||
/// Base abstraction for all Semantic Kernel agent threads. | ||
/// A thread represents a specific conversation with an agent. | ||
/// </summary> | ||
/// <remarks> | ||
/// This class is used to manage the lifecycle of an agent thread. | ||
/// The thread can be not-start, started or ended. | ||
/// </remarks> | ||
public abstract class AgentThread | ||
{ | ||
/// <summary> | ||
/// Gets the id of the current thread. | ||
/// </summary> | ||
public abstract string? Id { get; } | ||
|
||
/// <summary> | ||
/// Creates the thread and returns the thread id. | ||
/// </summary> | ||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param> | ||
/// <returns>The id of the new thread.</returns> | ||
public abstract Task<string> CreateAsync(CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Deletes the current thread. | ||
/// </summary> | ||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param> | ||
/// <returns>A task that completes when the thread has been ended.</returns> | ||
public abstract Task DeleteAsync(CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// This method is called when a new message has been contributed to the chat by any participant. | ||
/// </summary> | ||
/// <remarks> | ||
/// Inheritors can use this method to update their context based on the new message. | ||
/// </remarks> | ||
/// <param name="newMessage">The new message.</param> | ||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param> | ||
/// <returns>A task that completes when the context has been updated.</returns> | ||
public abstract Task OnNewMessageAsync(ChatMessageContent newMessage, CancellationToken cancellationToken = default); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.