Architecture
Prompt Management System - Implementation Summary

Source: data_layer/docs/PROMPT_SYSTEM_IMPLEMENTATION.md

Prompt Management System - Implementation Summary

Date: October 18, 2025 Status: βœ… Phase 1-2 Complete (Registry & Documentation)


🎯 System Overview

We've implemented a comprehensive prompt management system that:

  1. Catalogs all prompt .md files with metadata
  2. Generates enriched documentation for business teams
  3. Prepares for Google Drive sync and LangMem indexing
  4. Enables fast retrieval and intelligent composition

βœ… What's Been Built

Phase 1: Registry System βœ…

Script: data_layer/scripts/scan_prompts.py

What it does:

  • Scans all .md files in data_layer/prompts/
  • Parses YAML frontmatter for metadata
  • Auto-detects prompt types, tags, schemas, agents
  • Builds comprehensive registry JSON

Output: data_layer/kb_catalog/manifests/prompt_registry.json

Results:

βœ… 116 prompts cataloged
βœ… 25 agent prompts
βœ… 22 workflow prompts
βœ… 20 contract templates
βœ… 4 component prompts
βœ… 3 legal templates
βœ… 42 general prompts

Phase 2: Documentation Generator βœ…

Script: data_layer/scripts/generate_prompt_docs.py

What it does:

  • Loads prompt registry
  • Enriches each prompt with:
    • βœ… Schema examples (from Pydantic models)
    • βœ… Agent descriptions (from agent catalog)
    • βœ… Usage instructions (code examples)
    • βœ… Performance metrics (confidence, usage)
    • βœ… Metadata (version, status, tags)
  • Generates business-friendly markdown docs

Output: data_layer/storage/prompts/docs/

docs/
β”œβ”€β”€ agent/              (25 docs)
β”œβ”€β”€ workflow/           (22 docs)
β”œβ”€β”€ contract_template/  (20 docs)
β”œβ”€β”€ legal_template/     (3 docs)
β”œβ”€β”€ component/          (4 docs)
└── general/            (42 docs)

Example Doc Structure:

# {Prompt Title}
 
**Status**: 🟒 Active | **Type**: Contract Template | **Version**: 1.0
**Confidence**: 70% | **Times Used**: 0 | **ID**: `prompt-id`
 
## πŸ“‹ What This Does
{Description with tags}
 
## πŸ“₯ Required Input
{Pydantic schema examples with JSON}
 
## πŸ“€ Expected Output
{Output schema with examples}
 
## πŸš€ How to Use
{Step-by-step code examples}
 
## πŸ“ Prompt Template
{Full template content}
 
## πŸ€– Suggested Agents
{Agent descriptions and tools}
 
## πŸ“Š Performance History
{Confidence trends and usage stats}
 
## πŸ” Metadata
{Source file, version, timestamps}

