<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[The Tech Scrapbook]]></title><description><![CDATA[The Tech Scrapbook]]></description><link>https://pratik-bhattarai-dev.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sun, 22 Nov 2026 15:32:26 GMT</lastBuildDate><atom:link href="https://pratik-bhattarai-dev.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Deep Research Isn't a Single Agent: Designing a Multi-Agent Research Architecture]]></title><description><![CDATA[A simple look at how the Searcher, Analyst, and Writer work together inside PersonaFlow]]></description><link>https://pratik-bhattarai-dev.hashnode.dev/deep-research-isn-t-a-single-agent-designing-a-multi-agent-research-architecture</link><guid isPermaLink="true">https://pratik-bhattarai-dev.hashnode.dev/deep-research-isn-t-a-single-agent-designing-a-multi-agent-research-architecture</guid><dc:creator><![CDATA[Pratik Bhattarai]]></dc:creator><pubDate>Wed, 19 Aug 2026 17:08:28 GMT</pubDate><content:encoded><![CDATA[<p>A normal AI conversation follows one shape:</p>
<pre><code class="language-text">Question → Answer
</code></pre>
<p>That works when the model already knows enough. Deep research doesn't. It has to understand the goal, search for information, inspect sources, weigh evidence, spot what's missing, and turn all of that into a usable report:</p>
<pre><code class="language-text">Question → Research → Evidence → Analysis → Synthesis → Answer
</code></pre>
<p>While building the deep-research feature in <strong>PersonaFlow</strong>, I realized this isn't a bigger-prompt problem - it's a system-design problem.</p>
<h2>The pipeline architecture behind deep research</h2>
<p>Strip away the agents for a moment and the architecture looks like this:</p>
<pre><code class="language-text">Research Goal → Planning → Retrieval → Evidence Collection → Analysis → Synthesis → Final Report
</code></pre>
<p>Each stage owns one job:</p>
<ul>
<li><p><strong>Planning</strong> - figure out what the user actually wants to learn</p>
</li>
<li><p><strong>Retrieval</strong> - find candidate sources</p>
</li>
<li><p><strong>Evidence collection</strong> - extract the relevant parts and keep provenance</p>
</li>
<li><p><strong>Analysis</strong> - compare evidence, surface gaps, answer the question</p>
</li>
<li><p><strong>Synthesis</strong> - turn findings into a report</p>
</li>
</ul>
<p>What separates this from a single LLM call is state: the system has to remember what's been searched, what's been found, what's still missing, and what to do next.</p>
<h2>Why the architecture splits into specialized agents</h2>
<p>One agent can search, analyze, and write for a trivial task. Fold every responsibility into one agent for a real research task, though, and it becomes unclear where a failure originated - a bad conclusion could be a bad search, a bad read of the evidence, or a bad summary, and you can't tell which from the outside.</p>
<ul>
<li><p>Search is an exploration problem - generating and refining queries.</p>
</li>
<li><p>Evidence collection is a filtering problem - relevance and source tracking.</p>
</li>
<li><p>Analysis is a reasoning problem - comparison and gap detection.</p>
</li>
<li><p>Writing is a communication problem - structure and clarity.</p>
</li>
</ul>
<p>Splitting these into agents with narrow, well-defined jobs gives each stage a clear owner and a clear failure boundary:</p>
<pre><code class="language-text">Orchestrator
     ↓
Searcher → Analyst → Writer
</code></pre>
<p>The goal isn't agent-count for its own sake - it's separating stages whose success criteria genuinely differ.</p>
<h2>The architecture needs a feedback loop, not just a pipeline</h2>
<p>Real research isn't linear. A first pass returns weak sources, a competitor buries pricing in a subpage, two sources disagree, or analysis itself surfaces a new question. A one-way pipeline can't recover from any of that - the architecture needs a loop back into retrieval:</p>
<pre><code class="language-text">Planning → Retrieval → Evidence → Analysis
                                    ↓
                         Is the evidence enough?
                           ├─ No  → Identify the gap → Search again
                           └─ Yes → Synthesis → Final report
