Building AI Dialogue Apps with Web Search and Multimodal Capabilities
This article explores the architecture and engineering considerations for building AI-powered conversational applications that go beyond single-turn Q&A. It covers key capabilities including web search integration, deep reasoning with retrieval, file parsing, webpage link reading, and content safety, along with system design, tool-calling workflows, cost management, and compliance requirements.
Background: From Single-Turn Q&A to Multi-Capability Orchestration
Early conversational applications typically performed a single task: passing user questions to a model and displaying the response. As requirements evolve, applications now need to answer time-sensitive questions, understand uploaded contracts and reports, read webpage links shared by users, and support voice interaction. Each added capability introduces a new set of APIs, billing rules, and risk considerations.
For developers, the challenge is not whether an individual capability can be integrated, but how to combine these capabilities based on scenarios while managing cost, latency, and compliance risks.
Core Capability Breakdown
Web Search
Model training data has a cutoff date, making it unreliable for time-sensitive topics such as news, prices, and policies. Web search supplements model responses with external retrieval results through tool calling. The model determines whether retrieval is needed based on the question, generates search queries, obtains result summaries, and cites sources in its answer.
Implementation notes:
- Retain source URLs and publication dates in search results so users can verify information.
- Limit the number of web pages referenced in a single response to avoid overly long contexts.
- Apply deduplication and relevance filtering to results to reduce noise.
Deep Thinking Combined with Retrieval
For questions requiring multi-step reasoning, models typically decompose the problem, retrieve information for each part, and then synthesize a conclusion. For example, comparing two technical solutions requires finding official documentation for each, reading performance evaluations, and then reaching a conclusion.
These scenarios have noticeably higher latency. We recommend setting dedicated timeout values and maximum retrieval rounds, and displaying intermediate states such as “searching” in the interface to reduce user uncertainty while waiting.
File Parsing
File input generally follows two processing approaches:
- Pure text extraction: Suitable for text-heavy documents, offering low cost and fast speed.
- Mixed-layout parsing: Suitable for documents containing tables, charts, or scanned images, requiring recognition of both layout structure and image content.
Parsed results should be length-controlled before being added to the conversation context. Putting an entire hundred-page report directly into the context is expensive and dilutes key information. A more practical approach is to chunk the document first and retrieve relevant sections based on the question.
Webpage Link Reading
When a user message contains a link, the system can fetch the page content, strip out navigation bars, ads, and other irrelevant elements, and then pass the cleaned content to the model. Key implementation points:
- Only fetch domains explicitly provided by the user or on an allowlist to prevent server-side request forgery.
- Set fetch timeouts and page size limits.
- For dynamically rendered pages, determine whether a headless browser is needed. This significantly increases resource consumption and should be enabled on demand.
Standalone Tool Interfaces
Search, web scraping, OCR, speech recognition, and speech synthesis can also be invoked independently without a model. Standalone calls suit the following scenarios:
- Batch processing historical documents without model inference.
- Replacing only one component of a system, such as upgrading the speech recognition module independently.
- Feeding tool outputs into other models or business rule engines, giving developers full control over orchestration logic.
Content Safety
Applications serving external users need basic risk screening for both input and output. A common approach is to place checks before and after model calls, return a standardized refusal message when risk is detected, and log the incident for manual review.
System Architecture Design
A reusable conversational application generally consists of five layers:
- Access layer: Handles authentication, rate limiting, and session identification.
- Orchestration layer: Determines which tools to enable based on user options and manages multi-round tool calls.
- Tool layer: Encapsulates search, scraping, file parsing, and voice capabilities with unified input/output formats.
- Storage layer: Persists conversation history, file parsing caches, and search result caches.
- Security and audit layer: Performs content moderation and records call traces and costs.
The orchestration layer is the core of the system. It translates tool-call requests from the model into actual service invocations and feeds results back into the context. Orchestration logic should be decoupled from specific service interfaces to facilitate future replacement of underlying implementations.
Tool-Calling Workflow and Example
A request with tool calling typically follows these steps:
- Receive the user message and feature flags.
- Build the available tool list based on the flags.
- Call the model. If the model returns tool-call requests, execute the corresponding tools.
- Append tool results to the context and call the model again.
- Repeat until the model produces a final answer or reaching the maximum number of rounds.
- Run safety screening on the output, return the response, and log usage.
Illustrative code (function and parameter names are for demonstration only; adjust to match your actual interfaces):
MAX_TOOL_ROUNDS = 5def handle_chat(user_message, options, history):tools = build_tool_list(options) # Generate tool list based on feature flagsmessages = history + [{"role": "user", "content": user_message}]for _ in range(MAX_TOOL_ROUNDS):reply = llm_client.chat(messages=messages,tools=tools,thinking=options.get("deep_think", False),)if not reply.tool_calls:breakfor call in reply.tool_calls:result = run_tool(call.name, call.arguments) # Execute toolmessages.append(tool_result_message(call, result))else:return fallback_answer() # Fallback reply after exceeding the round limitif not passes_safety_check(reply.text):return refusal_message()record_usage(reply.usage) # Record model and tool usagereturn reply.text
run_tool must validate arguments before execution, especially URLs. Parameters generated by the model cannot be trusted directly.
Cost and Billing
This type of service typically uses dual billing: models charge by input and output token counts, while tools charge by call count or usage volume. Engineering teams need to establish the following capabilities:
- Record call counts and token consumption by session and feature dimension to identify cost sources.
- Apply short-term caching to search and scraping results so identical questions do not trigger repeated external service calls within the cache validity period.
- Set per-user, per-day call limits to prevent abnormal traffic from causing cost overruns.
- Calibrate cost estimates against actual invoices rather than relying only on theoretical calculations from unit price documentation.
Specific pricing standards are subject to the latest published rates from service providers; this article does not provide specific figures.
Security and Compliance
When serving external users, compliance obligations exist alongside technical solutions. Developers should focus on the following:
- Enable safety checks to screen both input and output for risk.
- Fulfill local regulatory obligations, such as content safety review, model registration or filing, and AI-generated content labeling.
- Document data processing methods and retention periods in the user agreement.
- Set file type and size limits for user uploads, and delete source files according to policy after parsing is complete.
Compliance requirements vary by region and business type. Consult legal counsel before launch.
Pre-Launch Checklist
- Does each capability have dedicated timeout, retry, and fallback policies?
- Is the tool-calling round limit configured?
- Is domain allowlisting enabled for web scraping, with internal network addresses blocked?
- Do file parsing results have length controls and cache expiration policies?
- Does safety screening cover both input and output?
- Are cost monitoring and alerting configured?
- Are logs properly redacted, avoiding recording sensitive user information?