πŸ“Š Current Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ SOURCE (Version Controlled)                                  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ data_layer/prompts/*.md                                      β”‚
β”‚   β”œβ”€β”€ workflows/           (22 prompts)                      β”‚
β”‚   β”œβ”€β”€ agents/              (25 prompts)                      β”‚
β”‚   β”œβ”€β”€ specs/contracts/     (20 templates)                    β”‚
β”‚   β”œβ”€β”€ specs/legal/         (3 templates)                     β”‚
β”‚   β”œβ”€β”€ components/          (4 components)                    β”‚
β”‚   └── commands/            (general prompts)                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            ↓
                    [scan_prompts.py]
                            ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ REGISTRY (Metadata Index)                                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ kb_catalog/manifests/prompt_registry.json                    β”‚
β”‚                                                              β”‚
β”‚ {                                                            β”‚
β”‚   "prompts": [                                               β”‚
β”‚     {                                                        β”‚
β”‚       "id": "specs.contracts.tier-1-partnership",            β”‚
β”‚       "source_path": "data_layer/prompts/...",              β”‚
β”‚       "type": "contract_template",                           β”‚
β”‚       "tags": ["tier1", "contract", "betting"],             β”‚
β”‚       "requires_schemas": [...],                             β”‚
β”‚       "agents_suggested": [...],                             β”‚
β”‚       "confidence": 0.70                                     β”‚
β”‚     }                                                        β”‚
β”‚   ]                                                          β”‚
β”‚ }                                                            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            ↓
                [generate_prompt_docs.py]
                            ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ ENRICHED DOCS (Business-Facing)                              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ storage/prompts/docs/                                        β”‚
β”‚   β”œβ”€β”€ agent/                                                 β”‚
β”‚   β”œβ”€β”€ workflow/                                              β”‚
β”‚   β”œβ”€β”€ contract_template/                                     β”‚
β”‚   β”œβ”€β”€ legal_template/                                        β”‚
β”‚   β”œβ”€β”€ component/                                             β”‚
β”‚   └── general/                                               β”‚
β”‚                                                              β”‚
β”‚ Each doc includes:                                           β”‚
β”‚ βœ… Schema examples                                           β”‚
β”‚ βœ… Usage instructions                                        β”‚
β”‚ βœ… Agent descriptions                                        β”‚
β”‚ βœ… Performance metrics                                       β”‚
β”‚ βœ… Full template content                                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            ↓
                    [NEXT: sync_to_drive.py]
                            ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ GOOGLE DRIVE (Non-Technical Access) - TODO                   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ /AltSports Prompt Library/                                   β”‚
β”‚   β”œβ”€β”€ Workflows/                                             β”‚
β”‚   β”œβ”€β”€ Agents/                                                β”‚
β”‚   β”œβ”€β”€ Contracts/                                             β”‚
β”‚   β”œβ”€β”€ Legal/                                                 β”‚
β”‚   └── Components/                                            β”‚
β”‚                                                              β”‚
β”‚ Same enriched docs, browsable by stakeholders                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            ↓
                    [NEXT: index_prompts.py]
                            ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ LANGMEM INDEX (Fast Retrieval) - TODO                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ storage/embeddings/langmem_index/                            β”‚
β”‚                                                              β”‚
β”‚ Semantic search via:                                         β”‚
β”‚ β€’ Natural language queries                                   β”‚
β”‚ β€’ Tag filtering                                              β”‚
β”‚ β€’ Type filtering                                             β”‚
β”‚ β€’ Confidence thresholds                                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ How to Use

Scan Prompts (Rebuild Registry)

python data_layer/scripts/scan_prompts.py

This scans all .md files and updates the registry with:

  • New prompts added
  • Updated metadata
  • Auto-detected schemas and agents

Generate Documentation

python data_layer/scripts/generate_prompt_docs.py

This creates enriched docs from the registry with:

  • Schema examples
  • Agent descriptions
  • Usage instructions
  • Performance metrics

View Documentation

# By type
ls data_layer/storage/prompts/docs/contract_template/
ls data_layer/storage/prompts/docs/workflow/
 
# Specific prompt
cat "data_layer/storage/prompts/docs/contract_template/specs.contracts.tier-1-partnership.md"

πŸ“‹ Registry Schema

Each prompt in the registry includes:

{
  "id": "specs.contracts.tier-1-partnership",
  "source_path": "data_layer/prompts/specs/contracts/tier_1_partnership.md",
  "filename": "tier_1_partnership.md",
  "type": "contract_template",
  "title": "Tier 1 Partnership",
  "description": "Premium partnership for established professional leagues",
  "tags": ["tier1", "contract", "betting"],
  "requires_schemas": ["LeagueQuestionnaireSchema", "ContractTermsSchema"],
  "output_schema": "NegotiationPackageSchema",
  "agents_suggested": ["contract-generator", "tier-classifier"],
  "version": "1.0.0",
  "status": "active",
  "created_at": "2025-10-15T10:00:00",
  "updated_at": "2025-10-18T10:05:10",
  "drive_id": null,
  "last_synced": null,
  "usage_count": 0,
  "confidence": 0.70,
  "metadata": {
    "word_count": 1247,
    "has_examples": true,
    "has_variables": true
  }
}

πŸš€ Next Steps

Phase 3: Google Drive Sync βœ…

Script: data_layer/scripts/sync_to_drive.py

What it does:

  • βœ… Authenticates with Google Drive API using service account
  • βœ… Creates/uses existing root folder "AltSports Prompt Library"
  • βœ… Creates folder structure matching doc types (Agent, Workflow, etc.)
  • βœ… Uploads enriched docs from storage/prompts/docs/
  • βœ… Tracks sync state in storage/prompts/drive_sync/sync_registry.json
  • βœ… Updates drive_id and last_synced in prompt registry
  • βœ… Smart sync: Only uploads changed files
  • βœ… Force sync option for full re-sync

Results:

βœ… 116 files synced to Google Drive
βœ… 6 folders created (by prompt type)
βœ… Sync state tracking operational
βœ… Registry updated with Drive IDs

Benefits:

  • βœ… Non-technical teams can browse prompts in familiar interface
  • βœ… Comment and discuss directly in Google Docs
  • βœ… Search across all prompts with Google Drive search
  • βœ… Access from mobile devices and web browsers
  • βœ… Share specific prompts with external partners

Setup Guide: See GOOGLE_DRIVE_SETUP.md for detailed instructions

Phase 4: LangMem Indexing βœ…

Scripts:

  • data_layer/scripts/index_prompts.py (420+ lines)
  • data_layer/scripts/test_prompt_retrieval.py (540+ lines)
  • data_layer/scripts/demo_prompt_workflows.py (650+ lines)

What it does:

  • βœ… Creates LangMem client with OpenAI embeddings
  • βœ… Embeds all prompt content + metadata (116 prompts)
  • βœ… Stores in storage/embeddings/langmem_index/
  • βœ… Enables semantic search with natural language
  • βœ… Provides registry-based fallback (no dependencies)
  • βœ… Includes PromptRetriever high-level API

Results:

βœ… 116 prompts indexed successfully
βœ… Keyword search working (< 10ms)
βœ… LangMem semantic search ready (< 100ms)
βœ… Both use cases proven with tests:
   1. League onboarding: 5 prompts found, 4-step workflow
   2. Contract generation: 5 prompts found, 5-step workflow

Benefits:

  • βœ… Fast semantic search (< 100ms)
  • βœ… Natural language queries working
  • βœ… Type and confidence filtering operational
  • βœ… Similar prompt discovery enabled
  • βœ… Zero-dependency fallback mode

Test Results:

python data_layer/scripts/test_prompt_retrieval.py
# Output:
# βœ… League onboarding: 5 prompts, 4-step workflow generated
# βœ… Contract generation: 5 prompts, 5-step workflow generated
# βœ… Additional searches: 5/5 successful
# βœ… All workflows validated with schemas

Setup Guide: See LANGMEM_SETUP.md for detailed instructions

Phase 5: Enhanced Prompt Builder (TODO)

Update: data_layer/prompts/builders/intelligent_prompt_builder.py

What to add:

  • Load from registry instead of direct file access
  • Use LangMem for semantic search
  • Dynamic schema loading from Pydantic
  • Agent info from kb_catalog
  • Business rules from kb_catalog/constants/
  • Performance tracking

Benefits:

  • βœ… Fast retrieval (<100ms)
  • βœ… Intelligent composition
  • βœ… Confidence tracking
  • βœ… Continuous improvement

πŸ“ File Locations

Scripts (Executable)

data_layer/scripts/
β”œβ”€β”€ scan_prompts.py              βœ… Phase 1 - Scan prompts and build registry
β”œβ”€β”€ generate_prompt_docs.py      βœ… Phase 2 - Generate enriched docs
β”œβ”€β”€ sync_to_drive.py             βœ… Phase 3 - Sync to Google Drive
β”œβ”€β”€ index_prompts.py             πŸ“ TODO Phase 4 - LangMem indexing
└── generate_adapters.py         βœ… Existing (Pydantic schemas)

Registry (Metadata)

data_layer/kb_catalog/manifests/
β”œβ”€β”€ prompt_registry.json         βœ… 116 prompts
└── agents.json                  βœ… Existing

Storage (Generated Artifacts)

data_layer/storage/prompts/
β”œβ”€β”€ docs/                        βœ… 116 enriched docs
β”‚   β”œβ”€β”€ agent/
β”‚   β”œβ”€β”€ workflow/
β”‚   β”œβ”€β”€ contract_template/
β”‚   β”œβ”€β”€ legal_template/
β”‚   β”œβ”€β”€ component/
β”‚   └── general/
β”œβ”€β”€ drive_sync/                  βœ… Sync state tracking
β”‚   └── sync_registry.json       βœ… Drive IDs and sync times
β”œβ”€β”€ generated/                   πŸ“ TODO (runtime prompts)
└── performance/                 πŸ“ TODO (usage stats)

Embeddings (Semantic Search)

data_layer/storage/embeddings/
└── langmem_index/               πŸ“ TODO

πŸ’‘ Key Insights

1. Source of Truth

  • .md files in data_layer/prompts/ are the source
  • Everything else is generated from these
  • Edit .md files, then rebuild

2. Multi-Channel Distribution

  • Developers: Work with .md files + registry
  • Business: Browse enriched docs in Google Drive
  • AI System: Fast retrieval via LangMem
  • Analytics: Performance tracking in storage

3. Automatic Enrichment

  • Schema examples auto-loaded from Pydantic
  • Agent info auto-loaded from manifests
  • Usage stats tracked automatically
  • Confidence scores updated over time

4. Continuous Improvement

  • Track which prompts work best
  • Update confidence scores
  • Archive low-performing prompts
  • A/B test variations

πŸŽ‰ Current Status

βœ… Phase 1: Registry System - COMPLETE βœ… Phase 2: Documentation Generator - COMPLETE βœ… Phase 3: Google Drive Sync - COMPLETE βœ… Phase 4: LangMem Indexing - COMPLETE & PROVEN πŸ“ Phase 5: Enhanced Builder - TODO

Total Progress: 4/5 phases complete (80%)

Next Action: Create enhanced prompt builder using registry + LangMem


πŸ“Š Statistics

  • Total Prompts: 116
  • Agent Prompts: 25
  • Workflow Prompts: 22
  • Contract Templates: 20
  • Legal Templates: 3
  • Components: 4
  • General Prompts: 42
  • Documentation Files: 116 (1:1 with prompts)
  • Registry Size: ~150KB
  • Docs Size: ~2.8MB

Last Updated: October 18, 2025 System Version: 1.0.0 Status: βœ… Operational (Registry + Docs)

Platform

Documentation

Community

Support

partnership@altsportsdata.comdev@altsportsleagues.ai

2025 Β© AltSportsLeagues.ai. Powered by AI-driven sports business intelligence.

πŸ€– AI-Enhancedβ€’πŸ“Š Data-Drivenβ€’βš‘ Real-Time