翻篇收录说明
翻篇网页快照

AI Context Management in Domain-specific Tools

https://eclipsesource.com/blogs/2024/07/26/ai-context-management-in-domain-specific-tools/

最近抓取:2026-12-03 21:51:46(北京时间)

最近内容变化:2026-12-03 21:51:46(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Discover how AI context management in domain-specific tools and IDEs can be implemented effectively. Learn practical strategies like Retrieval Augmented Generation (RAG), workspace maps, and autonomous context requests to enhance the quality and accuracy of your AI integration with DSLs, IDEs, and other tools.

正文摘录

AI Context Management in Domain-specific Tools byJonas, Maximilian & Philip July 26, 2024 | 19 min ReadIntegrating AI into custom tools and IDEs is transforming productivity in many industries. However, the true effectiveness of these AI integrations relies not just on the capabilities of Large Language Models (LLMs) but also on the efficient management of context within these tools, as outlined in a recent blog post.In this blog post, we explore the how of AI context management in tools and IDEs, focusing on domain-specific tools and providing practical strategies and real-world examples. You’ll learn about key techniques such as Retrieval Augmented Generation (RAG), workspace maps, and autonomous context requesting strategies. We’ll use a concrete example tool to illustrate how these strategies can be implemented effectively. By understanding and applying these methods, you can significantly enhance the performance and relevance of AI integrations in your domain-specific applications. Relevant Context in Domain-Specific ToolsIn software tools and IDEs, the AI integration needs to handle various types of context effectively. This includes:Workspace files and project configuration: The files that make up the current project, as well as its settings and configurations.Tool state: Information about open editors, selected elements, user interactions, problem markers, and more.While modern LLMs are often already familiar with general purpose programming languages and generic IDEs, domain-specific tools add another layer of complexity. As they might be unknown to the underlying LLM, they often require additional domain-specific knowledge, including:Domain-Specific Languages and Formats: Understanding the specific languages and data formats used in different domains, including their syntax and semantics.Custom Editors and Commands: Handling unique functionalities and commands provided by custom editors in the tool, such as graphical diagram editors, complex tree-, table- and form-based editors, with their own set of editing operations and capabilities.Specialized Knowledge of the Domain: Incorporating specific knowledge about the domain that might not be covered by off-the-shelf language models, such as specs of hardware components for embedded engineering or other unique rules, workflows, or constraints of the domain.Context Management and AugmentationManaging and augmenting the diverse range of context types is crucial. The challenge is to identify the right context with the right level of detail for a specific user request and feed this context to LLM alongside the user request. While context windows for modern language models are continuously expanding, adding lots of irrelevant data can unnecessarily increase costs and often even more importantly reduce response quality, as many language models are susceptible to the so-called lost-in-the-middle problem.The most common techniques to augment context in IDEs and tools include:Retrieval Augmented Generation (RAG): Retrieves relevant content from a data source for a given user request.Workspace Maps: Uses a parser generator like Tree-sitter to create a condensed tree representation of the workspace.Autonomous Context Requests: Sets up a prompt chain that incrementally provides context, allowing the LLM to choose and request context as needed.Example: Robot Engineering ToolWe will go into more detail about each of those context augmentation strategies based on a concrete example: a robot engineering tool. With this example tool users can define the behaviors of a robot built up from modular hardware components.A project in this tool includes:Configuration File: Specifies the project’s name, purpose, target runtime, and imported libraries.Hardware Component Model: Describes building blocks like sensors, actuators, and communication modules.Program Files: Defines robot behavior using a rule-based domain-specific language (event-condition-action).In this example, we want to provide an AI assistant that can help users with questions in three categories:Hardware Components Catalog: For questions about hardware components, we use RAG.Code: For code-related questions, we use in-context learning, meaning we provide explanations of the DSL as part of the system prompt, alongside workspace maps.Project Configuration: For project configuration questions, we use autonomous context requesting.In all other cases, we don’t want the assistant to give any real response to avoid hallucinations and inappropriate responses.Routing to the Appropriate Context Augmentation StrategyIn more complex AI tool integrations, different user requests may require different context retrieval strategies, as the ones mentioned in our example robot engineering tool above. A common approach is to use a language model to classify the user request and route it to the specific context retrieval strategy. While this approach adds a round-trip and thus extends the response time, we can mitigate this by relying on a less capable and cheaper language model to save on cost and response time. For very narrow use cases, it might even suffice to obtain the embedding as a semantic representation of the user question and classify it by comparing the embedding to the embeddings of prepared example questions for each category.To route user requests to the appropriate context augmentation strategy in our example, we can use the following classification prompt:InstructionsYou are responsible for classifying user requests in a chat for a robot engineering tool. Each project in this tool includes:Configuration File: Specifies the project’s name, purpose, target runtime, entry program, and imported libraries.Hardware Component Model: Describes the building blocks of the robot, such as sensors, actuators, and communication modules. Only components from a predefined catalog can be used.Program Files: Define the robot’s behavior using a rule-based domain-specific language (event-condition-action) and functions for evaluating conditions and executing actions.Classify incoming questions into one of the following categories:hardware-components-catalog: Questions about available hardware components, their purposes, capabilities, specifications, etc.code: Questions about the project’s code, including programs, functions, events, and conditions.project-configuration: Questions about configuring a project, including its name, description, target runtime, and imported libraries.other: Any other questions that do not fit into the categories above.Your response must follow this format:{ "category": "<category-name>" } User Request{{userRequest}}Next, we feed this prompt with the actual userRequest to an LLM, for instance ChatGPT 3.5 Turbo.const prompt = fillPrompt(classificationPrompt, { userInput }); const messages = [{ role: "system", content: prompt }]; const response = await openai.chat.completions.create({ model: "gpt-3.5-turbo", messages, }); const result = response.choices[0].message.content || ""; const category = JSON.parse(result).category; if (category === "hardware-components-catalog") { … } Now, let’s see what answer we get for different questions.Which hardware could I use to navigate through rooms in the dark? –> hardware-components-catalogI need an additional camera module, which ones could I use? –> hardware-components-catalogHow can I convert an int into millimeters? –> codeWhich actions are called on event obstacle_detected? –> codeWhat is this project about? –> project-configurationWhat libraries can I add? –> project-configurationAre robots eval and plan to take over the world? –> otherGreat, so let’s explore how we can actually answer the user questions above with distinct strategies, now as we have classified those questions.Use Case 1: Hardware Components Catalog with RAGFor questions about hardware components in our example, we use Retrieval Augmented Generation (RAG) to incorporate knowledge from a large hardware component catalog.The process for establishing a RAG pipeline typically starts by scraping relevant content from data sources like PDFs, extracting and converting text into usable data. This text is then divided into chunks, each representing a specific piece of information. For each of those chunks, an embedding is computed, which is a mathematical representation of the semantic meaning of the chunk. These embeddings are then fed into a vector store for later retrieval. If a user request comes in, we compute an embedding for the user request and query the vector store for the most similar chunks to the user request embedding. We then augment the user request with the content of those chunks and feed it into the language model.Typical RAG pipelines differ in terms of their input data (documents, web pages, databases, etc.), chunking strategy, query mechanism, ranking approaches, etc. In many cases, also preprocessing the user request with an LLM can improve results. For instance, the user request can be generalized before computing the embedding to match the most relevant topics.In this blog post, we won’t go into detail about the concrete implementation and just assume that we have a component that can give us relevant content chunks about hardware components from a large catalog for a given user query.Prompt for Hardware Components Catalog QuestionsFor answering questions about hardware components, we’ll use the following prompt with three variables listOfCurrentComponents, contentFromRAG, and userQuestion:InstructionsYou are helping users of a robot engineering tool with their questions on hardware components of their robot project.The following components are already built into the robot:{{listOfCurrentComponents}}For a given user request, write an answer just based on the list of components from below and only mention components really needed for the user request. Describe how these components can be used in the robot, also taking the existing components of the robot into account. Keep your answ