Who Executes Web Access and File Reading in LLM Applications: A Practical Architecture Guide
This article explains a common point of confusion in retrieval-augmented generation (RAG) development: whether the model itself browses the web or parses files. It clarifies that the model only handles reasoning and generation, while the execution layer performs web fetching, file reading, parsing, chunking, and retrieval. It compares two integration paths—in-conversation server-side tools and standalone retrieval/fetching APIs—outlines their trade-offs, provides a four-question selection checklist, and covers prompt design, cost, security, observability, and common pitfalls.
1. The Core Issue: Capability Ownership Defines Engineering Boundaries
When building retrieval-augmented generation (RAG) applications, developers often confuse two questions: “Can the model access the internet?” and “Who parses the file?” Separating them makes the answer clear. The model is responsible only for reasoning and generation. Any action that interacts with the external world must be handled by the side running it. In other words, fetching web pages, reading local or cloud files, parsing formats, and splitting text are all execution-layer tasks, not reasoning-layer capabilities.
The API documentation of a cloud provider typically divides entry points into two categories. In the first, the model decides during a conversation whether external information is needed, and tools provided on the server side perform retrieval within a controlled scope and feed the results back to the model. In the second, retrieval and fetching are exposed as standalone capabilities that the application invokes proactively, choosing the query terms and processing the results itself. Understanding this boundary is the first step in sound architecture design.
2. Responsibility Split Between the Two Entry Points
1. In-Conversation Server-Side Tools: Model Decides, Platform Executes
In this mode, the application passes only the user’s question to the model. During reasoning, the model determines that it needs external information, and a platform-side tool performs the retrieval and returns the results as context so the model can continue generating. The advantages are low integration cost and natural interaction, making it suitable for open-ended Q&A, time-sensitive topics, and conversational exploration.
The limitations are equally clear. The model rewrites the query, so the application cannot intervene precisely. The retrieval scope and number of results are constrained by platform policies. The returned content has usually already been digested by the model, so the application cannot access raw snippets for secondary citation or auditing.
2. Standalone Retrieval and Fetching APIs: Application Decides, Application Executes
In this mode, retrieval and fetching are explicit steps. The application first generates or rewrites the query, calls the retrieval capability to obtain candidate links and summaries, then fetches the full text as needed, cleans it, splits it, and stores it. Finally, it assembles the selected snippets into the prompt. The value lies in full-pipeline control: query terms can be enumerated, results can be cached, snippets can be annotated with their sources, and failures can be retried.
The cost is a longer pipeline. The application must maintain its own retrieval strategy, deduplication rules, content cleaning, and quota management. For enterprise applications with strict compliance requirements, citation traceability needs, or the need to precisely control context length and cost, this path is almost mandatory.
3. Selection Checklist
Four questions can quickly settle the decision:
- Do you need citation traceability and per-item auditing? If yes, choose the standalone API.
- Do you need a fixed set of sources or an allowlist/blocklist? If yes, choose the standalone API.
- Is it open-ended conversational Q&A with low controllability requirements? The in-conversation tool is sufficient.
- Do you need to reuse existing retrieval assets (self-built indexes, vector databases, documents in object storage)? The standalone API is the more natural fit.
A common compromise in practice is a dual-track approach: use the in-conversation tool by default to preserve the user experience, and switch to the standalone pipeline when a request requires citations, fixed sources, or long-document parsing.
4. Who Actually Reads the File
File reading is never the model’s job. A sensible division of labor is that the application fetches the file, parses the format, cleans and splits the content, and generates vector and keyword indexes, while the model only consumes already-structured text snippets. Illustrative code:
def build_context(file_obj, query, top_k=5):raw = extract_text(file_obj) # Application-side parsingchunks = split(raw, size=800, overlap=80)hits = index.search(query, top_k=top_k) # Application-side retrievalreturn "\n\n".join(f"[{i}] {h.text}" for i, h in enumerate(hits))
The direct benefits are that parsing failures can be localized, chunking strategies can be tuned, snippets can be annotated with their sources, and sensitive content can be redacted before ingestion.
5. Prompt and Retrieval Pipeline Design Patterns
Regardless of which entry point you use, the prompt should explicitly enforce three things: answer only based on the given snippets, state clearly when the snippets are insufficient, and tag each conclusion with the snippet number. On the retrieval side, a standard pipeline of query rewriting, multi-route recall, reranking, and truncation is recommended. Deduplicate by the same link and the same title, and strip template and advertising sections from the body text.
6. Cost, Security, and Observability
For cost, the standalone pipeline can reduce spending by caching hot queries, limiting the number of fetched items, and truncating context according to a token budget. For security, fetched results must be treated as untrusted input, with prompt-injection filtering and permission checks applied, and file access following the principle of least privilege. For observability, it is advisable to instrument query terms, recall counts, matched snippets, latency, and failure reasons, and connect them to logging services and monitoring alerts for traceability and tuning.
7. Common Pitfalls
The first is assuming that “the model can access the internet” means the application no longer needs to manage retrieval. The second is pasting fetched web pages directly into the prompt while ignoring cleaning and injection risks. The third is routing every request through the in-conversation tool, which makes auditing and reproduction impossible. The fourth is neglecting quotas and concurrency, causing the pipeline to collapse under peak load.
