Skip to content

Commit 77247a3

Browse files
authored
.NET: Change thread_id from entity ID to GUID (#2260)
1 parent e413c5a commit 77247a3

File tree

5 files changed

+39
-18
lines changed

5 files changed

+39
-18
lines changed

dotnet/samples/AzureFunctions/01_SingleAgent/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ curl -X POST http://localhost:7071/api/agents/Joker/run \
4747
To continue a conversation, include the `thread_id` in the query string or JSON body:
4848

4949
```bash
50-
curl -X POST "http://localhost:7071/api/agents/Joker/run?thread_id=@dafx-joker@your-thread-id" \
50+
curl -X POST "http://localhost:7071/api/agents/Joker/run?thread_id=your-thread-id" \
5151
-H "Content-Type: application/json" \
5252
-H "Accept: application/json" \
5353
-d '{"message": "Tell me another one."}'
@@ -64,7 +64,7 @@ The expected `application/json` output will look something like:
6464
```json
6565
{
6666
"status": 200,
67-
"thread_id": "@dafx-joker@your-thread-id",
67+
"thread_id": "ee6e47a0-f24b-40b1-ade8-16fcebb9eb40",
6868
"response": {
6969
"Messages": [
7070
{

dotnet/samples/AzureFunctions/06_LongRunningTools/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ The response will be a text string that looks something like the following, indi
5252
```http
5353
HTTP/1.1 200 OK
5454
Content-Type: text/plain
55-
x-ms-thread-id: @publisher@351ec855-7f4d-4527-a60d-498301ced36d
55+
x-ms-thread-id: 351ec855-7f4d-4527-a60d-498301ced36d
5656
5757
The content generation workflow for the topic "The Future of Artificial Intelligence" has been successfully started, and the instance ID is **6a04276e8d824d8d941e1dc4142cc254**. If you need any further assistance or updates on the workflow, feel free to ask!
5858
```

dotnet/src/Microsoft.Agents.AI.Hosting.AzureFunctions/BuiltInFunctions.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ public static async Task<HttpResponseData> RunAgentHttpAsync(
8383

8484
string? threadIdValue = threadIdFromBody ?? threadIdFromQuery;
8585

86-
// If no session ID is provided, use a new one based on the function name and invocation ID.
87-
// This may be better than a random one because it can be correlated with the function invocation.
88-
// Specifying a session ID is how the caller correlates multiple calls to the same agent session.
86+
// The thread_id is treated as a session key (not a full session ID).
87+
// If no session key is provided, use the function invocation ID as the session key
88+
// to help correlate the session with the function invocation.
89+
string agentName = GetAgentName(context);
8990
AgentSessionId sessionId = string.IsNullOrEmpty(threadIdValue)
90-
? new AgentSessionId(GetAgentName(context), context.InvocationId)
91-
: AgentSessionId.Parse(threadIdValue);
91+
? new AgentSessionId(agentName, context.InvocationId)
92+
: new AgentSessionId(agentName, threadIdValue);
9293

9394
if (string.IsNullOrWhiteSpace(message))
9495
{
@@ -110,7 +111,7 @@ public static async Task<HttpResponseData> RunAgentHttpAsync(
110111
}
111112
}
112113

113-
AIAgent agentProxy = client.AsDurableAgentProxy(context, GetAgentName(context));
114+
AIAgent agentProxy = client.AsDurableAgentProxy(context, agentName);
114115

115116
DurableAgentRunOptions options = new() { IsFireAndForget = !waitForResponse };
116117

@@ -126,7 +127,7 @@ public static async Task<HttpResponseData> RunAgentHttpAsync(
126127
req,
127128
context,
128129
HttpStatusCode.OK,
129-
sessionId.ToString(),
130+
sessionId.Key,
130131
agentResponse);
131132
}
132133

@@ -140,7 +141,7 @@ await agentProxy.RunAsync(
140141
return await CreateAcceptedResponseAsync(
141142
req,
142143
context,
143-
sessionId.ToString());
144+
sessionId.Key);
144145
}
145146

146147
public static async Task<string?> RunMcpToolAsync(

dotnet/tests/Microsoft.Agents.AI.Hosting.AzureFunctions.IntegrationTests/SamplesValidation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ await this.RunSampleTestAsync(samplePath, async (logs) =>
7575
// The response headers should include the agent thread ID, which can be used to continue the conversation.
7676
string? threadId = response.Headers.GetValues("x-ms-thread-id")?.FirstOrDefault();
7777
Assert.NotNull(threadId);
78+
Assert.NotEmpty(threadId);
7879

7980
this._outputHelper.WriteLine($"Agent thread ID: {threadId}");
80-
Assert.StartsWith("@dafx-joker@", threadId);
8181

8282
// Wait for up to 30 seconds to see if the agent response is available in the logs
8383
await this.WaitForConditionAsync(
@@ -289,7 +289,7 @@ await this.RunSampleTestAsync(samplePath, async (logs) =>
289289
startResponse.Headers.TryGetValues("x-ms-thread-id", out IEnumerable<string>? agentIdValues);
290290
string? threadId = agentIdValues?.FirstOrDefault();
291291
Assert.NotNull(threadId);
292-
Assert.StartsWith("@dafx-publisher@", threadId);
292+
Assert.NotEmpty(threadId);
293293

294294
// Wait for the orchestration to report that it's waiting for human approval
295295
await this.WaitForConditionAsync(

python/samples/getting_started/azure_functions/01_single_agent/README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,40 @@ Follow the common setup steps in `../README.md` to install tooling, configure Az
1818

1919
Send a prompt to the Joker agent:
2020

21+
Bash (Linux/macOS/WSL):
22+
2123
```bash
22-
curl -X POST http://localhost:7071/api/agents/Joker/run \
23-
-H "Content-Type: text/plain" \
24+
curl -i -X POST http://localhost:7071/api/agents/Joker/run \
2425
-d "Tell me a short joke about cloud computing."
2526
```
2627

28+
PowerShell:
29+
30+
```powershell
31+
Invoke-RestMethod -Method Post -Uri http://localhost:7071/api/agents/Joker/run `
32+
-Body "Tell me a short joke about cloud computing."
33+
```
34+
2735
The agent responds with a JSON payload that includes the generated joke.
2836

29-
> **Note:** To return immediately with an HTTP 202 response instead of waiting for the agent output, set the `x-ms-wait-for-response` header or include `"wait_for_response": false` in the request body. The default behavior waits for the response.
37+
> [!TIP]
38+
> To return immediately with an HTTP 202 response instead of waiting for the agent output, set the `x-ms-wait-for-response` header or include `"wait_for_response": false` in the request body. The default behavior waits for the response.
3039
3140
## Expected Output
3241

33-
When you send a POST request with plain-text input, the Functions host responds with an HTTP 202 and queues the request for the durable agent entity. A typical response body looks like the following:
34-
Expected HTTP 202 payload:
42+
The default plain-text response looks like the following:
43+
44+
```http
45+
HTTP/1.1 200 OK
46+
Content-Type: text/plain; charset=utf-8
47+
x-ms-thread-id: 4f205157170244bfbd80209df383757e
48+
49+
Why did the cloud break up with the server?
50+
51+
Because it found someone more "uplifting"!
52+
```
53+
54+
When you specify the `x-ms-wait-for-response` header or include `"wait_for_response": false` in the request body, the Functions host responds with an HTTP 202 and queues the request to run in the background. A typical response body looks like the following:
3555

3656
```json
3757
{

0 commit comments

Comments
 (0)