Skip to main content
Glama
index.html58.1 kB
<!doctype html> <html lang="en" class="no-js"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="description" content="Memory persistence for AI assistants with temporal decay"> <meta name="author" content="prefrontal-systems"> <link rel="canonical" href="https://cortexgraph.dev/prompt_optimization_flow/"> <link rel="icon" href="../assets/images/favicon.png"> <meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.7.0"> <title>Prompt Optimization Flow - CortexGraph Documentation</title> <link rel="stylesheet" href="../assets/stylesheets/main.618322db.min.css"> <link rel="stylesheet" href="../assets/stylesheets/palette.ab4e12ef.min.css"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback"> <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style> <script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script> </head> <body dir="ltr" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo"> <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off"> <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off"> <label class="md-overlay" for="__drawer"></label> <div data-md-component="skip"> <a href="#prompt-optimization-flow" class="md-skip"> Skip to content </a> </div> <div data-md-component="announce"> </div> <header class="md-header" data-md-component="header"> <nav class="md-header__inner md-grid" aria-label="Header"> <a href=".." title="CortexGraph Documentation" class="md-header__button md-logo" aria-label="CortexGraph Documentation" data-md-component="logo"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg> </a> <label class="md-header__button md-icon" for="__drawer"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg> </label> <div class="md-header__title" data-md-component="header-title"> <div class="md-header__ellipsis"> <div class="md-header__topic"> <span class="md-ellipsis"> CortexGraph Documentation </span> </div> <div class="md-header__topic" data-md-component="header-topic"> <span class="md-ellipsis"> Prompt Optimization Flow </span> </div> </div> </div> <form class="md-header__option" data-md-component="palette"> <input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo" aria-label="Switch to dark mode" type="radio" name="__palette" id="__palette_0"> <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_1" hidden> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"/></svg> </label> <input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="slate" data-md-color-primary="indigo" data-md-color-accent="indigo" aria-label="Switch to light mode" type="radio" name="__palette" id="__palette_1"> <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_0" hidden> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12s-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"/></svg> </label> </form> <script>var palette=__md_get("__palette");if(palette&&palette.color){if("(prefers-color-scheme)"===palette.color.media){var media=matchMedia("(prefers-color-scheme: light)"),input=document.querySelector(media.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");palette.color.media=input.getAttribute("data-md-color-media"),palette.color.scheme=input.getAttribute("data-md-color-scheme"),palette.color.primary=input.getAttribute("data-md-color-primary"),palette.color.accent=input.getAttribute("data-md-color-accent")}for(var[key,value]of Object.entries(palette.color))document.body.setAttribute("data-md-color-"+key,value)}</script> <label class="md-header__button md-icon" for="__search"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg> </label> <div class="md-search" data-md-component="search" role="dialog"> <label class="md-search__overlay" for="__search"></label> <div class="md-search__inner" role="search"> <form class="md-search__form" name="search"> <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required> <label class="md-search__icon md-icon" for="__search"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg> </label> <nav class="md-search__options" aria-label="Search"> <button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg> </button> </nav> <div class="md-search__suggest" data-md-component="search-suggest"></div> </form> <div class="md-search__output"> <div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix> <div class="md-search-result" data-md-component="search-result"> <div class="md-search-result__meta"> Initializing search </div> <ol class="md-search-result__list" role="presentation"></ol> </div> </div> </div> </div> </div> <div class="md-header__source"> <a href="https://github.com/prefrontal-systems/cortexgraph" title="Go to repository" class="md-source" data-md-component="source"> <div class="md-source__icon md-icon"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </div> <div class="md-source__repository"> prefrontal-systems/cortexgraph </div> </a> </div> </nav> </header> <div class="md-container" data-md-component="container"> <nav class="md-tabs" aria-label="Tabs" data-md-component="tabs"> <div class="md-grid"> <ul class="md-tabs__list"> <li class="md-tabs__item"> <a href=".." class="md-tabs__link"> Home </a> </li> <li class="md-tabs__item"> <a href="../installation/" class="md-tabs__link"> Getting Started </a> </li> <li class="md-tabs__item"> <a href="../architecture/" class="md-tabs__link"> Documentation </a> </li> <li class="md-tabs__item"> <a href="../deployment/" class="md-tabs__link"> Deployment </a> </li> <li class="md-tabs__item"> <a href="../CONTRIBUTING/" class="md-tabs__link"> Development </a> </li> <li class="md-tabs__item"> <a href="../features/auto-recall-conversation/" class="md-tabs__link"> Features </a> </li> <li class="md-tabs__item"> <a href="../LICENSE/" class="md-tabs__link"> About </a> </li> </ul> </div> </nav> <main class="md-main" data-md-component="main"> <div class="md-main__inner md-grid"> <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" > <div class="md-sidebar__scrollwrap"> <div class="md-sidebar__inner"> <nav class="md-nav md-nav--primary md-nav--lifted" aria-label="Navigation" data-md-level="0"> <label class="md-nav__title" for="__drawer"> <a href=".." title="CortexGraph Documentation" class="md-nav__button md-logo" aria-label="CortexGraph Documentation" data-md-component="logo"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54"/></svg> </a> CortexGraph Documentation </label> <div class="md-nav__source"> <a href="https://github.com/prefrontal-systems/cortexgraph" title="Go to repository" class="md-source" data-md-component="source"> <div class="md-source__icon md-icon"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </div> <div class="md-source__repository"> prefrontal-systems/cortexgraph </div> </a> </div> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href=".." class="md-nav__link"> <span class="md-ellipsis"> Home </span> </a> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_2" > <label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0"> <span class="md-ellipsis"> Getting Started </span> <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="false"> <label class="md-nav__title" for="__nav_2"> <span class="md-nav__icon md-icon"></span> Getting Started </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="../installation/" class="md-nav__link"> <span class="md-ellipsis"> Installation </span> </a> </li> <li class="md-nav__item"> <a href="../quickstart/" class="md-nav__link"> <span class="md-ellipsis"> Quick Start </span> </a> </li> <li class="md-nav__item"> <a href="../configuration/" class="md-nav__link"> <span class="md-ellipsis"> Configuration </span> </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_3" > <label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0"> <span class="md-ellipsis"> Documentation </span> <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false"> <label class="md-nav__title" for="__nav_3"> <span class="md-nav__icon md-icon"></span> Documentation </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="../architecture/" class="md-nav__link"> <span class="md-ellipsis"> Architecture </span> </a> </li> <li class="md-nav__item"> <a href="../api/" class="md-nav__link"> <span class="md-ellipsis"> API Reference </span> </a> </li> <li class="md-nav__item"> <a href="../graph_features/" class="md-nav__link"> <span class="md-ellipsis"> Knowledge Graph </span> </a> </li> <li class="md-nav__item"> <a href="../scoring_algorithm/" class="md-nav__link"> <span class="md-ellipsis"> Scoring Algorithm </span> </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_4" > <label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0"> <span class="md-ellipsis"> Deployment </span> <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false"> <label class="md-nav__title" for="__nav_4"> <span class="md-nav__icon md-icon"></span> Deployment </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="../deployment/" class="md-nav__link"> <span class="md-ellipsis"> Deployment Guide </span> </a> </li> <li class="md-nav__item"> <a href="../security/" class="md-nav__link"> <span class="md-ellipsis"> Security </span> </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_5" > <label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0"> <span class="md-ellipsis"> Development </span> <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false"> <label class="md-nav__title" for="__nav_5"> <span class="md-nav__icon md-icon"></span> Development </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="../CONTRIBUTING/" class="md-nav__link"> <span class="md-ellipsis"> Contributing </span> </a> </li> <li class="md-nav__item"> <a href="../ROADMAP/" class="md-nav__link"> <span class="md-ellipsis"> Roadmap </span> </a> </li> <li class="md-nav__item"> <a href="../future_roadmap/" class="md-nav__link"> <span class="md-ellipsis"> Future Plans </span> </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_6" > <label class="md-nav__link" for="__nav_6" id="__nav_6_label" tabindex="0"> <span class="md-ellipsis"> Features </span> <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_6_label" aria-expanded="false"> <label class="md-nav__title" for="__nav_6"> <span class="md-nav__icon md-icon"></span> Features </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="../features/auto-recall-conversation/" class="md-nav__link"> <span class="md-ellipsis"> Auto-Recall </span> </a> </li> </ul> </nav> </li> <li class="md-nav__item md-nav__item--nested"> <input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_7" > <label class="md-nav__link" for="__nav_7" id="__nav_7_label" tabindex="0"> <span class="md-ellipsis"> About </span> <span class="md-nav__icon md-icon"></span> </label> <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_7_label" aria-expanded="false"> <label class="md-nav__title" for="__nav_7"> <span class="md-nav__icon md-icon"></span> About </label> <ul class="md-nav__list" data-md-scrollfix> <li class="md-nav__item"> <a href="../LICENSE/" class="md-nav__link"> <span class="md-ellipsis"> License </span> </a> </li> <li class="md-nav__item"> <a href="../CHANGELOG/" class="md-nav__link"> <span class="md-ellipsis"> Changelog </span> </a> </li> </ul> </nav> </li> </ul> </nav> </div> </div> </div> <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" > <div class="md-sidebar__scrollwrap"> <div class="md-sidebar__inner"> <nav class="md-nav md-nav--secondary" aria-label="Table of contents"> <label class="md-nav__title" for="__toc"> <span class="md-nav__icon md-icon"></span> Table of contents </label> <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix> <li class="md-nav__item"> <a href="#overview" class="md-nav__link"> <span class="md-ellipsis"> Overview </span> </a> </li> <li class="md-nav__item"> <a href="#key-benefits" class="md-nav__link"> <span class="md-ellipsis"> Key Benefits </span> </a> </li> <li class="md-nav__item"> <a href="#architecture-components" class="md-nav__link"> <span class="md-ellipsis"> Architecture Components </span> </a> <nav class="md-nav" aria-label="Architecture Components"> <ul class="md-nav__list"> <li class="md-nav__item"> <a href="#1-proxy-server" class="md-nav__link"> <span class="md-ellipsis"> 1. Proxy Server </span> </a> </li> <li class="md-nav__item"> <a href="#2-local-llms" class="md-nav__link"> <span class="md-ellipsis"> 2. Local LLMs </span> </a> </li> <li class="md-nav__item"> <a href="#3-mcp-tool-chain" class="md-nav__link"> <span class="md-ellipsis"> 3. MCP Tool Chain </span> </a> </li> <li class="md-nav__item"> <a href="#4-validation-layer" class="md-nav__link"> <span class="md-ellipsis"> 4. Validation Layer </span> </a> </li> </ul> </nav> </li> <li class="md-nav__item"> <a href="#detailed-flow-description" class="md-nav__link"> <span class="md-ellipsis"> Detailed Flow Description </span> </a> <nav class="md-nav" aria-label="Detailed Flow Description"> <ul class="md-nav__list"> <li class="md-nav__item"> <a href="#phase-1-initial-intake" class="md-nav__link"> <span class="md-ellipsis"> Phase 1: Initial Intake </span> </a> </li> <li class="md-nav__item"> <a href="#phase-2-intelligent-routing" class="md-nav__link"> <span class="md-ellipsis"> Phase 2: Intelligent Routing </span> </a> </li> <li class="md-nav__item"> <a href="#phase-3-prompt-optimization" class="md-nav__link"> <span class="md-ellipsis"> Phase 3: Prompt Optimization </span> </a> </li> <li class="md-nav__item"> <a href="#phase-4-validation-refinement" class="md-nav__link"> <span class="md-ellipsis"> Phase 4: Validation &amp; Refinement </span> </a> </li> <li class="md-nav__item"> <a href="#phase-5-mcp-tool-chain-execution" class="md-nav__link"> <span class="md-ellipsis"> Phase 5: MCP Tool Chain Execution </span> </a> </li> <li class="md-nav__item"> <a href="#phase-6-final-assembly" class="md-nav__link"> <span class="md-ellipsis"> Phase 6: Final Assembly </span> </a> </li> <li class="md-nav__item"> <a href="#phase-7-claude-execution" class="md-nav__link"> <span class="md-ellipsis"> Phase 7: Claude Execution </span> </a> </li> </ul> </nav> </li> <li class="md-nav__item"> <a href="#sequence-diagram" class="md-nav__link"> <span class="md-ellipsis"> Sequence Diagram </span> </a> </li> <li class="md-nav__item"> <a href="#configuration-options" class="md-nav__link"> <span class="md-ellipsis"> Configuration Options </span> </a> <nav class="md-nav" aria-label="Configuration Options"> <ul class="md-nav__list"> <li class="md-nav__item"> <a href="#complexity-thresholds" class="md-nav__link"> <span class="md-ellipsis"> Complexity Thresholds </span> </a> </li> </ul> </nav> </li> </ul> </nav> </div> </div> </div> <div class="md-content" data-md-component="content"> <article class="md-content__inner md-typeset"> <a href="https://github.com/prefrontal-systems/cortexgraph/edit/main/docs/prompt_optimization_flow.md" title="Edit this page" class="md-content__button md-icon" rel="edit"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M10 20H6V4h7v5h5v3.1l2-2V8l-6-6H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h4zm10.2-7c.1 0 .3.1.4.2l1.3 1.3c.2.2.2.6 0 .8l-1 1-2.1-2.1 1-1c.1-.1.2-.2.4-.2m0 3.9L14.1 23H12v-2.1l6.1-6.1z"/></svg> </a> <h1 id="prompt-optimization-flow">Prompt Optimization Flow<a class="headerlink" href="#prompt-optimization-flow" title="Permanent link">&para;</a></h1> <h2 id="overview">Overview<a class="headerlink" href="#overview" title="Permanent link">&para;</a></h2> <p>This document describes a sophisticated prompt optimization architecture that intercepts, analyzes, enhances, and validates user prompts before they reach Claude. The system uses a multi-stage pipeline involving local LLMs, MCP tool chains, knowledge graph integration, and cloud-based optimization to maximize prompt quality while minimizing API costs.</p> <h2 id="key-benefits">Key Benefits<a class="headerlink" href="#key-benefits" title="Permanent link">&para;</a></h2> <ul> <li><strong>Zero Initial API Cost</strong>: All optimization happens before hitting paid Claude API endpoints</li> <li><strong>Intelligent Complexity Routing</strong>: Simple prompts bypass optimization for speed; complex prompts get full treatment</li> <li><strong>Knowledge Graph Integration</strong>: Automatically enriches prompts with relevant context from CortexGraph</li> <li><strong>Multi-Model Validation</strong>: Cross-validates optimizations using multiple LLMs to ensure quality</li> <li><strong>Flexible Architecture</strong>: Local LLMs can be swapped with cloud providers as needed</li> <li><strong>Metadata Enrichment</strong>: Adds confidence scores, similarity metrics, and processing metadata to prompts</li> </ul> <h2 id="architecture-components">Architecture Components<a class="headerlink" href="#architecture-components" title="Permanent link">&para;</a></h2> <h3 id="1-proxy-server">1. <strong>Proxy Server</strong><a class="headerlink" href="#1-proxy-server" title="Permanent link">&para;</a></h3> <ul> <li>Central orchestration layer</li> <li>Handles routing decisions based on complexity</li> <li>Manages communication between all components</li> <li>Tracks confidence/similarity thresholds</li> </ul> <h3 id="2-local-llms">2. <strong>Local LLMs</strong><a class="headerlink" href="#2-local-llms" title="Permanent link">&para;</a></h3> <ul> <li>Primary: Prompt optimization and tagging</li> <li>Validation: Multiple instances for cross-validation</li> <li>Can be replaced with cloud providers (OpenAI, Anthropic, etc.)</li> </ul> <h3 id="3-mcp-tool-chain">3. <strong>MCP Tool Chain</strong><a class="headerlink" href="#3-mcp-tool-chain" title="Permanent link">&para;</a></h3> <ul> <li><strong>CortexGraph</strong>: Knowledge graph for context retrieval</li> <li><strong>STOPPER</strong>: Process control and validation</li> <li><strong>Custom Tools</strong>: User-defined extensions</li> <li><strong>Gemini Optimizer</strong>: Large context window for final assembly</li> </ul> <h3 id="4-validation-layer">4. <strong>Validation Layer</strong><a class="headerlink" href="#4-validation-layer" title="Permanent link">&para;</a></h3> <ul> <li>Semantic similarity checks</li> <li>Confidence scoring</li> <li>Iterative refinement below thresholds</li> </ul> <h2 id="detailed-flow-description">Detailed Flow Description<a class="headerlink" href="#detailed-flow-description" title="Permanent link">&para;</a></h2> <h3 id="phase-1-initial-intake">Phase 1: Initial Intake<a class="headerlink" href="#phase-1-initial-intake" title="Permanent link">&para;</a></h3> <ol> <li><strong>User Input</strong>: User enters prompt in Claude Code interface</li> <li><strong>Proxy Intercept</strong>: Proxy captures the prompt before it reaches Claude</li> <li><strong>Complexity Analysis</strong>: NLP-based complexity rating determines routing strategy</li> </ol> <h3 id="phase-2-intelligent-routing">Phase 2: Intelligent Routing<a class="headerlink" href="#phase-2-intelligent-routing" title="Permanent link">&para;</a></h3> <ol> <li><strong>Simple Path</strong> (Low Complexity):</li> <li>Proxy applies basic formatting rules</li> <li>Routes directly to Claude with minimal processing</li> <li> <p>Optimizes for speed and reduces overhead</p> </li> <li> <p><strong>Complex Path</strong> (High Complexity):</p> </li> <li>Triggers full optimization pipeline</li> <li>Proceeds to Phase 3</li> </ol> <h3 id="phase-3-prompt-optimization">Phase 3: Prompt Optimization<a class="headerlink" href="#phase-3-prompt-optimization" title="Permanent link">&para;</a></h3> <ol> <li><strong>Local LLM Processing</strong>:</li> <li>Adds semantic tags to categorize intent</li> <li>Restructures prompt for optimal Claude comprehension</li> <li>Formats according to Claude best practices</li> <li>Extracts key entities and concepts</li> </ol> <h3 id="phase-4-validation-refinement">Phase 4: Validation &amp; Refinement<a class="headerlink" href="#phase-4-validation-refinement" title="Permanent link">&para;</a></h3> <ol> <li><strong>Multi-Model Validation</strong>:</li> <li>Routes optimized prompt to 2-n additional local LLMs</li> <li>Each validator scores the optimization independently</li> <li>Can use semantic similarity algorithms instead of LLMs</li> <li> <p>Calculates confidence and similarity metrics</p> </li> <li> <p><strong>Threshold Check</strong>:</p> </li> <li>If scores meet threshold: Proceed to Phase 5</li> <li>If scores below threshold: Return to Phase 3 for reprocessing</li> <li> <p>Prevents low-quality optimizations from proceeding</p> </li> <li> <p><strong>Tool Recommendation</strong>:</p> </li> <li>Proxy receives validated prompt with metadata</li> <li>System suggests relevant MCP tools for the query</li> </ol> <h3 id="phase-5-mcp-tool-chain-execution">Phase 5: MCP Tool Chain Execution<a class="headerlink" href="#phase-5-mcp-tool-chain-execution" title="Permanent link">&para;</a></h3> <ol> <li> <p><strong>CortexGraph Search</strong>:</p> <ul> <li>Searches knowledge graph for related concepts</li> <li>Retrieves relevant memories and context</li> <li>Returns similarity-scored results</li> </ul> </li> <li> <p><strong>STOPPER Validation</strong>:</p> <ul> <li>Process control checks</li> <li>Safety and constraint validation</li> <li>Prevents out-of-scope operations</li> </ul> </li> <li> <p><strong>Additional Tools</strong>:</p> <ul> <li>Routes to n other tools based on user preferences</li> <li>Each tool contributes specialized context</li> <li>Tools run in parallel for efficiency</li> </ul> </li> </ol> <h3 id="phase-6-final-assembly">Phase 6: Final Assembly<a class="headerlink" href="#phase-6-final-assembly" title="Permanent link">&para;</a></h3> <ol> <li> <p><strong>Gemini Optimization</strong>:</p> <ul> <li>Combines original prompt + optimizations + tool outputs</li> <li>Leverages Gemini's large context window (2M tokens)</li> <li>Uses generous free tier for cost optimization</li> <li>Assembles coherent final prompt</li> </ul> </li> <li> <p><strong>Quality Assurance</strong>:</p> <ul> <li>Compares input to assembled output</li> <li>Generates similarity score (drift detection)</li> <li>Calculates final confidence rating</li> <li>Appends metadata to prompt</li> </ul> </li> </ol> <h3 id="phase-7-claude-execution">Phase 7: Claude Execution<a class="headerlink" href="#phase-7-claude-execution" title="Permanent link">&para;</a></h3> <ol> <li> <p><strong>Final Prompt Delivery</strong>:</p> <ul> <li>Proxy sends optimized prompt to Claude</li> <li><strong>First API cost incurred at this step</strong></li> <li>Prompt includes:</li> <li>Original user intent (preserved)</li> <li>Optimization tags and structure</li> <li>Knowledge graph context</li> <li>Tool outputs and recommendations</li> <li>Confidence/similarity metadata</li> <li>Processing history</li> </ul> </li> <li> <p><strong>Normal Operation</strong>:</p> <ul> <li>Claude processes the enriched prompt</li> <li>Claude Code continues standard workflow</li> <li>User receives high-quality response</li> </ul> </li> </ol> <h2 id="sequence-diagram">Sequence Diagram<a class="headerlink" href="#sequence-diagram" title="Permanent link">&para;</a></h2> <p>```mermaid sequenceDiagram actor User participant Claude Code Interface participant Proxy participant NLP Complexity Analyzer participant Local LLM (Optimizer) participant Local LLM 2 (Validator) participant Local LLM N (Validator) participant Semantic Similarity Engine participant MCP Chain participant CortexGraph participant STOPPER participant Custom Tools participant Gemini participant Claude API</p> <div class="highlight"><pre><span></span><code>%% Phase 1: Initial Intake User-&gt;&gt;Claude Code Interface: Enter prompt Claude Code Interface-&gt;&gt;Proxy: Forward prompt Proxy-&gt;&gt;NLP Complexity Analyzer: Analyze complexity NLP Complexity Analyzer--&gt;&gt;Proxy: Complexity rating %% Phase 2: Routing Decision alt Low Complexity (Simple Prompt) Proxy-&gt;&gt;Proxy: Apply basic rules Proxy-&gt;&gt;Claude API: Route directly to Claude Note over Proxy,Claude API: Fast path for simple queries else High Complexity (Complex Prompt) Note over Proxy: Trigger full optimization pipeline %% Phase 3: Optimization Proxy-&gt;&gt;Local LLM (Optimizer): Optimize prompt Note over Local LLM (Optimizer): - Add semantic tags&lt;br/&gt;- Format for Claude&lt;br/&gt;- Extract entities&lt;br/&gt;- Restructure query Local LLM (Optimizer)--&gt;&gt;Proxy: Optimized prompt v1 %% Phase 4: Validation Loop rect rgb(240, 240, 240) Note over Proxy,Semantic Similarity Engine: Validation &amp; Refinement Loop par Parallel Validation Proxy-&gt;&gt;Local LLM 2 (Validator): Validate optimization Proxy-&gt;&gt;Local LLM N (Validator): Validate optimization Proxy-&gt;&gt;Semantic Similarity Engine: Check semantic similarity end Local LLM 2 (Validator)--&gt;&gt;Proxy: Confidence score 2 Local LLM N (Validator)--&gt;&gt;Proxy: Confidence score N Semantic Similarity Engine--&gt;&gt;Proxy: Similarity score Proxy-&gt;&gt;Proxy: Aggregate scores alt Below Confidence/Similarity Threshold Note over Proxy,Local LLM (Optimizer): Quality check failed Proxy-&gt;&gt;Local LLM (Optimizer): Reprocess with feedback Local LLM (Optimizer)--&gt;&gt;Proxy: Optimized prompt v2 Note over Proxy: Loop until threshold met else Above Threshold Note over Proxy: Quality validated, proceed end end Proxy-&gt;&gt;Proxy: Append recommendation metadata %% Phase 5: MCP Tool Chain Proxy-&gt;&gt;MCP Chain: Route validated prompt + metadata rect rgb(230, 245, 255) Note over MCP Chain,Custom Tools: MCP Tool Execution (Parallel) par Tool Execution MCP Chain-&gt;&gt;CortexGraph: Search knowledge graph MCP Chain-&gt;&gt;STOPPER: Validate constraints MCP Chain-&gt;&gt;Custom Tools: Execute user-defined tools end CortexGraph--&gt;&gt;MCP Chain: Context + memories (similarity scored) STOPPER--&gt;&gt;MCP Chain: Validation results Custom Tools--&gt;&gt;MCP Chain: Tool outputs end %% Phase 6: Final Assembly MCP Chain-&gt;&gt;Gemini: Assemble final prompt Note over Gemini: - Combine all inputs&lt;br/&gt;- Optimize structure&lt;br/&gt;- 2M token context&lt;br/&gt;- Free tier usage Gemini-&gt;&gt;Gemini: Compare input vs output Gemini-&gt;&gt;Gemini: Calculate similarity &amp; confidence Gemini--&gt;&gt;MCP Chain: Final prompt + metadata MCP Chain--&gt;&gt;Proxy: Return final prompt %% Phase 7: Claude Execution Note over Proxy,Claude API: 💰 First API cost incurred here Proxy-&gt;&gt;Claude API: Send final optimized prompt Note over Claude API: Prompt includes:&lt;br/&gt;- Original intent&lt;br/&gt;- Optimizations&lt;br/&gt;- Knowledge graph context&lt;br/&gt;- Tool outputs&lt;br/&gt;- Metadata end %% Normal Operation Claude API--&gt;&gt;Claude Code Interface: Process request Claude Code Interface--&gt;&gt;User: Return response Note over User,Claude Code Interface: Claude Code continues as normal </code></pre></div> <p>```</p> <h2 id="configuration-options">Configuration Options<a class="headerlink" href="#configuration-options" title="Permanent link">&para;</a></h2> <h3 id="complexity-thresholds">Complexity Thresholds<a class="headerlink" href="#complexity-thresholds" title="Permanent link">&para;</a></h3> <p>```python</p> <h1 id="proxy-configuration">Proxy configuration<a class="headerlink" href="#proxy-configuration" title="Permanent link">&para;</a></h1> <h1 id="prompts-with-complexity-complex_prompt_threshold-follow-the-complex-path-otherwise-the-simple-path-is-used">Prompts with complexity &gt; COMPLEX_PROMPT_THRESHOLD follow the complex path, otherwise the simple path is used.<a class="headerlink" href="#prompts-with-complexity-complex_prompt_threshold-follow-the-complex-path-otherwise-the-simple-path-is-used" title="Permanent link">&para;</a></h1> <p>COMPLEX_PROMPT_THRESHOLD = 0.4 ```</p> <h3 id="validation-settings">Validation Settings<a class="headerlink" href="#validation-settings" title="Permanent link">&para;</a></h3> <p>```python</p> <h1 id="validation-thresholds">Validation thresholds<a class="headerlink" href="#validation-thresholds" title="Permanent link">&para;</a></h1> <p>CONFIDENCE_THRESHOLD = 0.75 # Minimum confidence to proceed SIMILARITY_THRESHOLD = 0.80 # Minimum semantic similarity MAX_REFINEMENT_ITERATIONS = 3 # Prevent infinite loops ```</p> <h3 id="model-selection">Model Selection<a class="headerlink" href="#model-selection" title="Permanent link">&para;</a></h3> <p>```python</p> <h1 id="local-llms-can-be-replaced-with-cloud-providers">Local LLMs (can be replaced with cloud providers)<a class="headerlink" href="#local-llms-can-be-replaced-with-cloud-providers" title="Permanent link">&para;</a></h1> <p>OPTIMIZER_MODEL = "llama-3.1-70b" # Primary optimizer VALIDATOR_MODELS = [ # Validation ensemble "mixtral-8x7b", "qwen-2.5-72b", "deepseek-v2" ]</p> <h1 id="example-using-cloud-providers-alternative-to-local">Example using cloud providers (alternative to local)<a class="headerlink" href="#example-using-cloud-providers-alternative-to-local" title="Permanent link">&para;</a></h1> <h1 id="optimizer_model-openaigpt-4">OPTIMIZER_MODEL = "openai:gpt-4"<a class="headerlink" href="#optimizer_model-openaigpt-4" title="Permanent link">&para;</a></h1> <h1 id="validator_models-anthropicclaude-3-opus-openaigpt-4">VALIDATOR_MODELS = ["anthropic:claude-3-opus", "openai:gpt-4"]<a class="headerlink" href="#validator_models-anthropicclaude-3-opus-openaigpt-4" title="Permanent link">&para;</a></h1> <p>```</p> <h3 id="mcp-tools">MCP Tools<a class="headerlink" href="#mcp-tools" title="Permanent link">&para;</a></h3> <p>```python</p> <h1 id="tool-chain-configuration">Tool chain configuration<a class="headerlink" href="#tool-chain-configuration" title="Permanent link">&para;</a></h1> <p>MCP_TOOLS = { "cortex_graph": { "enabled": True, "similarity_threshold": 0.7, "max_results": 10 }, "stopper": { "enabled": True, "strict_mode": False }, "custom": { "user_preferences": True, "context_retrieval": True } } ```</p> <h3 id="gemini-settings">Gemini Settings<a class="headerlink" href="#gemini-settings" title="Permanent link">&para;</a></h3> <p>```python</p> <h1 id="final-assembly-configuration">Final assembly configuration<a class="headerlink" href="#final-assembly-configuration" title="Permanent link">&para;</a></h1> <p>GEMINI_MODEL = "gemini-2.0-flash-exp" # Free tier, large context GEMINI_MAX_TOKENS = 2000000 # 2M token context window GEMINI_TEMPERATURE = 0.3 # Consistent assembly ```</p> <h2 id="performance-characteristics">Performance Characteristics<a class="headerlink" href="#performance-characteristics" title="Permanent link">&para;</a></h2> <h3 id="latency-profile">Latency Profile<a class="headerlink" href="#latency-profile" title="Permanent link">&para;</a></h3> <table> <thead> <tr> <th>Stage</th> <th>Estimated Time</th> <th>Notes</th> </tr> </thead> <tbody> <tr> <td>Complexity Analysis</td> <td>10-50ms</td> <td>Fast NLP classification</td> </tr> <tr> <td>Simple Path (total)</td> <td>50-100ms</td> <td>Minimal processing overhead</td> </tr> <tr> <td>Optimization</td> <td>200-500ms</td> <td>Local LLM inference</td> </tr> <tr> <td>Validation</td> <td>150-300ms</td> <td>Parallel execution</td> </tr> <tr> <td>MCP Tool Chain</td> <td>100-400ms</td> <td>Depends on tool complexity</td> </tr> <tr> <td>Gemini Assembly</td> <td>300-800ms</td> <td>Large context processing</td> </tr> <tr> <td><strong>Complex Path (total)</strong></td> <td><strong>1-3 seconds</strong></td> <td>Full pipeline</td> </tr> </tbody> </table> <h3 id="cost-analysis">Cost Analysis<a class="headerlink" href="#cost-analysis" title="Permanent link">&para;</a></h3> <p><strong>Traditional Approach</strong> (direct to Claude): - Every prompt hits Claude API immediately - No optimization or context enrichment - Cost: $X per request from first token</p> <p><strong>Optimized Approach</strong> (this architecture): - Local LLMs: Free (self-hosted) or cheap (cloud) - Gemini: Leverages the generous free tier for final assembly - Claude API: Only hit after full optimization - Cost: $0 until Claude execution, then same $X but better results</p> <p><strong>Net Effect</strong>: - Same Claude API cost per request - Significantly better prompt quality - Higher success rate (fewer retries needed) - Lower total cost due to reduced iterations</p> <h2 id="implementation-considerations">Implementation Considerations<a class="headerlink" href="#implementation-considerations" title="Permanent link">&para;</a></h2> <h3 id="1-local-llm-requirements">1. <strong>Local LLM Requirements</strong><a class="headerlink" href="#1-local-llm-requirements" title="Permanent link">&para;</a></h3> <ul> <li>GPU: RTX 4090 or better for 70B models</li> <li>RAM: 64GB+ recommended</li> <li>Alternative: Use cloud inference APIs (Groq, Together.ai, OpenRouter)</li> </ul> <h3 id="2-proxy-server">2. <strong>Proxy Server</strong><a class="headerlink" href="#2-proxy-server" title="Permanent link">&para;</a></h3> <ul> <li>Needs to be MCP-compatible</li> <li>Should support WebSocket for streaming</li> <li>Must handle concurrent validation requests</li> </ul> <h3 id="3-knowledge-graph-integration">3. <strong>Knowledge Graph Integration</strong><a class="headerlink" href="#3-knowledge-graph-integration" title="Permanent link">&para;</a></h3> <ul> <li>CortexGraph needs to be populated with relevant data</li> <li>Index must be kept up-to-date</li> <li>Consider using CortexGraph for temporal memory</li> </ul> <h3 id="4-error-handling">4. <strong>Error Handling</strong><a class="headerlink" href="#4-error-handling" title="Permanent link">&para;</a></h3> <ul> <li>Fallback to simple path if optimization fails</li> <li>Timeout protection (max 5s total processing)</li> <li>Graceful degradation if tools unavailable</li> </ul> <h3 id="5-monitoring-observability">5. <strong>Monitoring &amp; Observability</strong><a class="headerlink" href="#5-monitoring-observability" title="Permanent link">&para;</a></h3> <ul> <li>Track optimization success rates</li> <li>Monitor confidence/similarity distributions</li> <li>Log processing times for each stage</li> <li>A/B test optimized vs non-optimized prompts</li> </ul> <h2 id="future-enhancements">Future Enhancements<a class="headerlink" href="#future-enhancements" title="Permanent link">&para;</a></h2> <ol> <li><strong>Adaptive Thresholds</strong>: Learn optimal confidence/similarity thresholds per user</li> <li><strong>Caching Layer</strong>: Cache optimizations for similar prompts</li> <li><strong>User Feedback Loop</strong>: Incorporate user ratings to improve optimization</li> <li><strong>Model Selection</strong>: Automatically choose best LLM based on prompt type</li> <li><strong>Streaming Optimization</strong>: Stream partial results during processing</li> <li><strong>Cost Tracking</strong>: Detailed cost accounting per stage</li> <li><strong>A/B Testing Framework</strong>: Compare different optimization strategies</li> </ol> <h2 id="security-considerations">Security Considerations<a class="headerlink" href="#security-considerations" title="Permanent link">&para;</a></h2> <ul> <li><strong>Prompt Injection</strong>: Validate all optimized prompts for injection attempts</li> <li><strong>Data Privacy</strong>: Local LLMs keep sensitive data on-premise</li> <li><strong>Rate Limiting</strong>: Prevent abuse of free tier services</li> <li><strong>Access Control</strong>: Authenticate proxy requests</li> <li><strong>Audit Trail</strong>: Log all prompt transformations</li> </ul> <h2 id="related-documentation">Related Documentation<a class="headerlink" href="#related-documentation" title="Permanent link">&para;</a></h2> <ul> <li><a href="../architecture/">CortexGraph Architecture</a> - Integration with temporal memory</li> <li><a href="../graph_features/">CortexGraph Documentation</a> - Knowledge graph features</li> <li><a href="https://github.com/modelcontextprotocol/specification">MCP Specification</a> - Tool protocol details</li> <li><a href="../prompt_injection/">Prompt Injection Prevention</a> - Security best practices</li> </ul> <h2 id="example-workflow">Example Workflow<a class="headerlink" href="#example-workflow" title="Permanent link">&para;</a></h2> <h3 id="input-prompt">Input Prompt<a class="headerlink" href="#input-prompt" title="Permanent link">&para;</a></h3> <p>``` "Help me write a Python function to process user data" ```</p> <h3 id="after-optimization">After Optimization<a class="headerlink" href="#after-optimization" title="Permanent link">&para;</a></h3> <p>```markdown</p> <h2 id="task-python-function-development">Task: Python Function Development<a class="headerlink" href="#task-python-function-development" title="Permanent link">&para;</a></h2> <p><strong>User Intent</strong>: Create data processing function</p> <p><strong>Context</strong> (from CortexGraph): - User prefers type hints (from memory: 2025-10-15) - Uses pytest for testing (from memory: 2025-10-20) - Prefers dataclasses over dicts (from memory: 2025-10-12)</p> <p><strong>Requirements</strong>: 1. Function should process user data 2. Follow user's Python style preferences 3. Include type hints and docstrings 4. Consider testing approach</p> <p><strong>Metadata</strong>: - Confidence: 0.87 - Similarity: 0.92 - Optimization iterations: 1 - Tools used: CortexGraph, STOPPER - Processing time: 1.2s ```</p> <h3 id="result">Result<a class="headerlink" href="#result" title="Permanent link">&para;</a></h3> <p>Claude receives a rich, contextualized prompt that produces higher-quality output on the first try, reducing the need for follow-up iterations.</p> <hr /> <p><strong>Built with</strong> <a href="https://claude.com/claude-code">Claude Code</a> 🤖</p> </article> </div> <script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script> </div> <button type="button" class="md-top md-icon" data-md-component="top" hidden> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg> Back to top </button> </main> <footer class="md-footer"> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class="md-copyright"> Made with <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener"> Material for MkDocs </a> </div> <div class="md-social"> <a href="https://github.com/prefrontal-systems/cortexgraph" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M173.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6m-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3m44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9M252.8 8C114.1 8 8 113.3 8 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C436.2 457.8 504 362.9 504 252 504 113.3 391.5 8 252.8 8M105.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1m-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7m32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1m-11.4-14.7c-1.6 1-1.6 3.6 0 5.9s4.3 3.3 5.6 2.3c1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2"/></svg> </a> <a href="https://github.com/prefrontal-systems/cortexgraph/discussions" target="_blank" rel="noopener" title="github.com" class="md-social__link"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><!--! Font Awesome Free 7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2025 Fonticons, Inc.--><path d="M384 144c0 97.2-86 176-192 176-26.7 0-52.1-5-75.2-14l-81.6 43.2c-9.3 4.9-20.7 3.2-28.2-4.2s-9.2-18.9-4.2-28.2l35.6-67.2C14.3 220.2 0 183.6 0 144 0 46.8 86-32 192-32s192 78.8 192 176m0 368c-94.1 0-172.4-62.1-188.8-144 120-1.5 224.3-86.9 235.8-202.7 83.3 19.2 145 88.3 145 170.7 0 39.6-14.3 76.2-38.4 105.6l35.6 67.2c4.9 9.3 3.2 20.7-4.2 28.2s-18.9 9.2-28.2 4.2L459.2 498c-23.1 9-48.5 14-75.2 14"/></svg> </a> </div> </div> </div> </footer> </div> <div class="md-dialog" data-md-component="dialog"> <div class="md-dialog__inner md-typeset"></div> </div> <script id="__config" type="application/json">{"annotate": null, "base": "..", "features": ["navigation.instant", "navigation.tracking", "navigation.tabs", "navigation.sections", "navigation.expand", "navigation.top", "search.suggest", "search.highlight", "content.code.copy", "content.code.annotate", "content.action.edit"], "search": "../assets/javascripts/workers/search.7a47a382.min.js", "tags": null, "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": null}</script> <script src="../assets/javascripts/bundle.e71a0d61.min.js"></script> </body> </html>

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/prefrontalsys/mnemex'

If you have feedback or need assistance with the MCP directory API, please join our Discord server