-
Notifications
You must be signed in to change notification settings - Fork 49
feat: add experiment-gated self-improving learning, bounded memory, and background curation #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
64cad76
Merge pull request #1 from Zoo-Code-Org/main
iskandarsulaili a40bdc1
feat: implement Self-Improving Manager for adaptive learning
iskandarsulaili 9805793
feat: Enhance SelfImprovingManager with MemoryStore and SkillUsageSto…
iskandarsulaili c6d0b55
feat: Implement ReviewPromptFactory and TranscriptRecall for self-imp…
iskandarsulaili 445e9ed
feat: Enhance self-improvement system with user message tracking and …
iskandarsulaili 0ff067a
Merge branch 'main' into selfimproving
iskandarsulaili File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // npx vitest run src/__tests__/learning-memory.test.ts | ||
|
|
||
| import { | ||
| DEFAULT_LEARNING_CONFIG, | ||
| EMPTY_LEARNING_STATE, | ||
| learningConfigSchema, | ||
| learningStateSchema, | ||
| memoryContextSchema, | ||
| type LearningState, | ||
| type MemoryContext, | ||
| } from "../index.js" | ||
|
|
||
| describe("learning types", () => { | ||
| it("exports the default learning config", () => { | ||
| expect(DEFAULT_LEARNING_CONFIG).toMatchObject({ | ||
| enabled: false, | ||
| reviewOnTurnCount: 10, | ||
| reviewOnToolIterationCount: 50, | ||
| }) | ||
| }) | ||
|
|
||
| it("parses the empty learning state", () => { | ||
| const result = learningStateSchema.safeParse(EMPTY_LEARNING_STATE) | ||
|
|
||
| expect(result.success).toBe(true) | ||
| expect(result.data).toEqual(EMPTY_LEARNING_STATE) | ||
| }) | ||
|
|
||
| it("applies learning config defaults", () => { | ||
| const result = learningConfigSchema.parse({}) | ||
|
|
||
| expect(result).toEqual(DEFAULT_LEARNING_CONFIG) | ||
| }) | ||
|
|
||
| it("preserves TypeScript inference for learning state", () => { | ||
| const state: LearningState = EMPTY_LEARNING_STATE | ||
|
|
||
| expect(state.version).toBe(1) | ||
| }) | ||
| }) | ||
|
|
||
| describe("memory types", () => { | ||
| it("parses a valid memory context", () => { | ||
| const input: MemoryContext = { | ||
| entries: [], | ||
| revision: 0, | ||
| generatedAt: Date.now(), | ||
| } | ||
|
|
||
| const result = memoryContextSchema.safeParse(input) | ||
|
|
||
| expect(result.success).toBe(true) | ||
| expect(result.data).toEqual(input) | ||
| }) | ||
|
|
||
| it("rejects more than ten memory entries", () => { | ||
| const result = memoryContextSchema.safeParse({ | ||
| entries: Array.from({ length: 11 }, (_, index) => ({ | ||
| id: `entry-${index}`, | ||
| content: "memory", | ||
| source: "learning", | ||
| createdAt: index, | ||
| updatedAt: index, | ||
| })), | ||
| revision: 0, | ||
| generatedAt: Date.now(), | ||
| }) | ||
|
|
||
| expect(result.success).toBe(false) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| import { z } from "zod" | ||
|
|
||
| /** | ||
| * FeedbackSignal - types of learning observations | ||
| */ | ||
| export const feedbackSignalSchema = z.enum([ | ||
| "USER_CORRECTION", | ||
| "TASK_SUCCESS", | ||
| "TASK_FAILURE", | ||
| "PATTERN_REPEAT", | ||
| "CODE_INDEX_HIT", | ||
| "PROMPT_QUALITY", | ||
| ]) | ||
|
|
||
| export type FeedbackSignal = z.infer<typeof feedbackSignalSchema> | ||
|
|
||
| /** | ||
| * LearningConfig - configuration for the learning system | ||
| */ | ||
| export const learningConfigSchema = z.object({ | ||
| enabled: z.boolean().default(false), | ||
| reviewOnTurnCount: z.number().int().min(1).default(10), | ||
| reviewOnToolIterationCount: z.number().int().min(1).default(50), | ||
| maxStoredPatterns: z.number().int().min(1).default(100), | ||
| maxStoredEvents: z.number().int().min(1).default(500), | ||
| maxPromptPatterns: z.number().int().min(1).default(5), | ||
| curatorEnabled: z.boolean().default(true), | ||
| curatorIntervalMs: z.number().int().min(60000).default(3600000), | ||
| staleAfterDays: z.number().int().min(1).default(14), | ||
| archiveAfterDays: z.number().int().min(1).default(60), | ||
| codeIndexCorrelationEnabled: z.boolean().default(true), | ||
| }) | ||
|
|
||
| export type LearningConfig = z.infer<typeof learningConfigSchema> | ||
|
|
||
| export const DEFAULT_LEARNING_CONFIG: LearningConfig = { | ||
| enabled: false, | ||
| reviewOnTurnCount: 10, | ||
| reviewOnToolIterationCount: 50, | ||
| maxStoredPatterns: 100, | ||
| maxStoredEvents: 500, | ||
| maxPromptPatterns: 5, | ||
| curatorEnabled: true, | ||
| curatorIntervalMs: 3600000, | ||
| staleAfterDays: 14, | ||
| archiveAfterDays: 60, | ||
| codeIndexCorrelationEnabled: true, | ||
| } | ||
|
|
||
| /** | ||
| * LearningEvent - a single learning observation | ||
| */ | ||
| export const learningEventSchema = z.object({ | ||
| id: z.string(), | ||
| signal: feedbackSignalSchema, | ||
| timestamp: z.number(), | ||
| taskId: z.string().optional(), | ||
| workspacePath: z.string().optional(), | ||
| mode: z.string().optional(), | ||
| context: z.object({ | ||
| userTurnCount: z.number().optional(), | ||
| toolIterationCount: z.number().optional(), | ||
| toolNames: z.array(z.string()).optional(), | ||
| promptFingerprint: z.string().optional(), | ||
| errorKey: z.string().optional(), | ||
| codeIndex: z | ||
| .object({ | ||
| available: z.boolean(), | ||
| hits: z.number(), | ||
| topScore: z.number().optional(), | ||
| }) | ||
| .optional(), | ||
| }), | ||
| outcome: z.object({ | ||
| success: z.boolean().optional(), | ||
| corrected: z.boolean().optional(), | ||
| summary: z.string().optional(), | ||
| confidenceDelta: z.number().optional(), | ||
| }), | ||
| }) | ||
|
|
||
| export type LearningEvent = z.infer<typeof learningEventSchema> | ||
|
|
||
| /** | ||
| * PatternState - lifecycle state for learned patterns | ||
| */ | ||
| export const patternStateSchema = z.enum(["active", "stale", "archived"]) | ||
|
|
||
| export type PatternState = z.infer<typeof patternStateSchema> | ||
|
|
||
| /** | ||
| * PatternType - category of learned pattern | ||
| */ | ||
| export const patternTypeSchema = z.enum(["prompt", "tool", "error", "skill", "code-index"]) | ||
|
|
||
| export type PatternType = z.infer<typeof patternTypeSchema> | ||
|
|
||
| /** | ||
| * LearnedPattern - a pattern extracted from learning events | ||
| */ | ||
| export const learnedPatternSchema = z.object({ | ||
| id: z.string(), | ||
| patternType: patternTypeSchema, | ||
| state: patternStateSchema, | ||
| summary: z.string(), | ||
| confidenceScore: z.number().min(0).max(1), | ||
| frequency: z.number().int().min(0), | ||
| successRate: z.number().min(0).max(1), | ||
| firstSeenAt: z.number(), | ||
| lastSeenAt: z.number(), | ||
| lastAppliedAt: z.number().optional(), | ||
| sourceSignals: z.array(feedbackSignalSchema), | ||
| context: z.object({ | ||
| toolNames: z.array(z.string()).optional(), | ||
| errorKeys: z.array(z.string()).optional(), | ||
| modes: z.array(z.string()).optional(), | ||
| workspacePaths: z.array(z.string()).optional(), | ||
| }), | ||
| }) | ||
|
|
||
| export type LearnedPattern = z.infer<typeof learnedPatternSchema> | ||
|
|
||
| /** | ||
| * ActionType - types of improvement actions | ||
| */ | ||
| export const actionTypeSchema = z.enum(["PROMPT_ENRICHMENT", "TOOL_PREFERENCE", "ERROR_AVOIDANCE", "SKILL_SUGGESTION"]) | ||
|
|
||
| export type ActionType = z.infer<typeof actionTypeSchema> | ||
|
|
||
| /** | ||
| * ImprovementAction - an action to apply based on learned patterns | ||
| */ | ||
| export const improvementActionSchema = z.object({ | ||
| id: z.string(), | ||
| actionType: actionTypeSchema, | ||
| target: z.enum(["system-prompt", "task-execution", "skills-manager", "review-queue"]), | ||
| payload: z.record(z.string(), z.unknown()), | ||
| timestamp: z.number(), | ||
| }) | ||
|
|
||
| export type ImprovementAction = z.infer<typeof improvementActionSchema> | ||
|
|
||
| /** | ||
| * LearningTelemetry - telemetry counters for the learning system | ||
| */ | ||
| export const learningTelemetrySchema = z.object({ | ||
| promptEnrichmentUses: z.number().int().default(0), | ||
| toolPreferenceUses: z.number().int().default(0), | ||
| errorAvoidanceUses: z.number().int().default(0), | ||
| skillSuggestionCount: z.number().int().default(0), | ||
| lastReviewAt: z.number().optional(), | ||
| lastCuratorRunAt: z.number().optional(), | ||
| }) | ||
|
|
||
| export type LearningTelemetry = z.infer<typeof learningTelemetrySchema> | ||
|
|
||
| /** | ||
| * LearningState - full serializable state of the learning system | ||
| */ | ||
| export const learningStateSchema = z.object({ | ||
| version: z.literal(1), | ||
| config: learningConfigSchema, | ||
| counters: z.object({ | ||
| userTurnsSinceReview: z.number().int().default(0), | ||
| toolIterationsSinceReview: z.number().int().default(0), | ||
| }), | ||
| patterns: z.array(learnedPatternSchema).default([]), | ||
| archivedPatterns: z.array(learnedPatternSchema).default([]), | ||
| recentEvents: z.array(learningEventSchema).default([]), | ||
| pendingActions: z.array(improvementActionSchema).default([]), | ||
| telemetry: learningTelemetrySchema, | ||
| }) | ||
|
|
||
| export type LearningState = z.infer<typeof learningStateSchema> | ||
|
|
||
| export const EMPTY_LEARNING_STATE: LearningState = { | ||
| version: 1, | ||
| config: DEFAULT_LEARNING_CONFIG, | ||
| counters: { | ||
| userTurnsSinceReview: 0, | ||
| toolIterationsSinceReview: 0, | ||
| }, | ||
| patterns: [], | ||
| archivedPatterns: [], | ||
| recentEvents: [], | ||
| pendingActions: [], | ||
| telemetry: { | ||
| promptEnrichmentUses: 0, | ||
| toolPreferenceUses: 0, | ||
| errorAvoidanceUses: 0, | ||
| skillSuggestionCount: 0, | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { z } from "zod" | ||
|
|
||
| /** | ||
| * MemoryEntry - a single durable memory entry for prompt-facing context | ||
| * Adapted from Hermes' bounded memory store concept. | ||
| */ | ||
| export const memoryEntrySchema = z.object({ | ||
| id: z.string(), | ||
| content: z.string().max(2000), | ||
| source: z.enum(["learning", "user", "system", "review"]), | ||
| createdAt: z.number(), | ||
| updatedAt: z.number(), | ||
| relevanceScore: z.number().min(0).max(1).optional(), | ||
| tags: z.array(z.string()).optional(), | ||
| expiresAt: z.number().optional(), | ||
| }) | ||
|
|
||
| export type MemoryEntry = z.infer<typeof memoryEntrySchema> | ||
|
|
||
| /** | ||
| * MemoryContext - bounded set of memory entries for prompt injection | ||
| */ | ||
| export const memoryContextSchema = z.object({ | ||
| entries: z.array(memoryEntrySchema).max(10), | ||
| revision: z.number().int().default(0), | ||
| generatedAt: z.number(), | ||
| }) | ||
|
|
||
| export type MemoryContext = z.infer<typeof memoryContextSchema> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 85
🏁 Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 106
🏁 Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 1466
Remove the duplicate
marketplacere-exportpackages/types/src/index.tsre-exports./marketplace.jstwice (lines 18 and 28), which is redundant.♻️ Proposed fix
export * from "./learning.js" export * from "./marketplace.js" export * from "./mcp.js" export * from "./message.js" export * from "./memory.js" @@ export * from "./skills.js" -export * from "./marketplace.js" export * from "./telemetry.js"🤖 Prompt for AI Agents