Building a Chatbot with Coding AI Agents: Low-Cost Setup and Memory System Design

    This article explains how to build a maintainable chatbot by using a coding AI agent as an installation and operations proxy. It covers the limitations of calling model APIs directly, a control plane and data plane architecture, step-by-step deployment and upgrades, stable user identification, layered memory and affinity design, voice and multimodal boundaries, permission governance, prompt engineering, and cost, stability, and compliance considerations.

    1. Why Calling a Model API Directly Is Not the Best Approach

    In chatbot projects, the most common approach is to connect a business application directly to a large language model API: a user message arrives, a prompt is assembled, the API is called, and the result is sent back to the chat platform. This flow looks simple, but in high-frequency group chat scenarios, it quickly exposes three problems.

    The first is unpredictable cost. In conversational scenarios, a single request often includes a system prompt, message history, role settings, and tool descriptions, so token consumption is much higher than for ordinary question answering. Once the bot enters high-frequency chat, costs can grow linearly or even faster, and price fluctuations during peak hours can further amplify uncertainty.

    The second is messy identity and context management. Many early implementations use a nickname as the user key, so historical records break as soon as a user changes their name. When group chat and private chat share the same memory file, context can also bleed between them.

    The third is difficulty extending capabilities. When you need to add voice, image understanding, permission control, or other features, piling code directly into the business layer quickly corrupts the main flow, increases debugging costs, and makes rollbacks difficult.

    Using a coding AI agent—a development agent with code understanding, file reading and writing, command execution, and step-by-step planning capabilities—as an installation and operations proxy, and running the bot itself within a versionable project structure, is an effective way to mitigate these problems.

    2. Overall Architecture: Separating the Control Plane and Data Plane

    It is recommended to split the system into two planes to avoid mixing responsibilities.

    • Control plane (installation/upgrade sessions): responsible for environment detection, dependency installation, configuration generation, code modification, and upgrades. It has higher privileges but is used only for deployment and changes.
    • Data plane (chat sessions): retains only the on-duty prompt and necessary rule descriptions and handles daily conversation. It should not debug, modify code, or install dependencies.

    This separation brings two direct benefits: first, the chat context stays lean, reducing wasted tokens; second, changes are auditable and rollback-friendly, avoiding the situation where a live system is broken through casual conversation.

    A sample directory layout could look like this:

    1. project/
    2. ├── bridge/ # Integration layer: platform adapters, message sending/receiving, routing
    3. │ ├── README.md # Deployment and running instructions (read by the control plane)
    4. │ └── upgrade.md # Upgrade step instructions
    5. ├── memory/ # Memory layer: user profiles, affinity, conversation summaries
    6. │ ├── impression/ # Profile files keyed by stable user IDs
    7. │ └── summary/ # Periodic group chat summaries
    8. ├── config/ # Model, voice, permission, and other configurations
    9. └── logs/ # Runtime and audit logs

    3. Deployment: Let the Agent Complete Installation Step by Step

    It is recommended to hand the deployment process to a control plane session and proceed by “reading instructions, analyzing the environment, and executing step by step,” rather than manually typing commands one by one.

    1. Select the project root directory in the workspace, choose a coding mode, and select a faster-responding model tier. The strongest reasoning capability is not required during deployment.
    2. Provide the root directory instruction file to the session and have it read the integration layer documentation before starting work.
    3. The control plane first detects the runtime environment (runtime version, package manager, network, and port usage) and suggests installation steps when dependencies are missing.
    4. Follow the prompts to configure credentials and fill in platform integration parameters. Keep configuration files separate from code so that secrets do not enter the version repository.
    5. After startup, create a new chat session and paste the on-duty prompt to begin the conversation.

    For upgrades, simply give the upgrade instructions in the integration layer directory to the control plane session. The program is updated while personal memory data is retained. The key constraint here is that upgrades and debugging happen only in the control plane; chat sessions do not participate.

    4. Core Capability Design

    4.1 Stable Identity Recognition

    Use the stable user identifier provided by the platform as the primary key, and treat the nickname only as a display attribute. Profile files should be organized as “user identifier → attribute set,” so a nickname change only updates the display field and does not affect historical associations. Group chat and private chat should use namespace isolation—for example, the same identifier reads different memory partitions in different scenarios—and the isolation policy can be toggled.

    4.2 Affinity and Layered Memory

    Divide memory into three layers to control context length and call costs:

    • Long-term profile: stable preferences, taboos, and forms of address, written to persistent files;
    • Stage summaries: short summaries generated for group chats over time windows, replacing the practice of stuffing all history back into the context;
    • Short-term context: only the most recent several rounds of conversation.

    Affinity can be abstracted as an interpretable numeric range, updated by signals such as interaction frequency, positive feedback, and violation records, and mapped to behavior policies (such as tone, proactiveness, and whether the user is allowed to reach the bot via private chat).

    1. {
    2. "user_id": "stable-id",
    3. "display_name": "Nickname",
    4. "affinity": 0.62,
    5. "tags": ["Prefers concise answers", "Dislikes being @-mentioned"],
    6. "scope": {"group": "g-01", "private": "p-01"}
    7. }

    4.3 Voice Output and Multimodal Boundaries

    Speech synthesis can use a free option as the default implementation; the quality is average but the cost is zero. When audio quality matters, abstract voice capability behind an interface and replace it with a paid implementation without changing the business layer. A boundary needs special attention: not all models support image understanding. When connecting a model without multimodal capability, image recognition should explicitly degrade with a notice rather than fail silently.

    4.4 Permissions and Governance

    In group chats, low-affinity, high-frequency spamming should be handled by administrators. The bot only provides “suggest mute” candidates and an evidence summary and does not directly hold highly destructive permissions. All administrative actions are written to audit logs for traceability.

    5. Prompts and the “Nurturing” Approach

    A bot’s behavior depends largely on prompts and accumulated rules rather than the model itself. Practical approaches include:

    • Add usage scenario annotations for emojis and assets (such as acting cute, proud, or angry) so the model builds a “situation–expression” mapping;
    • Have the model actively record rules during conversations, forming a reviewable rule list;
    • Manually supply definitions for in-group slang. If the model is left to summarize such jargon on its own, it can easily learn it incorrectly; manually provided definitions are more reliable;
    • Iterate prompts based on preferences, with the control plane session making unified adjustments and versioning them.

    6. Cost, Risk, and Compliance Notes

    • Cost control: streamlining the on-duty prompt, using summaries instead of full history, and selecting model tiers by scenario are the three most effective measures.
    • Stability: free trial quotas are time-limited, so the architecture should support replacing models to avoid binding to a single implementation.
    • Compliance and security: use accounts and APIs you own or are authorized to use, and comply with the target platform’s automation and rate limits. Do not attempt to bypass limits through unofficial reverse engineering or proxy methods; this may violate terms of service and brings account suspension and data risks.
    • Open-source etiquette: derivative development should retain license notices, and commercial resale and redistribution are prohibited.

    7. Conclusion

    By treating a coding AI agent as an installation and operations proxy, splitting the bot into a control plane and a data plane, and using stable identifiers, layered memory, replaceable capability interfaces, and least-privilege governance as the backbone, you can build a continuously evolving chat agent at a controllable cost. The real long-term advantage lies not in a particular free quota, but in whether memory and rule assets are accumulated cleanly and remain portable enough.