Building an AI Assistant into a County-Level Media Client: A Technical Practice Guide
This article walks through the technical practice of adding an AI assistant to a county-level media client, covering the problem framing, a five-layer architecture, RAG engineering details, multi-turn dialogue and tool calling, performance and cost control, security and compliance, metrics, and a phased rollout plan. It shows how to make local, time-sensitive, policy-heavy answers traceable and auditable while keeping the assistant focused on intent recognition, material pre-checks, and guidance rather than replacing existing business systems.
1. Background and Problem Definition
A county-level media client completed its AI assistant integration in March 2025. By that point, the client had already merged four capability areas: news, government affairs, daily-life services, and business information, making it one of the main information entry points for local residents. Operating data from that year showed roughly 55,000 cumulative installs with more than 7,000 new installs added annually, positioning the client as an important channel between the government and the public. The annual report also noted room for improvement in the depth of government services, the coverage of daily-life services, and the user interaction experience.
Translated into engineering terms, these conclusions point to three measurable goals:
- Availability: services must stay online 24/7, avoiding the time-slot limits of human agents.
- Answerability: questions that are local, time-sensitive, and policy-heavy should get clear answers rather than vague fallbacks.
- Governability: answers must be traceable, constrained, and auditable to meet compliance requirements in government scenarios.
It is worth stressing that the assistant solves an entry-efficiency problem; it does not replace business systems. Actual transactions, payments, and appointments should still be handled by existing business systems, while the assistant takes on intent recognition, material pre-checks, path guidance, and status queries.
2. Layered Overall Architecture
A solution that can evolve sustainably is typically split into five layers, with clear contracts decoupling each layer from the next:
- Access layer: a fixed entry point on the client home page (for example, a persistent Q&A button), supporting text input, voice input, and quick cards for common questions.
- Session layer: manages multi-turn context, session timeouts, and secondary confirmation for sensitive operations.
- Orchestration layer: intent routing, tool-call orchestration, retrieval strategy selection, and fallback policies.
- Knowledge and tool layer: a policy document repository, a service-guide repository, a travel and culture information repository, and wrappers around query interfaces.
- Governance layer: content safety filtering, log auditing, metrics monitoring, and canary releases.
The orchestration layer is where complexity concentrates. The recommended strategy is “intent first, retrieval as fallback” rather than handing every question to the large model for free-form generation.
3. Key Engineering Details of Retrieval-Augmented Generation
The biggest risk in government Q&A is an answer that “looks like the right one.” The core technique for suppressing hallucination is retrieval-augmented generation (RAG), with the following engineering points:
- Chunking strategy: split by heading hierarchy and clause numbering, keeping “one policy clause per chunk” to avoid cross-clause semantic contamination.
- Metadata design: attach fields such as issuing agency, effective date, applicable scope, and expiry date to each chunk for filtering and citation.
- Hybrid retrieval: keyword retrieval handles exact matches on proper nouns and reference numbers, vector retrieval handles semantic recall of colloquial phrasing, and the two result sets are fused and then reranked.
- Time filtering: policy questions are forcibly filtered by effective date, so expired documents never enter the context.
- Citation constraints: the model must include the source identifier of each chunk in its answer; when there is no retrieval hit, it must explicitly reply that no basis was found and hand off to a human or provide a service channel.
Illustrative retrieval and prompt-constraint logic (pseudocode):
def answer(query, user_ctx):intent = route_intent(query) # service/policy/travel/complaint/chitchatif intent == "service":return guide_flow(intent, user_ctx) # structured service guidancehits = hybrid_search(query, top_k=8)hits = filter_by_effective_date(hits, today())if not hits:return fallback_reply() # explicitly no basis; hand off to a humanprompt = build_prompt(query, hits, allow_source=True)resp = llm.generate(prompt, temperature=0.1)return guardrail(resp, hits) # safety filtering + citation validation
Combining a low temperature value, mandatory citation validation, and a fallback whenever there is no hit significantly reduces the probability of fabricated clauses.
4. Multi-Turn Dialogue and Tool Calling
Real user questions are often incomplete, such as “where should I go in spring” or “what materials do I need to bring.” The session layer needs to maintain slots and fill missing information with a single follow-up question rather than repeated back-and-forth:
{"session_id": "s-20250318-0001","intent": "travel_recommend","slots": {"season": "spring", "party": null, "duration": null},"turn": 2,"pending_confirm": false}
Tool calling follows the principle of least privilege: query tools are open by default, queries involving personal information must be bound to an authenticated identity, and write operations are never executed directly but only output as steps and entry-point guidance. All tool results must pass structural validation, degrading to a “guided answer” when fields are missing.
5. Performance, Cost, and Stability
The cost of intelligent Q&A comes mainly from three parts: retrieval, model inference, and log storage. Common optimizations include:
- Caching results for high-frequency questions, with an invalidation policy tied to policy updates;
- Using a small-parameter model for chitchat and simple intents, escalating complex questions to a larger model;
- Truncating and reranking retrieval results to control context length;
- Sampling logs and monitoring metrics in tiers, archiving raw dialogue text after masking as required by compliance.
For stability, introduce a circuit breaker and a degradation chain: when the model service is unavailable, fall back to pure retrieval Q&A; when retrieval is unavailable, fall back to common questions and a human entry point. Availability targets should be written into the service level agreement and continuously verified through monitoring and alerting.
6. Security, Compliance, and Content Governance
Government scenarios need a “double safeguard”: identity and permission checks on the input side, and content safety review on the output side. Key points include blocking sensitive words and non-compliant content, minimizing personal information collection, defining a clear retention period for conversations, and keeping the full chain auditable. The release cadence should be canary-based: open to a small share of users first, watch the no-basis answer rate and the human handoff rate, then gradually ramp up.
7. Measuring Results and the Iteration Loop
Build four categories of metrics to avoid vanity metrics like “call volume”:
| Dimension | Example metrics |
|---|---|
| Quality | First-answer resolution rate, no-basis answer rate, citation hit rate |
| Experience | Average turns, follow-up rate, session abandonment rate |
| Coverage | Government service coverage, number of daily-life items covered |
| Cost | Average cost per session, cache hit rate |
The iteration loop depends on badcase attribution: classify no-basis answers as “missing knowledge / poor chunking / intent misjudgment / ambiguous phrasing,” driving knowledge backfill, chunking restructuring, intent sample augmentation, and prompt optimization respectively. This loop is the engineering path to the “coverage and interaction experience improvement” the annual report pointed to.
8. Recommended Rollout Cadence
Phase one connects the entry point and common questions and establishes the knowledge and audit foundation; phase two adds service guidance and identity-bound queries; phase three builds multi-turn complex task orchestration and personalized recommendations. The overall approach can lean on general cloud capabilities: object storage for documents, a message queue for peak shaving, a container platform for inference services, and log and monitoring services for observability, so the team can focus its energy on knowledge and orchestration, the two areas that truly determine results.
