AgentContextIndex

@Serializable
data class AgentContextIndex(val compactedRounds: AgentContextIndex.CompactedRounds?, val historyRounds: List<AgentContextIndex.CompletedRound>?, val currentRound: AgentContextIndex.CurrentRound?) : UuidIndex(source)

表示 Agent 的上下文,不持有任何消息,而是使用 UUID 索引。

在 AgentContext 的模型中,每条用户消息都会开启一个独立的轮次,每个轮次中 Agent 可能进行多轮工具调用,这些中间的工具调用称为 Turn。

每个 Turn 记录一条 Agent 消息和若干工具请求以及响应,Agent 在下一个 Turn 思考并继续调用工具。

如果 Agent 没有调用工具,Turn 将不会被创建,Agent 的消息将作为 finalAssistantMessage,CurrentRound 会被归档,转换为一条 CompletedRound 并进入 historyRounds。

Constructors

Link copied to clipboard
constructor(compactedRounds: AgentContextIndex.CompactedRounds?, historyRounds: List<AgentContextIndex.CompletedRound>?, currentRound: AgentContextIndex.CurrentRound?)

Types

Link copied to clipboard
@Serializable
data class CompactedRounds(val compactedRounds: AgentContextIndex.CompactedRounds?, val rounds: List<AgentContextIndex.CompletedRound>, val summarizedMessage: UUID) : UuidIndex

上下文压缩产生的归档,包含 summary 和 summary 覆盖的若干 CompletedRound

Link copied to clipboard
@Serializable
data class CompletedRound(val userMessage: UUID, val turns: List<AgentContextIndex.Turn>?, val finalAssistantMessage: UUID?) : UuidIndex

已完成的轮次,由用户手动终止 Agent 产生,或 LLM 在响应中未调用工具,此时 finalAssistantMessage 非空。

Link copied to clipboard
@Serializable
data class CurrentRound(val userMessage: UUID, val turns: List<AgentContextIndex.Turn>?, val assistantMessage: UUID?, val finishedToolCalls: List<AgentContextIndex.Turn.Tool>?, val pendingToolCalls: List<@Serializable(with = UuidSerializer::class) UUID>?) : UuidIndex

表示当前正在进行的一个轮次,由一条用户消息开启,LLM 将在一个轮次中进行工具调用 - 推理 - 工具调用的循环。

Link copied to clipboard
@Serializable
data class Turn(val assistantMessage: UUID, val tools: List<AgentContextIndex.Turn.Tool>) : UuidIndex

一个 Turn 由一次 LLM 思考产生,LLM 在 assistantMessage 中发起了 tools 中的所有调用,程序处理所有调用并为每一个请求生成响应,并再次调用 LLM。

Properties

Link copied to clipboard

压缩自 historyRounds 的消息,只有一条 summary 进入实际上下文。

Link copied to clipboard

正在进行的轮次。

Link copied to clipboard

已经完成的轮次。

Functions

Link copied to clipboard
open override fun ids(): Set<UUID>

整个索引结构中引用的全部 UUID