-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.go
More file actions
69 lines (58 loc) · 1.82 KB
/
Copy pathcontext.go
File metadata and controls
69 lines (58 loc) · 1.82 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package reference
import (
"fmt"
"strings"
)
// ContextFrame represents an engineered context payload for an agent step.
type ContextFrame struct {
SystemRules string `json:"system_rules"`
ActiveFile string `json:"active_file"`
WorkspaceState string `json:"workspace_state"`
KnowledgeItems []string `json:"knowledge_items"`
ToolHistory []string `json:"tool_history"`
MaxHistoryItems int `json:"max_history_items"`
}
// NewContextFrame creates a new ContextFrame with default limits.
func NewContextFrame(systemRules string) *ContextFrame {
return &ContextFrame{
SystemRules: systemRules,
MaxHistoryItems: 10,
}
}
// AddToolObservation appends a condensed tool observation to execution history.
func (c *ContextFrame) AddToolObservation(toolName, summary string) {
entry := fmt.Sprintf("[%s] %s", toolName, summary)
c.ToolHistory = append(c.ToolHistory, entry)
if len(c.ToolHistory) > c.MaxHistoryItems {
c.ToolHistory = c.ToolHistory[len(c.ToolHistory)-c.MaxHistoryItems:]
}
}
// AssemblePayload compiles all context elements into a clean, token-dense prompt payload.
func (c *ContextFrame) AssemblePayload() string {
var sb strings.Builder
sb.WriteString("=== SYSTEM RULES ===\n")
sb.WriteString(c.SystemRules)
sb.WriteString("\n\n")
if c.WorkspaceState != "" {
sb.WriteString("=== WORKSPACE STATE ===\n")
sb.WriteString(c.WorkspaceState)
sb.WriteString("\n\n")
}
if len(c.KnowledgeItems) > 0 {
sb.WriteString("=== KNOWLEDGE ITEMS ===\n")
for _, ki := range c.KnowledgeItems {
sb.WriteString("- ")
sb.WriteString(ki)
sb.WriteString("\n")
}
sb.WriteString("\n")
}
if len(c.ToolHistory) > 0 {
sb.WriteString("=== EXECUTION HISTORY (CONDENSED) ===\n")
for _, step := range c.ToolHistory {
sb.WriteString(step)
sb.WriteString("\n")
}
}
return sb.String()
}