</code></pre>
<p>The critical design detail is that the second pass is <em>targeted</em>. If regional pricing is missing, the system searches for regional pricing - it doesn't rerun the whole research task.</p>
<h2>Agents should hand off structured artifacts, not prose</h2>
<p>Passing a paragraph from one agent to the next is the easy option and the wrong one - sources blur together, details get dropped, and the receiving agent has no reliable way to trace a claim back to its evidence.</p>
<p>Structured handoffs fix this. An evidence item might look like:</p>
<pre><code class="language-json">{
  "sourceUrl": "https://example.com/pricing",
  "topic": "pricing",
  "claim": "The professional plan includes team analytics.",
  "evidence": "Relevant text extracted from the source",
  "publishedAt": "2026-05-10",
  "relevanceScore": 0.91
}
</code></pre>
<p>And the Analyst's output might look like:</p>
<pre><code class="language-json">{
  "finding": "A competitor offers analytics in a lower-priced plan.",
  "businessImpact": "This may weaken our offer for small sales teams.",
  "evidenceIds": ["evidence-12", "evidence-19"],
  "gap": "Regional pricing is still missing",
  "nextAction": "Run a targeted pricing search"
}
</code></pre>
<p>Exact fields are negotiable. The principle isn't: <strong>agents should communicate through structured artifacts, not conversational text.</strong> It's what makes the pipeline validatable, storable, debuggable, and reusable.</p>
<h2>How this maps onto PersonaFlow</h2>
<p>PersonaFlow lets an organization spin up AI personas for different roles, each connected to selected knowledge. Deep research applies the same model to web research: a user picks a research type - competitor analysis, pricing comparison, market conditions, risk - and supplies questions, instructions, focus areas, and a time window.</p>
<p>The resulting flow:</p>
<img src="https://cdn.hashnode.com/uploads/covers/6a848898e65b9a0e2fc7e41d/08118aca-1193-4112-9101-457a9d15b84c.png" alt="" style="display:block;margin:0 auto" />

<p>A manual orchestrator manages every handoff - it's the single place holding context, state, agent tasks, retries, guardrails, and saved results.</p>
<h3>Orchestrator: owns context and control flow</h3>
<p>The orchestrator loads the request, research type, time range, organization details, active persona, and any recent stored research, then decides whether the task needs fresh search or just a gap fill. Context isn't optional here - the same topic can require a different answer depending on persona (sales vs. risk) or organization.</p>
<h3>Searcher: turns intent into targeted retrieval</h3>
<p>The Searcher converts intention into focused queries - around five per task in the current implementation - then works down through the retrieval funnel:</p>
<pre><code class="language-text">User intention → Search queries → Relevant websites
     → Useful subpages → Scrape content → Check relevance
</code></pre>
<p>A homepage isn't enough. Depending on the question, the useful evidence might sit on a pricing page, a docs page, or an announcement. The Searcher inspects candidate subpages, extracts content, checks it against the request, and refines its queries if the evidence comes back weak.</p>
<h3>Analyst: converts evidence into findings and gaps</h3>
<p>The Analyst receives the original request, organization context, time range, and the cleaned evidence with source details. It doesn't summarize page by page - it compares evidence across sources to surface competitor strengths, product gaps, pricing differences, risks, and missing facts. When something important is absent, it emits a focused follow-up request, which the orchestrator routes back to the Searcher.</p>
<h3>Guardrails: validate before synthesis</h3>
<p>Before anything reaches the Writer, the orchestrator checks the analysis against the original request, confirms evidence traces back to the correct task, enforces organization/persona scope, and screens for restricted information. Web content is treated as evidence, never as instructions - and every claim stays tied to its source.</p>
<h3>Writer: synthesizes from approved findings only</h3>
<p>The Writer builds the final report - executive summary, findings, comparisons, gaps, risks, recommendations, sources - strictly from the approved analysis and its evidence references. It doesn't re-search, and if a section is underspecified, it routes a clarification request back to the Analyst via the orchestrator.</p>
<p>The evidence, analysis summary, and final report are all persisted.</p>
<h2>Where Firecrawl and MCP sit in the architecture</h2>
<p>The Searcher calls the <strong>Firecrawl MCP server</strong> for search and page extraction:</p>
<pre><code class="language-text">Searcher Agent → MCP tool call → Firecrawl → Search and page content
</code></pre>
<p>Firecrawl is a tool inside the retrieval layer, not a research agent - the Searcher decides what's needed, Firecrawl performs the external action, and the orchestrator governs when that action is allowed. That separation keeps retrieval swappable: another crawler, a search API, a vector store, or an internal knowledge base could sit behind the same interface.</p>
<h2>Reuse as an architectural concern, not an afterthought</h2>
<p>Web research burns time, tokens, and crawl credits, so PersonaFlow checks stored research before starting fresh:</p>
<pre><code class="language-text">New request → Check stored research
                 ↓
        Is it relevant and recent?
          ├─ Yes    → Reuse it for analysis
          ├─ Partly → Search for missing or outdated details
          └─ No     → Start new research
