You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/AI/Service/CurrentSessionContext.cs

24 lines
742 B
C#

1 month ago
using System.Threading;
using AI.Models;
namespace AI.Service
{
/// <summary>
/// 当前会话上下文,供在 Kernel 工具调用(如知识库插件)中获取当前 ChatSession以便将结果写入 Store。
/// 由 KernelService 在 AskAsync/AskStreamAsync 开始时设置,结束时清空。
/// </summary>
public static class CurrentSessionContext
{
private static readonly AsyncLocal<ChatSession?> _current = new();
/// <summary>
/// 当前正在处理的聊天会话(仅在 LLM 调用链内有效)。
/// </summary>
public static ChatSession? Current
{
get => _current.Value;
set => _current.Value = value;
}
}
}