Pre-Query Custom Endpoint Call and Placeholder Replacement for Classification & Knowledge Graph Memory Layer or Other Data

Summary: Expand the existing architecture to include a pre-query endpoint call and placeholder replacement that can be used for a classifier step with custom directives and knowledge graph memory system support, offering an alternative to the current flat key-value pair memory system, and other pre-query functionality that might not explicitly involve a memory system

The Problem: The current key-value pair memory system, capped at 100 slots for Pro accounts, functions adequately for basic state retention, but lacks the relational depth required for some use cases, like user behavior analysis. When building complex AI agents, a flat memory structure forces the system to treat every piece of context with equal, disconnected weight, and we do not have the ability to analyze behaviors over time. This is especially important for safety systems.
For example, my Simulation endpoint users are navigating through complex social and workplace simulations where they are required to demonstrate behaviors across various complication social and business situations. The flat key-value pair memory system can track generalizations in behaviors demonstrated, but cannot engage in the time-based pattern detection operations like a classifier + knowledge graph database (such as Neo4j). That type of analysis and pattern detection provides tremendous value to the Simulation process and to the communication skills development of the users, which is the entire reason that they are engaging with the Simulation agent.
There are other use cases where a pre-query endpoint call that includes the chat history and user data for billing and tracking purposes might be useful.

The Solution:

Pre-Query Classifier: An invisible intermediary step that analyzes input to extract relevant data to use in the knowledge graph db query and memory agent report to include with the main agent request before it generates a response. This uses a small model and custom directives and a model query that returns a JSON object containing the required analysis. In addition to its usage in the knowledge graph memory system, I have previously used the classifier to detect if certain agents or instructions are required to be included in the main query, such as those governing image generation, Composio, and search tool usage, among others.

Knowledge Graph Layer: A relational memory structure that maps the connections between different data points/nodes, rather than isolating them in separate slots. For example, my current solution tracks entities, situations, and detected patterns, and is especially helpful in safety for detecting patterns of toxicity in these data points. Most of these high-value pattern detections would remain hidden in a flat key-value pair memory system.

Custom pre-query endpoint and self-hosting of knowledge graph database: This solution may be more complex than most users would require, and the enterprise requirements for hosting a scalable multi-user knowledge graph database are quite complex. Offering a self-hosted option with a custom pre-query endpoint call that includes the original request with the whole chat history and the user data for billing purposes, and that can include a classifier query using the existing Pickaxe API (compatible with monetized agents, of course, such that users are charged for the end user credits used by the classifier query) and custom functions that call a self-hosted knowledge graph db (such as Neo4j on Railway) and then generate a report that gets returned and included with its own placeholder replacement, such as {PX_custom_pre_query_report}, would be comparatively easy to implement.

The Impact: As developers create more sophisticated workflows, agents must understand the relationships between variables. A knowledge graph layer combined with pre-query classification allows for highly contextual memory retrieval that scales significantly better than static prompts. Offering a custom pre-query endpoint call and a custom placeholder replacement is a relatively fast way to offer this functionality without taking on the complexity of the entire classifier plus knowledge graph db operations workflow and adding it to the existing processes.

This would be an excellent feature for Pro plans so that I can use it.

Thank you very much for taking community feature requests seriously!