chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、 Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。 今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
commit
7ec21f35b0
5767 files changed
+1436788
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"academy/internal/agent/compaction"
|
||||
"academy/internal/logger"
|
||||
"academy/internal/types"
|
||||
)
|
||||
|
||||
// SetContextCheckpointSink enables persisting compaction checkpoints. Nil (the
|
||||
// default) keeps every compaction local to the turn that ran it.
|
||||
func (e *AgentEngine) SetContextCheckpointSink(sink types.ContextCheckpointSink) {
|
||||
e.checkpointSink = sink
|
||||
}
|
||||
|
||||
// saveContextCheckpoint writes a compaction that ends on a stored turn onto
|
||||
// that turn. Best-effort: a failed write costs the next turn one more
|
||||
// summarization, never this turn anything.
|
||||
func (e *AgentEngine) saveContextCheckpoint(ctx context.Context, cp *compaction.Checkpoint, round int) {
|
||||
if cp == nil || e.checkpointSink == nil {
|
||||
return
|
||||
}
|
||||
err := e.checkpointSink.SaveContextCheckpoint(ctx, cp.TurnID, &types.ContextCheckpoint{
|
||||
Summary: cp.Summary,
|
||||
CreatedAt: time.Now(),
|
||||
Degraded: cp.Degraded,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Warnf(ctx, "[Agent][Round-%d] Failed to save context checkpoint on turn %s: %v",
|
||||
round, cp.TurnID, err)
|
||||
return
|
||||
}
|
||||
if cp.Degraded {
|
||||
logger.Warnf(ctx, "[Agent][Round-%d] Saved a degraded context checkpoint through turn %s "+
|
||||
"(raw archive, %d chars): the summarizer failed; the next compaction refines it",
|
||||
round, cp.TurnID, len(cp.Summary))
|
||||
return
|
||||
}
|
||||
logger.Infof(ctx, "[Agent][Round-%d] Saved context checkpoint through turn %s (%d chars)",
|
||||
round, cp.TurnID, len(cp.Summary))
|
||||
}
|
||||
Reference in new issue
Block a user