AgentThread Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Base abstraction for all agent threads.
public abstract class AgentThread
type AgentThread = class
Public MustInherit Class AgentThread
- Inheritance
-
AgentThread
- Derived
Remarks
An AgentThread contains the state of a specific conversation with an agent which may include:
- Conversation history or a reference to externally stored conversation history.
- Memories or a reference to externally stored memories.
- Any other state that the agent needs to persist across runs for a conversation.
An AgentThread may also have behaviors attached to it that may include:
- Customized storage of state.
- Data extraction from and injection into a conversation.
- Chat history reduction, e.g. where messages needs to be summarized or truncated to reduce the size.
Because of these behaviors, an AgentThread may not be reusable across different agents, since each agent may add different behaviors to the AgentThread it creates.
To support conversations that may need to survive application restarts or separate service requests, an AgentThread can be serialized and deserialized, so that it can be saved in a persistent store. The AgentThread provides the Serialize(JsonSerializerOptions) method to serialize the thread to a JsonElement and the DeserializeThread(JsonElement, JsonSerializerOptions) method can be used to deserialize the thread.
Constructors
| AgentThread() |
Initializes a new instance of the AgentThread class. |
Methods
| GetService(Type, Object) |
Asks the AgentThread for an object of the specified type |
| GetService<TService>(Object) |
Asks the AgentThread for an object of type |
| MessagesReceivedAsync(IEnumerable<ChatMessage>, CancellationToken) |
This method is called when new messages have been contributed to the chat by any participant. |
| Serialize(JsonSerializerOptions) |
Serializes the current object's state to a JsonElement using the specified serialization options. |