feat(team): share leader memory with team members (read-only)

Team members dispatched via team tasks can now read the leader's memory
files (MEMORY.md, memory/*.md) as a fallback when they have no own
memory. Memory writes are blocked for members — only the leader can
save memory files. This follows the existing team_workspace context
propagation pattern: dispatch metadata → RunRequest → context → tools.

Affected tools: read_file (interceptor), memory_get, memory_search,
list_files (interceptor). All include leader fallback with per-user →
global scope cascade.
This commit is contained in:
viettranx committed 2026-03-27 22:45:40 +07:00
1 parent e9342533e0
commit ee9f5b8aaf
10 files changed
+523 -7

No files matched your search

+21
View File
@@ -356,6 +356,27 @@ func TeamTaskIDFromCtx(ctx context.Context) string {
return ""
}
// --- Leader agent ID propagation (team task dispatch → memory interceptor) ---
const ctxLeaderAgentID toolContextKey = "tool_leader_agent_id"
// WithLeaderAgentID injects the team leader's agent UUID string into context
// so the memory interceptor can fallback-read leader's memory for team members.
func WithLeaderAgentID(ctx context.Context, id string) context.Context {
return context.WithValue(ctx, ctxLeaderAgentID, id)
}
// LeaderAgentIDFromCtx returns the leader's agent UUID string from context.
func LeaderAgentIDFromCtx(ctx context.Context) string {
if v, _ := ctx.Value(ctxLeaderAgentID).(string); v != "" {
return v
}
if rc := store.RunContextFromCtx(ctx); rc != nil {
return rc.LeaderAgentID
}
return ""
}
// --- Workspace scope propagation (delegation origin) ---
const (