</code></pre>
<p>A competitor researched a few hours ago can be reused outright; a request that goes beyond what's already known triggers only a gap fill - always scoped to the organization, and never assumed to be permanently accurate.</p>
<h2>Common failure modes and their architectural fix</h2>
<table>
<thead>
<tr>
<th>Failure</th>
<th>Architectural response</th>
</tr>
</thead>
<tbody><tr>
<td>Queries too broad</td>
<td>Generate from goal, focus areas, and time range</td>
</tr>
<tr>
<td>Irrelevant sources</td>
<td>Check relevance before evidence reaches the Analyst</td>
</tr>
<tr>
<td>Duplicated information</td>
<td>Deduplicate URLs and near-identical content</td>
</tr>
<tr>
<td>Conflicting sources</td>
<td>Keep every claim tied to its specific source and date</td>
</tr>
<tr>
<td>Weak-support claims</td>
<td>Log the gap, trigger a targeted search</td>
</tr>
<tr>
<td>Context overflow</td>
<td>Pass selected evidence records, not full pages</td>
</tr>
<tr>
<td>Repeated agent work</td>
<td>Reuse recent evidence, track completed tasks</td>
</tr>
<tr>
<td>Unsupported writing</td>
<td>Constrain the Writer to approved findings only</td>
</tr>
<tr>
<td>Data crossing boundaries</td>
<td>Enforce org/persona scope across retrieval, storage, and output</td>
</tr>
</tbody></table>
<p>The point isn't eliminating failure - it's giving every failure mode a visible, traceable place in the architecture.</p>
<h2>Final thoughts</h2>
<p>A typical LLM app looks like:</p>
<pre><code class="language-text">Prompt → LLM → Response
</code></pre>
<p>A deep-research system looks like:</p>
<pre><code class="language-text">Research goal → Plan → Search → Retrieve → Extract evidence
     → Validate → Analyze → Identify gaps → Search again if needed
     → Synthesize → Report
