You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instructions="You are a helpful support specialist for Contoso Outdoors. Answer questions using the provided context and cite the source document when available.",
30
+
ChatOptions=new() { Instructions="You are a helpful support specialist for Contoso Outdoors. Answer questions using the provided context and cite the source document when available." },
Copy file name to clipboardExpand all lines: agent-framework/user-guide/agents/multi-turn-conversation.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,10 +17,10 @@ The Microsoft Agent Framework provides built-in support for managing multi-turn
17
17
18
18
For example, when using a ChatClientAgent based on a foundry agent, the conversation history is persisted in the service. While, when using a ChatClientAgent based on chat completion with gpt-4.1 the conversation history is in-memory and managed by the agent.
19
19
20
-
The `AgentThread` type is the abstraction that represents a conversation thread with an agent.
20
+
The `AgentThread` type is the abstraction that represents conversation history and other state of an agent.
21
21
`AIAgent` instances are stateless and the same agent instance can be used with multiple `AgentThread` instances. All state is therefore preserved in the `AgentThread`.
22
22
An `AgentThread` can both represent chat history plus any other state that the agent needs to preserve across multiple interactions.
23
-
The chat history may be stored in the thread itself, or remotely, with the `AgentThread` only containing a reference to the remote chat history.
23
+
The conversation history may be stored in the `AgentThread` object itself, or remotely, with the `AgentThread` only containing a reference to the remote conversation history.
24
24
The `AgentThread` state may also include memories or references to memories stored remotely.
25
25
26
26
> [!TIP]
@@ -31,9 +31,9 @@ The `AgentThread` state may also include memories or references to memories stor
31
31
`AgentThread` instances can be created in two ways:
32
32
33
33
1. By calling `GetNewThread` on the agent.
34
-
1. By running the agent and not providing an `AgentThread`. In this case the agent will create a throwaway `AgentThread`with an underlying thread which will only be used for the duration of the run.
34
+
1. By running the agent and not providing an `AgentThread`. In this case the agent will create a throwaway `AgentThread` which will only be used for the duration of the run.
35
35
36
-
Some underlying threads might be persistently created in an underlying service, where the service requires this, for example, Foundry Agents or OpenAI Responses. Any cleanup or deletion of these threads is the responsibility of the user.
36
+
Some underlying service stored conversations/threads/responses might be persistently created in an underlying service, where the service requires this, for example, Foundry Agents or OpenAI Responses. Any cleanup or deletion of these is the responsibility of the user.
37
37
38
38
::: zone pivot="programming-language-csharp"
39
39
@@ -54,7 +54,7 @@ response = await agent.RunAsync("Hello, how are you?");
54
54
`AgentThread` instances can be serialized and stored for later use. This allows for the preservation of conversation context across different sessions or service calls.
55
55
56
56
For cases where the conversation history is stored in a service, the serialized `AgentThread` will contain an
57
-
id of the thread in the service.
57
+
id that points to the conversation history in the service.
58
58
For cases where the conversation history is managed in-memory, the serialized `AgentThread` will contain the messages
59
59
themselves.
60
60
@@ -85,21 +85,20 @@ The differences between the underlying threading models are abstracted away via
85
85
86
86
`AIAgent` instances are stateless and the same agent instance can be used with multiple `AgentThread` instances.
87
87
88
-
Not all agents support all thread types though. For example if you are using a `ChatClientAgent` with the responses service, `AgentThread` instances created by this agent, will not work with a `ChatClientAgent` using the Foundry Agent service.
89
-
This is because these services both support saving the conversation history in the service, and the `AgentThread`
90
-
only has a reference to this service managed thread.
88
+
Not all agents support all `AgentThread` types though. For example if you are using a `ChatClientAgent` with the responses service, `AgentThread` instances created by this agent, will not work with a `ChatClientAgent` using the Foundry Agent service.
89
+
This is because these services both support saving the conversation history in the service, and while the two `AgentThread` instances will have references to each service stored conversation, the id from the responses service cannot be used with the Foundry Agent service, and vice versa.
91
90
92
91
It is therefore considered unsafe to use an `AgentThread` instance that was created by one agent with a different agent instance, unless you are aware of the underlying threading model and its implications.
93
92
94
-
## Threading support by service / protocol
93
+
## Conversation history support by service / protocol
95
94
96
-
| Service |Threading Support |
95
+
| Service |Conversation History Support |
97
96
|---------|--------------------|
98
-
| Foundry Agents | Service managed persistent threads|
99
-
| OpenAI Responses | Service managed persistent threads OR in-memory threads|
100
-
| OpenAI ChatCompletion | In-memory threads|
101
-
| OpenAI Assistants | Service managed threads|
102
-
| A2A | Service managed threads|
97
+
| Foundry Agents | Service stored persistent conversation history|
98
+
| OpenAI Responses | Service stored response chains OR in-memory conversation history|
| OpenAI Assistants | Service stored persistent conversation history|
101
+
| A2A | Service stored persistent conversation history|
103
102
104
103
::: zone-end
105
104
@@ -112,7 +111,7 @@ It is therefore considered unsafe to use an `AgentThread` instance that was crea
112
111
1. By calling `get_new_thread()` on the agent.
113
112
1. By running the agent and not providing an `AgentThread`. In this case the agent will create a throwaway `AgentThread` with an underlying thread which will only be used for the duration of the run.
114
113
115
-
Some underlying threads might be persistently created in an underlying service, where the service requires this, for example, Azure AI Agents or OpenAI Responses. Any cleanup or deletion of these threads is the responsibility of the user.
114
+
Some underlying service stored conversations/threads/responses might be persistently created in an underlying service, where the service requires this, for example, Azure AI Agents or OpenAI Responses. Any cleanup or deletion of these is the responsibility of the user.
116
115
117
116
```python
118
117
# Create a new thread.
@@ -129,7 +128,7 @@ response = await agent.run("Hello, how are you?")
129
128
`AgentThread` instances can be serialized and stored for later use. This allows for the preservation of conversation context across different sessions or service calls.
130
129
131
130
For cases where the conversation history is stored in a service, the serialized `AgentThread` will contain an
132
-
id of the thread in the service.
131
+
id that points to the conversation history in the service.
133
132
For cases where the conversation history is managed in-memory, the serialized `AgentThread` will contain the messages
134
133
themselves.
135
134
@@ -180,7 +179,8 @@ async with AzureCliCredential() as credential:
180
179
181
180
`Agents` are stateless and the same agent instance can be used with multiple `AgentThread` instances.
182
181
183
-
Not all agents support all thread types though. For example if you are using a `ChatAgent` with the OpenAI Responses service and `store=True`, `AgentThread` instances used by this agent, will not work with a `ChatAgent` using the Azure AI Agent service, because the thread_ids are not compatible.
182
+
Not all agents support all `AgentThread` types though. For example if you are using a `ChatAgent` with the OpenAI Responses service and `store=True`, `AgentThread` instances used by this agent, will not work with a `ChatAgent` using the Azure AI Agent service.
183
+
This is because these services both support saving the conversation history in the service, and while the two `AgentThread` instances will have references to each service stored conversation, the id from the OpenAI Responses service cannot be used with the Foundry Agent service, and vice versa.
184
184
185
185
It is therefore considered unsafe to use an `AgentThread` instance that was created by one agent with a different agent instance, unless you are aware of the underlying threading model and its implications.
0 commit comments