{"id":14582,"date":"2025-03-10T06:25:47","date_gmt":"2025-03-10T06:25:47","guid":{"rendered":"https:\/\/www.happiestminds.com\/blogs\/?p=14582"},"modified":"2025-03-10T07:03:52","modified_gmt":"2025-03-10T07:03:52","slug":"building-intelligent-ai-applications-a-practical-guide-to-key-components","status":"publish","type":"post","link":"https:\/\/www.happiestminds.com\/blogs\/building-intelligent-ai-applications-a-practical-guide-to-key-components\/","title":{"rendered":"Building Intelligent AI Applications: A Practical Guide to Key Components"},"content":{"rendered":"<div id=\"bsf_rt_marker\"><\/div><h5>What This Blog Is (And isn\u2019t)<\/h5>\n<p>Learning a new technology could be intimidating, especially when exposed to the complexities of the topic early on.<\/p>\n<p>This blog is an attempt to simplify building AI applications while hiding away its complexities. We won\u2019t delve into the inner workings of an LLM but focus on using it to solve real-world problems.<\/p>\n<p>We\u2019ll explore concepts like Retrieval-Augmented Generation (RAG), AI agents, and tools, along with code examples for practical implementation.<\/p>\n<h5>Understanding AI Buzzwords<\/h5>\n<p>Let\u2019s look into the key components &amp; concepts that make AI applications so powerful.<\/p>\n<h5>Large Language Model (LLM)<\/h5>\n<p>Think of an LLM as an application with APIs that can process requests and generate responses in natural language (one that is used by humans).<\/p>\n<p>How does an LLM do it?<\/p>\n<p>When you send a query to an LLM, it constructs a response by predicting one word at a time.<\/p>\n<p>First, the query is split into tokens (for simplification, assume each word is a token).<\/p>\n<p>Then, these tokens are converted to a numerical representation called an embedding.<\/p>\n<p>These embeddings are passed through a series of neural networks to calculate probability scores of all suitable next words (the LLM training data plays a key role in this step).<\/p>\n<p>After this, the most suitable next word is selected.<\/p>\n<p>Then, it takes both the query and the predicted word to generate the following word, continuing this process until a full response is formed.<\/p>\n<p>LLMs are of two main types: <strong>Closed-source<\/strong> and <strong>Open-source<\/strong>.<\/p>\n<ul>\n<li>Closed-source LLMs (such as those from OpenAI and Anthropic) run on the provider\u2019s servers and require API keys for access.<\/li>\n<li>Open-source LLMs can either run locally (<em>refer to the code example section for setup instructions<\/em>) or be accessed through hosted services, often requiring API keys as well.<\/li>\n<\/ul>\n<h5>Prompt<\/h5>\n<p>A prompt is a set of instructions, in plain text, given to an AI system. It acts as a guide, shaping how the AI should respond by providing context, tone, or specific details.<\/p>\n<p>When you send a query to an LLM, your AI application will use the prompt to convert the query into well-crafted instruction that improves the accuracy and relevance of the AI\u2019s reply.<\/p>\n<p>For example:<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"601\">You are an AI assistant that provides helpful responses to user queries.Current conversation:<br \/>\n{history}<br \/>\nHuman: {input}<br \/>\nAI<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Here, the user\u2019s query is replaced by the variable {input}. All previous interactions in the conversation are stored in the variable {history}. This allows the LLM to maintain context, helping the AI generate more relevant and coherent responses.<\/p>\n<h5>LangChain<\/h5>\n<p>LangChain is a framework designed to simplify working with Large Language Models (LLMs) for building AI-powered applications. It helps developers manage prompts, memory, and interactions with different models efficiently.<\/p>\n<p>While LangChain is a popular choice, other frameworks like <strong>LlamaIndex<\/strong> (for data retrieval) and <strong>Haystack<\/strong> (for search-based AI applications) can also be used. However, for our solution, we will be using LangChain due to its flexibility and ease of use.<\/p>\n<p>Key Features of LangChain:<\/p>\n<ul>\n<li>Prompt Management\u200a\u2014\u200aHelps structure and reuse prompts effectively.<\/li>\n<li>Memory\u200a\u2014\u200aMaintains conversation history for contextual responses.<\/li>\n<li>Integrations\u200a\u2014\u200aSupports various LLMs (OpenAI, Anthropic, local models) and data sources.<\/li>\n<li>Agents &amp; Chains\u200a\u2014\u200aEnables complex workflows by combining multiple AI steps.<\/li>\n<\/ul>\n<h5>Retrieval-Augmented Generation (RAG)<\/h5>\n<p>RAG (Retrieval Augmented Generation) is like giving your AI a place to look for information relevant to your input query.<\/p>\n<p>LLMs face many limitations, but a critical one is that they can\u2019t answer questions about data they weren\u2019t trained on\u200a\u2014\u200awhether it\u2019s your company\u2019s private documents, your personal files, or specialized databases. RAG helps overcome this fundamental challenge.<\/p>\n<p>Here\u2019s a simple example: Imagine a talent acquisition team with many resumes that needs to find the best candidates for a job opening.<\/p>\n<p>The solution works in three steps. We will use LangChain\u2019s retrieval chain, which takes 2 inputs \u2014 a history-aware retriever &amp; a document chain and generates a response.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-14583 size-large\" src=\"https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/Building-Intelligent-AI-Applications-02-1024x776.jpg\" alt=\"\" width=\"640\" height=\"485\" srcset=\"https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/Building-Intelligent-AI-Applications-02-1024x776.jpg 1024w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/Building-Intelligent-AI-Applications-02-300x227.jpg 300w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/Building-Intelligent-AI-Applications-02-768x582.jpg 768w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/Building-Intelligent-AI-Applications-02.jpg 1199w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>Step 1\u200a\u2014\u200aConvert resume files into vector store<\/p>\n<p>Use an embedding model to convert each resume into numerical vectors (think of them as unique addresses in a digital library) and store them in a vector database like ChromaDB.<\/p>\n<p>Step 2\u200a\u2014\u200aRetrieve the relevant document<\/p>\n<p>The user query and chat history are combined and passed to an LLM for rephrasing and refinement. This updated query, now enriched with historical context, is then sent to the vector database. The same embedding model that was used to build the database is employed to query the data. The embedding model retrieves documents from the resumes that most closely match the refined user query.<\/p>\n<p>Step 3\u200a\u2014\u200aGenerate final response<\/p>\n<p>The retrieved documents, along with the user query and chat history, are fed into the LLM. The model then generates a response based on the information extracted from the documents returned by the vector database.<\/p>\n<h5>AI Agents &amp; Tools<\/h5>\n<p>The AI application is now capable of tapping into the company\u2019s private knowledge base using RAG. However, it\u2019s time to supercharge its capabilities with intelligent agents that wield specialized tools to perform specific actions.<\/p>\n<p>AI agents are indeed sophisticated, yet traditional software systems built with code that strategically integrate LLMs with a suite of functions\/tools and prompts to respond to user queries.<\/p>\n<p>A function\/tool is nothing but a modular piece of code with a specific purpose, capable of performing actions that the LLM itself cannot do directly. These include calling external APIs, performing computational tasks, accessing databases, crawling websites, etc.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-14584 size-large\" src=\"https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/Building-Intelligent-AI-Applications-01-1024x777.jpg\" alt=\"\" width=\"640\" height=\"486\" srcset=\"https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/Building-Intelligent-AI-Applications-01-1024x777.jpg 1024w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/Building-Intelligent-AI-Applications-01-300x228.jpg 300w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/Building-Intelligent-AI-Applications-01-768x583.jpg 768w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/Building-Intelligent-AI-Applications-01.jpg 1198w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>The AI Agent operates in a continuous cycle of the following steps:<\/p>\n<ul>\n<li><strong>Thought:<\/strong> The LLM determines the next action and its parameters.<\/li>\n<li><strong>Action:<\/strong> The agent executes the selected action by invoking the appropriate function with the given arguments.<\/li>\n<li><strong>Observation:<\/strong> The LLM analyzes the tool\u2019s response and decides whether to repeat the cycle or finalize its response.<\/li>\n<\/ul>\n<p>In many agent frameworks, the rules and guidelines are embedded directly into the system prompt, ensuring that every cycle adheres to a defined logic.<\/p>\n<p>The Langsmith repository contains numerous predefined prompts. Let\u2019s explore a simple ReAct prompt from Langsmith:<\/p>\n<p><a href=\"https:\/\/smith.langchain.com\/hub\/hwchase17\/\">Langsmith repository<\/a><\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"601\">Answer the following questions as best you can. You have access to the following tools:<\/p>\n<p>{tools}<\/p>\n<p>Use the following format:<\/p>\n<p>Question: The input question you must answer<br \/>\nThought: You should always think about what to do<br \/>\nAction: The action to take, should be one of [{tool_names}]<br \/>\nAction Input: The input to the action<br \/>\nObservation: The result of the action<br \/>\n&#8230; (this Thought\/Action\/Action Input\/Observation can repeat N times)<br \/>\nThought: I now know the final answer<br \/>\nFinal Answer: The final answer to the original input question<\/p>\n<p>Begin!<\/p>\n<p>Question: {input}<br \/>\nThought:{agent_scratchpad}<\/p>\n<p>&nbsp;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In this prompt, we define the <strong>{tools}<\/strong> available for the AI and specify a structured approach for processing the users <strong>{input}<\/strong>. The AI follows these steps:<\/p>\n<ul>\n<li><strong>Analyze the query<\/strong>\u200a\u2014\u200aThink about the best way to respond to the <strong>{input}<\/strong>.<\/li>\n<li><strong>Track progress<\/strong>\u200a\u2014\u200aUse <strong>{agent_scratchpad}<\/strong> to record thoughts and actions.<\/li>\n<li><strong>Select an action<\/strong>\u200a\u2014\u200aChoose the appropriate tool by specifying <strong>{tool_name}<\/strong>.<\/li>\n<li><strong>Process and refine<\/strong>\u200a\u2014\u200aObserve the tool\u2019s output, refine the approach if needed, and repeat the steps until the final answer is determined.<\/li>\n<\/ul>\n<p>This structured approach ensures logical reasoning, efficient tool usage, and accurate responses.<\/p>\n<h5>Example Code &amp; Implementation<\/h5>\n<p>The complete code examples for concepts explained in this blog is available on <a href=\"https:\/\/github.com\/tarique-happiestminds\/ai_conversartions\">Github<\/a>. The repository contains three Python AI chat applications that we\u2019ll explore in detail:<\/p>\n<p>To run an LLM locally, refer <a href=\"https:\/\/github.com\/tarique-happiestminds\/ai_conversartions?tab=readme-ov-file#using-llm\">README<\/a>.<\/p>\n<ol>\n<li>Build a chatbot using the Chainlit python package (check out the implementation code <a href=\"https:\/\/github.com\/tarique-happiestminds\/ai_conversartions\/blob\/main\/beginner\/ai_conversation.py\">here<\/a>):<\/li>\n<li>Build the AI application for the talent acquisition team using RAG (discussed earlier). Check out the implementation code <a href=\"https:\/\/github.com\/tarique-happiestminds\/ai_conversartions\/blob\/main\/beginner\/ai_rag_conversation.py\">here<\/a>:<\/li>\n<\/ol>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-14586 size-large\" src=\"https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/rag_conversation_output-1024x305.png\" alt=\"\" width=\"640\" height=\"191\" srcset=\"https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/rag_conversation_output-1024x305.png 1024w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/rag_conversation_output-300x89.png 300w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/rag_conversation_output-768x229.png 768w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/rag_conversation_output-1536x458.png 1536w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/rag_conversation_output.png 1848w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p style=\"text-align: center;\">Figure 2. RAG Application<\/p>\n<ol start=\"3\">\n<li>Build an app with AI Agent &amp; Tools to query about the weather of a city. (check out the implementation code <a href=\"https:\/\/github.com\/tarique-happiestminds\/ai_conversartions\/blob\/main\/beginner\/ai_agent_conversation.py\">here<\/a>):<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-14587 size-large\" src=\"https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/tools_weather_output-1024x535.png\" alt=\"\" width=\"640\" height=\"334\" srcset=\"https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/tools_weather_output-1024x535.png 1024w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/tools_weather_output-300x157.png 300w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/tools_weather_output-768x401.png 768w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/tools_weather_output-1536x802.png 1536w, https:\/\/www.happiestminds.com\/blogs\/wp-content\/uploads\/2025\/03\/tools_weather_output.png 1828w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>Figure 3. AI Agent application<\/p>\n<h5>Summary<\/h5>\n<p>This guide introduces the fundamental building blocks of modern AI applications, focusing on practical implementation rather than theoretical complexities. We explored essential concepts like Large Language Models (LLMs), prompt engineering, and frameworks like LangChain that make AI development more accessible. Through progressive examples\u200a\u2014\u200afrom building a basic chatbot to implementing RAG for intelligent document retrieval, to creating tool-wielding AI agents\u200a\u2014\u200awe have demonstrated how to construct AI solutions that solve real business problems.<\/p>\n<h5>What\u2019s Next?<\/h5>\n<p>Two exciting frontiers to explore are Multi-Agent Systems (MAS) and Agentic AI:<\/p>\n<p>Multi-Agent System (MAS), also known as Multi-Agent Artificial Intelligence (MAAI), involves multiple AI agents working together, each with specialized roles and capabilities. Some compelling use cases include:<\/p>\n<ul>\n<li>A financial fraud detection system where the different agents monitor transactions, analyze patterns, and investigate suspicious activities.<\/li>\n<li>A recruitment guiding system with agents for writing JD, searching for matching candidates and sending job invites.<\/li>\n<li>A supply chain optimization platform where agents manage inventory, coordinate logistics, and predict demand.<\/li>\n<li>A healthcare diagnostic system where agents collaborate on analyzing patient data, medical imaging, and treatment recommendations.<\/li>\n<\/ul>\n<p>Agentic AI systems focus on autonomous decision-making and goal-oriented behaviour. These systems can:<\/p>\n<ul>\n<li>Autonomously research and summarize topics across multiple sources while fact-checking.<\/li>\n<li>Handle complex project management by breaking down tasks, setting milestones, and adapting to changes.<\/li>\n<li>Operate as personal assistants that can schedule meetings, make reservations, and manage communications with minimal human intervention.<\/li>\n<\/ul>\n<p>The code examples provided in this blog serve as the starting point. By combining and extending these foundational patterns, one can build increasingly sophisticated AI applications tailored to their specific needs.<\/p>\n<p>Stay curious, keep experimenting, and remember that effective AI solutions often come from smart composition of simple, well-understood components rather than black-box complexity.<\/p>\n<p>All the best &amp; happy coding!<\/p>\n<div class=\"pld-like-dislike-wrap pld-template-2\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"Like\" data-post-id=\"14582\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-heart\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">9    <\/span>\r\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>What This Blog Is (And isn\u2019t) Learning a new technology could be intimidating, especially when exposed to the complexities of the topic early on. This blog is an attempt to simplify building AI applications while hiding away its complexities. We won\u2019t delve into the inner workings of an LLM but focus on using it to [&hellip;]<\/p>\n","protected":false},"author":267,"featured_media":14588,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1816,526,1818,1817,1815],"tags":[1820,828,1822,1821,1819],"class_list":["post-14582","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai-agents","category-chatbots","category-langchain","category-llm","category-rag","tag-ai-agents","tag-chatbots","tag-langchain","tag-llm","tag-rag"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/posts\/14582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/users\/267"}],"replies":[{"embeddable":true,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/comments?post=14582"}],"version-history":[{"count":6,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/posts\/14582\/revisions"}],"predecessor-version":[{"id":14598,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/posts\/14582\/revisions\/14598"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/media\/14588"}],"wp:attachment":[{"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/media?parent=14582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/categories?post=14582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.happiestminds.com\/blogs\/wp-json\/wp\/v2\/tags?post=14582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}