</code></pre>
<p>In PersonaFlow, the Searcher gathers, the Analyst interprets, and the Writer communicates - while the orchestrator holds context, state, guardrails, tools, and every handoff between them.</p>
<p>The lesson from building this: a multi-agent system isn't just several prompts wired together with arrows. The hard part is deciding what each agent knows, what it returns, when to search again, how claims stay tethered to evidence, and how the orchestrator recognizes the work is actually done.</p>
]]></content:encoded></item><item><title><![CDATA[What I Learned Building an AI Persona and Deep Research Platform]]></title><description><![CDATA[A practical project that helped me understand RAG, AI agents, prompt engineering, tool use, and data security]]></description><link>https://pratik-bhattarai-dev.hashnode.dev/what-i-learned-building-an-ai-persona-and-deep-research-platform</link><guid isPermaLink="true">https://pratik-bhattarai-dev.hashnode.dev/what-i-learned-building-an-ai-persona-and-deep-research-platform</guid><dc:creator><![CDATA[Pratik Bhattarai]]></dc:creator><pubDate>Wed, 19 Aug 2026 08:10:11 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a848898e65b9a0e2fc7e41d/026afc6f-98be-4b67-aa6f-6d1bcff553fc.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Like many developers learning AI, I first started by sending a prompt to an LLM and showing its response on a screen. It was exciting, but it was still only a chatbot.</p>
<p>I wanted to understand what happens when we build an AI system for a real organization. How can different teams use the same platform but have different AI assistants? How can the AI answer from company documents? How does it decide when to search the web? And how can multiple AI agents work together on a larger task?</p>
<p>To learn these things, I built an AI persona and knowledge-assistant platform. I also added a deep-research feature that uses three agents to collect information, analyze it, and prepare a report.</p>
<p>I built this project mainly to improve my own skills, but I believe it can also be a useful project idea for students and developers who want to learn how real AI applications are designed.</p>
<hr />
<h2>The idea behind the project</h2>
<p>Most organizations have different departments such as sales, marketing, customer support, HR, and finance. Every department has a different job and uses different information.</p>
<p>But when employees use a general AI tool, they often need to explain the role again and again:</p>
<blockquote>
<p>“Act as a sales expert.”</p>
</blockquote>
<blockquote>
<p>“Answer like a customer-support employee.”</p>
</blockquote>
<p>The AI also does not automatically know the organization’s products, policies, reports, or working process.</p>
<p>My idea was to create one platform where an organization can create different AI personas. A persona can have a name, description, role, and allowed features. It can also be connected to selected knowledge bases.</p>
<p>For example, a customer-support persona can use product guides and troubleshooting documents. A marketing persona can use campaign reports and brand information. Both assistants use the same platform, but they work with different roles and knowledge.</p>
<p>The simple idea is:</p>
<blockquote>
<p>The persona tells the AI how it should behave. The knowledge base gives it the information it can use.</p>
</blockquote>
<hr />
<h2>How the platform works</h2>
<p>The project backend is built with NestJS. PostgreSQL stores users, organizations, personas, knowledge bases, conversations, and research jobs. Cloudinary stores uploaded files. Jina creates embeddings, Pinecone stores vectors, Groq provides the language models, and Firecrawl handles web search and scraping.</p>
<p>The main flow is simple:</p>
<ol>
<li><p>A user registers an organization.</p>
</li>
<li><p>The user creates an AI persona.</p>
</li>
<li><p>The user creates a knowledge base and uploads documents.</p>
</li>
<li><p>The knowledge base is assigned to the persona.</p>
</li>
<li><p>The user starts a conversation with that persona.</p>
</li>
<li><p>The system finds useful information and prepares an answer.</p>
</li>
</ol>
<p>This sounds simple from the user’s side, but several things happen in the background.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6a848898e65b9a0e2fc7e41d/206041f9-82dc-4f6c-8cae-6b5c5adc98d4.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2>Turning documents into knowledge</h2>
<p>An LLM cannot directly use a large collection of files in every conversation. The documents first need to be processed.</p>
<p>When a user uploads a PDF, Word document, or text file, the platform:</p>
<ol>
<li><p>Validates and stores the file.</p>
</li>
<li><p>Extracts the text.</p>
</li>
<li><p>Cleans the extracted content.</p>
</li>
<li><p>Splits the text into smaller chunks.</p>
</li>
<li><p>Creates an embedding for each chunk.</p>
</li>
<li><p>Stores those embeddings in Pinecone.</p>
</li>
</ol>
<p>An embedding is a numerical form of text. It allows the system to search by meaning instead of matching only exact words.</p>
<p>For example, a user may ask, “How can I reset a blocked account?” The uploaded document may use the words “restore access to a locked profile.” A normal keyword search might miss the connection, but semantic search can still find the related section.</p>
<p>This process is called Retrieval-Augmented Generation, or RAG.</p>
<p>When the user asks a question, the system searches the vector database, finds the most relevant chunks, and gives them to the LLM as context. The LLM then answers using that information.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6a848898e65b9a0e2fc7e41d/93d8ca9d-21c8-46b3-ae8b-f3301c37c032.jpg" alt="" style="display:block;margin:0 auto" />

