Written by Katsiaryna Yanchanka
Abstract
In high-stakes service industries, managing communication during protracted engagement periods presents significant computational and empathetic challenges. Users often pose vague inquiries (e.g., “Any updates?”) requiring context-heavy responses that standard Retrieval-Augmented Generation (RAG) pipelines struggle to process efficiently. This paper introduces an open-source Dynamic Context Engine, a novel Generative AI library designed to automate complex email responses by prioritizing empathy, accuracy, and latency. Unlike traditional RAG, this library utilizes a unique two-step query architecture: an initial query analyzes intent to identifying necessary documentation, followed by a targeted retrieval process that injects only relevant files into the context window. A third-party evaluation conducted by a firm handling mass litigation validated the efficacy of this framework. The pilot implementation demonstrated that the library autonomously handled 46 out of 50 complex inquiries, achieving 96% automation and reducing response latency to under 5 minutes for 99.9% of cases. This work contributes to the open-source community by offering a scalable, low-overhead alternative to vector-heavy retrieval systems for sensitive communication.
Introduction
The application of Artificial Intelligence (AI) in regulated sectors is often hindered by the “black box” nature of standard retrieval systems. While Large Language Models (LLMs) excel at generation, grounding them in specific user history without incurring massive token costs remains a hurdle. This is particularly evident in industries dealing with multi-year lifecycles, where stakeholders frequently request ambiguous status updates.
Existing open-source solutions often rely on static vector databases. However, these struggle when the “answer” requires synthesizing emotional tone with specific historical documents. This paper details the architecture of a new open-source library designed to bridge this gap. By decoupling the identification of context from the generation of content, the library allows developers to build “empathetic automation” pipelines that are both computationally efficient and highly accurate.
To validate the library’s utility, a case study is presented involving an independent deployment by an organization in the regulated services sector, which utilized the framework to manage high-volume, sensitive correspondence.
Technical Architecture & Methodology
The core contribution of this work is the Dynamic Context mechanism, released as a modular Python library compatible with Azure Functions and OpenAI endpoints.
The Two-Step Query Logic
Standard RAG often retrieves chunks based on semantic similarity, which can miss the nuance of vague user queries. This library implements a logic-driven alternative:
- The Context Selector (Query I): The library first exposes the LLM to a manifest of available file metadata (structured as when_what, e.g., 2023_user_submission). It prompts the model not to answer the user, but to output a list of specific files required to construct a valid answer.
- The Generation Engine (Query II): The library dynamically retrieves only the files identified in step one. It then constructs a second prompt containing the user’s original inquiry, the targeted file contents, and the empathy parameters, instructing the LLM to generate the final response.
Case Study: Validation in a Regulated Environment
To test the robustness of the library, an external organization specializing in mass dispute resolution adopted the framework for a Proof of Concept (POC). The organization faced challenges with maintaining client trust over 5-7 year lifecycles.
Implementation Details
The adopting organization integrated the open-source library into their existing CRM. They utilized the library’s hook system to trigger automated drafting upon receipt of client emails.
- Data Structure: The organization utilized the library’s recommended file naming convention to index their knowledge base.
- Feedback Loop: The organization exposed logs generated by the library to analyze “skipped” files, allowing them to refine their internal prompt templates without altering the core codebase.
Performance Results
The independent metrics reported by the organization confirmed the library’s efficiency:
| Metric | Performance |
| Automation Accuracy | 96% |
| Latency (<5 mins) | 99.9% |
| Success Rate (POC) | 46/50 inquiries handled without human intervention |
The organization noted that the “Context Selector” step significantly reduced hallucinations compared to their previous attempts with well-funded companies: Abacus (80% accuracy), Forethought (40% accuracy), as the model was forced to explicitly justify which documents it was reading before answering, the comparison was conducted in February 2024.
Discussion
The success of this deployment highlights the viability of Dynamic Context as a superior alternative to vector search for specific use cases involving long document histories and vague queries. By empowering the LLM to “choose” its own context, the library reduces token consumption and increases the relevance of the output.
Furthermore, the “human-in-the-loop” design allows adopting teams, such as the success team at the testing organization, to optimize performance solely by updating their knowledge base, requiring no changes to the library’s source code.
Conclusion
This open-source framework demonstrates that splitting reasoning (context selection) from generation leads to higher fidelity in automated communications. The high accuracy rate achieved by the pilot organization suggests that this architecture is ready for broader adoption in fields requiring a delicate balance of technological efficiency and human-centric communication. Future updates to the library will focus on multimodal support and enhanced telemetry for debugging context selection logic.
References
- Open-source library: https://github.com/LamoomAI/lamoom-cicd
- Alarie, B., Niblett, A., & Yoon, A. H. (2018). How artificial intelligence will affect the practice of law. University of Toronto Law Journal, 68(1), 106–124. https://www.law.utoronto.ca/scholarship-publications/faculty-scholarship/publications/how-artificial-intelligence-will-affect
- Bucher, A. (2025). Navigating the power of artificial intelligence in the legal field. Houston Law Review, 62(4), 819–850. https://houstonlawreview.org/article/137782-navigating-the-power-of-artificial-intelligence-in-the-legal-field
- Huang, M.-H., Rust, R. T., & Maksimovic, V. (2023). The feeling economy: How artificial intelligence is creating the era of empathy. Journal of Service Research, 26(2), 159–176. https://www.rhsmith.umd.edu/news/feeling-economy-how-ai-creating-era-empathy
- Nasir, S., Abbas, Q., Bai, S., & Khan, R. A. (2024). A comprehensive framework for reliable legal AI: Combining specialized expert systems and adaptive refinement. https://arxiv.org/abs/2412.20468
- Remus, D., & Levy, F. (2017). Can robots be lawyers? Computers, lawyers, and the practice of law. Georgetown Journal of Legal Ethics, 30(3), 501–558. https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2701092
- Forte Group. (2025). Automated email response for legal services. Forte Group Case Studies. Retrieved from https://fortegrp.com/cases/automated-email-response[](https://fortegrp.com/cases/automated-email-response )
- Gao, T., Yao, X., & Chen, D. (2021). SimCSE: Simple contrastive learning of sentence embeddings. Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing, 6894–6910. https://arxiv.org/abs/2104.08821
- Brown, T. B., Mann, B., Ryder, N., Subbiah, M., Kaplan, J., Dhariwal, P., … & Amodei, D. (2020). Language models are few-shot learners. Advances in Neural Information Processing Systems, 33, 1877–1901. https://arxiv.org/abs/2005.14165
- Wirtz, J., Patterson, P. G., Kunz, W. H., Gruber, T., Lu, V. N., Paluch, S., & Martins, A. (2018). Brave new world: Service robots in the frontline. Journal of Service Management, 29(5), 907–931. https://espace.library.uq.edu.au/view/UQ:0c818bc
- Zafar, A. (2024). Balancing the scale: Navigating ethical and practical challenges of artificial intelligence (AI) integration in legal practices. Discover Artificial Intelligence, 4(27). https://link.springer.com/article/10.1007/s44163-024-00121-8