Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
86 lines
3.5 KiB
Go
86 lines
3.5 KiB
Go
package workbench
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/Tencent/WeKnora/internal/types"
|
|
)
|
|
|
|
// Store generation inputs, never provider credentials or executable tool config.
|
|
type AgentSnapshot struct {
|
|
Name string `json:"name"`
|
|
ModelID string `json:"model_id"`
|
|
SystemPrompt string `json:"system_prompt"`
|
|
Instructions string `json:"instructions"`
|
|
SkillIDs []string `json:"skill_ids"`
|
|
KBSelectionMode string `json:"kb_selection_mode"`
|
|
KnowledgeBases []string `json:"knowledge_bases"`
|
|
Temperature float64 `json:"temperature"`
|
|
Thinking *bool `json:"thinking"`
|
|
MemoryEnabled *bool `json:"memory_enabled"`
|
|
OutputLimit int `json:"output_limit"`
|
|
ContextWindow int `json:"context_window"`
|
|
CapturedAt time.Time `json:"captured_at"`
|
|
Fusions []FusionSnapshot `json:"fusions,omitempty"`
|
|
FusionMemories []*types.MemoryItem `json:"fusion_memories,omitempty"`
|
|
}
|
|
|
|
type FusionSnapshot struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
SystemPrompt string `json:"system_prompt"`
|
|
Instructions string `json:"instructions"`
|
|
SkillIDs []string `json:"skill_ids"`
|
|
MemoryEnabled *bool `json:"memory_enabled"`
|
|
}
|
|
|
|
type agentSnapshotsKey struct{}
|
|
|
|
func snapshotFromContext(ctx context.Context, id string) (AgentSnapshot, bool) {
|
|
m, _ := ctx.Value(agentSnapshotsKey{}).(map[string]AgentSnapshot)
|
|
v, ok := m[id]
|
|
return v, ok
|
|
}
|
|
|
|
func applyAgentSnapshot(agent *types.CustomAgent, snapshot AgentSnapshot) *types.CustomAgent {
|
|
copy := *agent
|
|
copy.Name = snapshot.Name
|
|
copy.Config.ModelID = snapshot.ModelID
|
|
copy.Config.SystemPrompt = snapshot.SystemPrompt
|
|
copy.Config.InstructionSkillIDs = append([]string(nil), snapshot.SkillIDs...)
|
|
copy.Config.KBSelectionMode = snapshot.KBSelectionMode
|
|
copy.Config.KnowledgeBases = append([]string(nil), snapshot.KnowledgeBases...)
|
|
copy.Config.Temperature = snapshot.Temperature
|
|
copy.Config.Thinking = snapshot.Thinking
|
|
copy.Config.MemoryEnabled = snapshot.MemoryEnabled
|
|
// A saved generation configuration cannot undo a later privacy opt-out.
|
|
if agent.Config.MemoryEnabled != nil && !*agent.Config.MemoryEnabled {
|
|
copy.Config.MemoryEnabled = agent.Config.MemoryEnabled
|
|
}
|
|
copy.Config.MaxCompletionTokens = snapshot.OutputLimit
|
|
copy.Config.FusionAgentIDs = nil
|
|
for _, fusion := range snapshot.Fusions {
|
|
copy.Config.FusionAgentIDs = append(copy.Config.FusionAgentIDs, fusion.ID)
|
|
}
|
|
return ©
|
|
}
|
|
|
|
func rememberAgentSnapshot(ctx context.Context, agent *types.CustomAgent, instructions string, contextWindow, outputLimit int, fusions []FusionSnapshot, memories []*types.MemoryItem) {
|
|
m, ok := ctx.Value(agentSnapshotsKey{}).(map[string]AgentSnapshot)
|
|
if !ok {
|
|
return
|
|
}
|
|
if _, exists := m[agent.ID]; exists {
|
|
return
|
|
}
|
|
m[agent.ID] = AgentSnapshot{
|
|
Name: agent.Name, ModelID: agent.Config.ModelID, SystemPrompt: agent.Config.SystemPrompt,
|
|
Instructions: instructions, SkillIDs: append([]string(nil), agent.Config.InstructionSkillIDs...),
|
|
KBSelectionMode: agent.Config.KBSelectionMode, KnowledgeBases: append([]string(nil), agent.Config.KnowledgeBases...),
|
|
Temperature: agent.Config.Temperature, Thinking: agent.Config.Thinking, MemoryEnabled: agent.Config.MemoryEnabled,
|
|
OutputLimit: outputLimit, ContextWindow: contextWindow, CapturedAt: time.Now().UTC(),
|
|
Fusions: fusions, FusionMemories: memories,
|
|
}
|
|
}
|