@pga-ai/core
v0.4.0
Published
PGA Core - Genomic Self-Evolving Prompts with Gene Bank, THK, Layered Memory, RAG, and Advanced Reasoning
Maintainers
Readme
@pga-ai/core
🧬 Genomic Self-Evolving Prompts — Core Engine
Created by Luis Alfredo Velasquez Duran | Germany, 2025
What is @pga-ai/core?
The core engine for PGA (Genomic Self-Evolving Prompts) — the world's first system that makes AI prompts evolve automatically like biological organisms.
Instead of manually tweaking prompts, PGA:
- ✅ Learns from every interaction
- ✅ Adapts to each user uniquely
- ✅ Improves continuously (autonomous)
- ✅ Never degrades (immune system)
- ✅ Tests changes before deployment (sandbox)
Installation
npm install @pga-ai/coreYou'll also need adapters for your LLM and database:
npm install @pga-ai/adapters-llm @pga-ai/adapters-storageQuick Start
import { PGA } from '@pga-ai/core';
import { ClaudeAdapter } from '@pga-ai/adapters-llm/anthropic';
import { PostgresAdapter } from '@pga-ai/adapters-storage/postgres';
// 1. Initialize PGA
const pga = new PGA({
llm: new ClaudeAdapter({
apiKey: process.env.ANTHROPIC_KEY,
}),
storage: new PostgresAdapter({
connectionString: process.env.DATABASE_URL,
}),
});
await pga.initialize();
// 2. Create genome
const genome = await pga.createGenome({
name: 'my-assistant',
});
// 3. Use in your agent loop
async function chat(userId: string, message: string) {
const response = await genome.chat(message, { userId });
return response;
}
// 4. PGA learns automatically from interactions
await genome.recordInteraction({
userId: 'user123',
userMessage: 'Hello!',
assistantResponse: 'Hi there!',
toolCalls: [],
score: 0.9,
timestamp: new Date(),
});That's it! Your agent now evolves automatically.
Core Concepts
Three-Layer Architecture
┌─────────────────────────────────────────┐
│ Layer 0: Immutable DNA │
│ Security, Ethics, Core Identity │
│ 🚫 NEVER mutates │
├─────────────────────────────────────────┤
│ Layer 1: Operative Genes │
│ Tool Usage, Coding Patterns │
│ 🐢 SLOW mutation (high validation) │
├─────────────────────────────────────────┤
│ Layer 2: Epigenomes │
│ User Preferences, Communication Style │
│ ⚡ FAST mutation (daily adaptation) │
└─────────────────────────────────────────┘User DNA Profiling
Each user gets a unique cognitive profile:
const dna = await genome.getDNA('user123');
console.log(dna.traits);
// {
// communicationStyle: 'technical',
// verbosity: 'terse',
// preferredTools: ['browser', 'code'],
// domainExpertise: { 'coding': 0.9 }
// }Automatic Evolution
PGA evolves through a 4-phase cycle:
- Transcription: Log every interaction
- Variation: Generate mutations
- Simulation: Test in sandbox
- Selection: Deploy only improvements
API Reference
PGA Class
new PGA(config)
Create PGA instance.
const pga = new PGA({
llm: new ClaudeAdapter({ apiKey: '...' }),
storage: new PostgresAdapter({ connectionString: '...' }),
config: {
enableSandbox: true, // Test mutations before deploy
mutationRate: 'balanced', // 'slow' | 'balanced' | 'aggressive'
},
});pga.initialize()
Initialize storage (create tables, etc.).
await pga.initialize();pga.createGenome(options)
Create new genome.
const genome = await pga.createGenome({
name: 'my-assistant',
config: {
enableSandbox: true,
mutationRate: 'balanced',
},
});GenomeInstance Class
genome.assemblePrompt(context)
Get optimized prompt for current context.
const prompt = await genome.assemblePrompt({
userId: 'user123',
taskType: 'coding',
});genome.chat(message, context)
Chat with PGA optimization.
const response = await genome.chat('Hello!', {
userId: 'user123',
});genome.recordInteraction(interaction)
Record interaction (enables learning).
await genome.recordInteraction({
userId: 'user123',
userMessage: 'Fix this bug',
assistantResponse: 'Bug fixed!',
toolCalls: [],
score: 0.95,
timestamp: new Date(),
});genome.getDNA(userId)
Get user's DNA profile.
const dna = await genome.getDNA('user123');genome.recordFeedback(userId, gene, sentiment)
Record user feedback.
await genome.recordFeedback('user123', 'communication-style', 'positive');Adapters
LLM Adapters
Implement LLMAdapter interface:
import type { LLMAdapter } from '@pga-ai/core';
export class MyLLMAdapter implements LLMAdapter {
readonly name = 'my-llm';
readonly model = 'my-model-v1';
async chat(messages, options) {
// Your implementation
}
}Available adapters:
@pga-ai/adapters-llm/anthropic- Claude@pga-ai/adapters-llm/openai- GPT@pga-ai/adapters-llm/google- Gemini@pga-ai/adapters-llm/local- Ollama
Storage Adapters
Implement StorageAdapter interface:
import type { StorageAdapter } from '@pga-ai/core';
export class MyStorageAdapter implements StorageAdapter {
async initialize() { /* ... */ }
async saveGenome(genome) { /* ... */ }
async loadGenome(id) { /* ... */ }
// ... other methods
}Available adapters:
@pga-ai/adapters-storage/postgres@pga-ai/adapters-storage/mongodb@pga-ai/adapters-storage/redis@pga-ai/adapters-storage/sqlite
Examples
See /examples directory for:
- Basic usage
- LangChain integration
- Custom agents
- Next.js app
License
MIT © Luis Alfredo Velasquez Duran
Created with 🧬 by Luis Alfredo Velasquez Duran
