Repository navigation
Expand file tree
/
Copy pathcontext_commit.go
More file actions
50 lines (46 loc) · 1.62 KB
/
Copy pathcontext_commit.go
File metadata and controls
50 lines (46 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package agentgo
// Context preparation failures are not provider failures, even if a host wraps
// a retryable error. Retrying cannot repair a rejected durable state transition.
type contextPreparationError struct{ cause error }
func (e *contextPreparationError) Error() string { return "prepare context: " + e.cause.Error() }
func (e *contextPreparationError) Unwrap() error { return e.cause }
func stageArtifacts(source *memoryArtifactManager) *memoryArtifactManager {
staged := newArtifactManager()
if source != nil {
for _, artifact := range source.ListArtifacts() {
staged.artifacts[artifact.ID()] = artifact
}
}
return staged
}
func acceptContext(agentCtx *AgentContext, config LoopConfig, result ContextCommitResult, staged *memoryArtifactManager, execution Execution, sink eventSink) error {
if !result.Changed && !staged.changed {
return nil
}
if !result.Changed {
result.Messages = copyMessages(agentCtx.Messages)
}
result.Changed = true
result.Artifacts = staged.ListArtifacts()
if result.Compaction != nil {
info := *result.Compaction
info.Committed = false
result.Compaction = &info
}
if config.CommitContext != nil {
if err := config.CommitContext(result); err != nil {
return &contextPreparationError{cause: err}
}
}
agentCtx.Messages = copyMessages(result.Messages)
if config.artifacts != nil {
config.artifacts.replace(staged.artifacts)
}
config.ContextManager.Sync(agentCtx.Messages)
if result.Compaction != nil {
info := *result.Compaction
info.Committed = true
sink.emit(Event{Type: EventContextCompacted, Execution: executionRef(execution), Compaction: &info})
}
return nil
}