Implement a RAG Assistant with LangChain Tools, Agents, and Chat History
coding a general-purpose LLM CodingProductivity
<role> You are a senior software engineer specializing in [programming language], LangChain, retrieval-augmented generation, AI agents, and conversational applications. </role> <context> Implement the feature in [project directory] using [LangChain version]. The application should use [LLM provider], [embedding model], [vector database], [document sources], and [chat history storage]. Expose the assistant through [application interface]. Follow the architecture, dependency management, formatting, and testing conventions described in [project instructions or existing codebase]. </context> <instructions> Implement a complete conversational RAG assistant that: 1. Loads documents from [document sources], splits them using [chunking strategy], creates embeddings, and stores searchable vectors in [vector database]. 2. Retrieves relevant context for each user message and supplies that context to the LangChain model through [RAG architecture]. 3. Defines and registers the required tools listed in [tool list], with clear descriptions, typed schemas, validated inputs, and reliable error handling. 4. Uses a LangChain agent to choose among document retrieval, registered tools, and direct model responses. 5. Persists messages, tool activity, retrieval context, and agent responses for each [session identifier] using [chat history storage]. 6. Sends only the conversation history relevant to the current request within the configured [context window or token limit]. 7. Exposes the assistant through [application interface] and supports [streaming or non-streaming responses]. 8. Adds focused tests for retrieval, tool invocation, agent routing, chat-history continuity, session isolation, and representative failure scenarios. 9. Documents setup, required environment variables, indexing steps, execution commands, and example usage in [documentation file]. 10. Integrate the implementation with the existing project structure whenever applicable and provide clear configuration points for models, prompts, tools, retrieval settings, and storage. </instructions> <constraints> Use [LangChain version] APIs and the project’s supported package versions. Load credentials and connection details from [environment variable convention]. Validate document ingestion, retrieval parameters, session identifiers, and tool arguments. Restrict tool execution to explicitly registered tools. Preserve existing functionality, apply secure coding practices, and keep secrets out of source control. Make external services replaceable through configuration and provide understandable errors when models, vector stores, tools, or history storage are unavailable. </constraints> <format> Return production-quality code and configuration changes, followed by setup instructions, test results, and a concise summary of the implemented components. Include file-by-file explanations when the response format is [output format]. </format> <tone> Use clear, precise, implementation-focused language and explain technical decisions at the level of detail requested in [explanation depth]. </tone> Final action: Complete the RAG and agent integration in [project directory], verify it with the available tests, and present the finished implementation with concise run instructions.
#text