<hr />
<h2>Prompt engineering is more than writing one prompt</h2>
<p>One important thing I learned is that prompt engineering is not only about writing a clever instruction.</p>
<p>The system needs to combine several pieces of context:</p>
<ul>
<li><p>The platform rules</p>
</li>
<li><p>The persona’s role and description</p>
</li>
<li><p>Recent conversation messages</p>
</li>
<li><p>Relevant knowledge-base content</p>
</li>
<li><p>Web information, if needed</p>
</li>
<li><p>Organization information</p>
</li>
<li><p>The current user question</p>
</li>
</ul>
<p>These parts should be clearly separated. If we put everything into one large block without structure, the model may not understand which information is most important.</p>
<p>The amount of context also needs to be controlled. Sending every document and every old message would make the request slow, expensive, and confusing. The system selects only the most useful information before calling the model.</p>
<p>This changed how I think about prompts. In a real AI project, prompt engineering is really about managing context properly.</p>
<hr />
<h2>Deciding when to use knowledge or the web</h2>
<p>Not every question needs the same data.</p>
<p>If the user says “Hello,” the system does not need to search anything. If the user asks about an uploaded company policy, it should search the knowledge base. If the question is about recent market changes, it may need the web.</p>
<p>I added a query-router agent to make this decision. It checks the user’s intention and chooses whether the request needs:</p>
<ul>
<li><p>A direct answer</p>
</li>
<li><p>Knowledge-base search</p>
</li>
<li><p>Web search</p>
</li>
<li><p>Both knowledge-base and web search</p>
</li>
</ul>
<p>The model helps classify the question, but the application still controls permissions. For example, the system only uses web search if that persona is allowed to use it.</p>
<p>This is important because an AI model can suggest an action, but the application should decide whether that action is allowed.</p>
<hr />
<h2>The deep-research system</h2>
<p>The most interesting feature for me is the deep-research system.</p>
<p>A normal chatbot usually gives one response. Research is different. It needs several searches, many web pages, comparison, analysis, and a well-organized final report.</p>
<p>For this workflow, I used three agents:</p>
<h3>1. Searcher Agent</h3>
<p>The Searcher understands the research question and creates several focused search queries. It uses Firecrawl to search the web and scrape useful pages.</p>
<p>It does not only collect the first search results. It can also look for useful pages inside a website, such as pricing, features, company information, support, or API pages.</p>
<p>Its main job is to collect and organize evidence. It does not write the final report.</p>
<h3>2. Analyst Agent</h3>
<p>The Analyst receives the information collected by the Searcher. It compares competitors and looks for strengths, weaknesses, features, pricing models, market gaps, risks, and possible opportunities.</p>
<p>Instead of passing one long paragraph to the next agent, the Analyst produces structured data. This makes the output easier to save and easier for the Writer to understand.</p>
<h3>3. Writer Agent</h3>
<p>The Writer receives the structured analysis and turns it into a clear Markdown report. It prepares sections such as the executive summary, key findings, competitor profiles, gaps, and recommendations.</p>
<p>The Writer’s job is presentation. It should explain the analysis clearly without doing a completely new research task.</p>
<p>The complete flow is:</p>
<p><strong>User request → Searcher → Analyst → Writer → Final report</strong></p>
<p>This is only a brief overview of the workflow. If you want to understand the complete architecture—including orchestration, research loops, structured agent communication, guardrails, failure handling, and scaling—I have explained it in a separate article:</p>
<p><a href="https://pratik-bhattarai-dev.hashnode.dev/deep-research-isn-t-a-single-agent-designing-a-multi-agent-research-architecture">👉 Deep Research Isn’t a Single Agent: Designing a Multi-Agent Research Architecture</a></p>
<hr />
<h2>Why I used a manual orchestrator</h2>
<p>The agents do not randomly call each other. A service in the application works as the orchestrator.</p>
<p>It creates the research job, starts each agent in the correct order, passes the output from one agent to the next, stores the progress, and marks the job as completed or failed.</p>
<p>I could have started with an agent framework, but building the flow manually helped me understand what an orchestrator actually does.</p>
<p>I learned how to manage:</p>
<ul>
<li><p>The state of the research job</p>
</li>
<li><p>The input and output of each agent</p>
</li>
<li><p>The order in which agents run</p>
</li>
<li><p>The context passed between agents</p>
</li>
<li><p>Errors and failed stages</p>
</li>
<li><p>The final result</p>
</li>
</ul>
<p>After understanding this flow, frameworks such as LangGraph become easier to understand because I know what they are managing behind the scenes.</p>
<hr />
<h2>A simple research example</h2>
<p>Imagine a digital-wallet company wants to study NFC payments in Nepal.</p>
<p>The user can ask the system to research competitors, market demand, regulations, customer benefits, possible risks, and product opportunities.</p>
<p>The Searcher creates different web queries and collects useful pages. The Analyst compares the information and finds patterns or gaps. The Writer then creates a structured report that the business team can read.</p>
<p>The main benefit is not that AI magically knows the answer. The benefit is that the system divides a large task into smaller jobs and gives each job to the right agent.</p>
<hr />
<h2>Keeping organization data separate</h2>
<p>Data security is very important in this type of platform.</p>
<p>One organization should never access another organization’s documents. Also, one persona should not use a knowledge base that was not assigned to it.</p>
<p>The project handles this at different levels:</p>
<ul>
<li><p>Database queries include the organization ID.</p>
</li>
<li><p>Personas and knowledge bases are checked before they are connected.</p>
</li>
<li><p>Each organization uses a separate Pinecone namespace.</p>
</li>
<li><p>Vector searches include organization and knowledge-base filters.</p>
</li>
<li><p>Conversations and research jobs are checked against the current user and organization.</p>
</li>
</ul>
<p>This taught me that data separation cannot depend on a prompt. It must be controlled by the backend and database.</p>
<hr />
<h2>Reducing hallucinations</h2>
<p>RAG does not completely remove hallucinations, but it can reduce them.</p>
<p>The system gives the model relevant source content instead of asking it to answer only from memory. It keeps filenames and source information with the retrieved text. It also asks the model to say when the available information does not contain an answer.</p>
<p>For knowledge-base conversations, another model call reviews the first answer and checks whether company-specific claims are supported by the retrieved documents.</p>
<p>The system also treats scraped website content as data, not as trusted instructions. This is important because a website or uploaded document may contain text that tries to change how the AI behaves.</p>
<p>Even with these steps, important answers and business recommendations should still be checked by a human.</p>
<hr />
<h2>What I learned from this project</h2>
<p>This project helped me understand that building an AI system is not only about choosing an LLM.</p>
<p>The real work includes:</p>
<ul>
<li><p>Preparing and managing data</p>
</li>
<li><p>Creating useful embeddings</p>
</li>
<li><p>Retrieving the correct context</p>
</li>
<li><p>Building clear prompts</p>
</li>
<li><p>Controlling tool access</p>
</li>
<li><p>Passing data between agents</p>
</li>
<li><p>Keeping organization data separate</p>
</li>
<li><p>Handling failures</p>
</li>
<li><p>Reducing unsupported answers</p>
</li>
</ul>
<p>I also learned that “multi-agent” does not always mean that agents must work in parallel or have full freedom. In this project, the agents work one after another, and the application controls the complete flow. That makes the system easier to understand and manage.</p>
<p>For students who want to learn AI development, I think this is a useful type of project because it combines backend development, databases, RAG, vector search, prompt engineering, web tools, multi-agent systems, and security in one place.</p>
<hr />
<h2>Final thoughts</h2>
<p>I started this project to improve my own skills and understand how modern AI systems work behind the scenes.</p>
<p>The biggest lesson for me was simple: the LLM response is only the final part. Before that response, the system has to find the right data, check permissions, build the context, choose tools, manage agents, and store the result.</p>
<p>That is what makes an AI project more than a chatbot.</p>
<p>I am still learning and improving the platform, but building it gave me a much clearer understanding of RAG and multi-agent architecture. I hope sharing this overview also helps other students and developers who want to build practical AI projects.</p>
]]></content:encoded></item></channel></rss>