Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ public override async IAsyncEnumerable<ResponseStreamEvent> CreateAsync(
// point below: AsyncLocal writes made in this streaming iterator are reverted across yield
// boundaries, so a single up-front assignment would be lost before the toolbox/MCP calls run.
var platformCallId = context.PlatformContext?.CallId;
var toolboxRequestScope = this._toolboxService?.CreateRequestScope()
?? FoundryToolboxService.RequestToolboxScope.CreateInactive();
await using var configuredToolboxRequestScope = toolboxRequestScope.ConfigureAwait(false);
HostedCallContext.CallId = platformCallId;
HostedCallContext.ToolboxCacheScopeId = toolboxRequestScope?.Id;

// Stamp/validate the hosted identity only when one was resolved. Locally (non-hosted) there is
// no user identity, so there is nothing to partition or tamper-check and the session is shared.
Expand Down Expand Up @@ -278,6 +282,7 @@ public override async IAsyncEnumerable<ResponseStreamEvent> CreateAsync(
// Re-apply the call id: the EmitCreated/EmitInProgress yields above reverted the ambient
// value, and the toolbox tools/list + consent egress below must carry it per request.
HostedCallContext.CallId = platformCallId;
HostedCallContext.ToolboxCacheScopeId = toolboxRequestScope?.Id;

var toolboxResolution = await this.ResolveToolboxToolsAsync(
this._toolboxService,
Expand Down Expand Up @@ -382,6 +387,7 @@ public override async IAsyncEnumerable<ResponseStreamEvent> CreateAsync(
// below revert the ambient AsyncLocal, but the MCP tools/call egress that happens
// inside MoveNextAsync must carry the platform call id on every request.
HostedCallContext.CallId = platformCallId;
HostedCallContext.ToolboxCacheScopeId = toolboxRequestScope?.Id;

bool shutdownDetected = false;
McpConsentInfo? consentInfo = null;
Expand Down Expand Up @@ -754,7 +760,7 @@ await toolboxService
return new(Tools: [], Consents: pendingConsents, Error: null);
}

List<AITool> toolsToAdd = [.. toolboxService.Tools];
List<AITool> toolsToAdd = [.. toolboxService.Tools, .. toolboxService.GetCurrentRequestTools()];
var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
List<McpConsentInfo>? markerConsents = null;

Expand Down
Loading
Loading