Build an AI Personal Assistant from Scratch: Cloud Deployment and Multi-Platform Integration
This guide walks you through building a practical AI personal assistant as a three-tier system: an integration layer, a gateway layer, and a capability layer. It explains why a cloud server is the right host, recommends 2-core/4G configurations and firewall rules, and shows how to deploy the gateway from an image or a clean system with process守护. You will also learn how to connect an OpenAI-compatible model service, integrate workplace and personal messaging platforms, and add long-term memory, custom skills, and multi-agent routing. The article closes with operations practices, risk controls, and a troubleshooting checklist for common failures.
1. Clarify the Requirements: What Are You Actually Building?
Many people think of an “AI personal assistant” as a chat window, but that is only the surface. A usable setup has three layers:
- Integration layer: the instant messaging tools you use every day, responsible for sending and receiving messages.
- Gateway layer: an always-on service that handles authentication, session routing, message format conversion, rate limiting, and logging.
- Capability layer: the large language model, vector retrieval, and tool calls (reading and writing files, querying databases, calling external APIs).
In the original requirements, the recurring “crayfish” was just a playful nickname for this kind of gateway project. This article uses the general technical term “AI assistant gateway.” Its value is not that it “can chat,” but that it frees model capabilities from a web chat box and turns them into an always-on service triggered by message events.
2. Why You Need a Cloud Server
The gateway service has three hard requirements: an always-on process, a publicly reachable callback address, and persistent storage for sessions and memory data. That makes it unsuitable for a local laptop that sleeps and changes IP addresses.
Beginners should prefer cloud deployment for three reasons. First, it is ready to use: lightweight application server images from mainstream cloud providers usually come with runtimes and dependencies preinstalled, saving manual compilation. Second, the network environment is more neutral, and overseas regions typically face fewer restrictions when accessing model APIs hosted abroad. Third, the cost is predictable: lightweight plans billed annually are usually around a hundred yuan, enough for personal-scale requests.
Configuration recommendation: 2 cores and 4 GB is a comfortable starting point. If you enable a local vector store and accumulate many documents, upgrade memory before CPU when memory is tight. If you only forward conversations, 2 cores and 2 GB will also run. Use a system disk of 40 GB or more; a data disk is optional for storing the memory store and logs.
The security group only needs three types of ports open: SSH (change the default port and restrict the source IP), the gateway management port (accessible only from your own IP), and the message callback port (initiated by the platform side).
3. Deploy the Gateway: From Image to Process Supervision
If you use a preconfigured image, open the management port after creating the instance to enter the initialization wizard. For a clean system, the general flow is as follows (illustrative):
# 1. Prepare the runtime environmentsudo apt update && sudo apt install -y git curl# 2. Get the gateway codegit clone <your-gateway-repo-url> ~/agent-gateway && cd ~/agent-gateway# 3. Install dependenciesnpm install -g pnpm && pnpm install# 4. Write the configurationcp .env.example .env && vi .env# 5. Start as a supervised processpm2 start main.js --name agent-gateway && pm2 save
Four groups of fields really matter in the configuration file:
# Model sideMODEL_BASE_URL=<model service URL>MODEL_API_KEY=<your key>MODEL_NAME=<model identifier># Session and memorySESSION_STORE=fileMEMORY_BACKEND=vectorMEMORY_TOP_K=5# Platform sideFEISHU_APP_ID=<app ID>FEISHU_APP_SECRET=<app secret>TELEGRAM_BOT_TOKEN=<bot token>
Right after initialization, do three things: change the default management password, enable log rotation, and set up a daily automatic backup of the memory store directory. Skipping this leaves a server with keys exposed to the public internet.
4. Connect the Large Model Capability
The gateway itself has no intelligence; it only forwards and orchestrates. You need a service URL, key, and model identifier compatible with the OpenAI-style protocol. When choosing, look at three things: long-context capability (whether it can hold the full memory), tool-calling support (whether it can operate external systems), and cost per token.
It is recommended to configure a “primary model” for complex reasoning and a lightweight model for chores such as title generation and intent classification, which can significantly reduce the bill.
5. Integrate Instant Messaging Platforms
Take a workplace platform commonly used by teams as an example. The standard steps are: create a custom app → enable bot capability → configure a long connection or callback address → subscribe to message events → publish a version and authorize it to yourself. In personal scenarios, authorize only your own department to avoid accidental triggers.
On the personal messaging tool side, it is simpler: create a bot token, put the token into the gateway, and start a conversation visible only to you. Note: do not commit the token into a code repository; use environment variables or a secret management service.
For connectivity checks, use a “three-stage troubleshooting” approach: first check whether the gateway log received the event, then whether the model call returned, and finally whether the reply was delivered. Most “the bot does not reply” issues are stuck at the first stage.
6. Advanced Capabilities: Memory, Skills, and Multi-Agent Collaboration
Long-term memory usually consists of a “summary layer plus vector retrieval layer.” After a conversation ends, extract key points into structured storage, and at retrieval time take the Top-K by similarity and inject them into the prompt. Be sure to set capacity limits and expiration policies, otherwise memory will swell and pollute the context.
Custom skills are essentially a set of tool definitions with a JSON Schema. The model outputs a structured call intent, and the gateway executes it and fills the result back in. The more specific the tool description, the higher the call accuracy.
Multi-agent collaboration is best done with a “router plus executor” pattern: a lightweight agent judges intent and dispatches, while multiple specialized agents each hold their own toolset, avoiding the difficulty of choice caused by too many tools in a single agent.
7. Operations and Risk Control
- Keep all keys in environment variables and rotate them regularly;
- Bind the gateway management plane to source IPs and verify signatures on callback endpoints;
- Set rate and budget limits on model calls to prevent runaway bills;
- Desensitize logs before writing them to disk to avoid leaking conversation content;
- Rehearse recovery procedures regularly and confirm the memory store can be restored.
8. Common Pitfalls Checklist
An outdated image version causing dependency conflicts, a callback address without public mapping, inconsistent time zones causing scheduled tasks to misbehave, silent truncation when the context is too long, and bot permissions not published so events are not received. Troubleshoot in the order above, and you can usually locate the issue within half an hour.
At this point, a personal assistant with a message entry point, model capability, long-term memory, and extensible skills is online. It can later be migrated smoothly to local devices or a container platform without architecture changes—this is the long-term benefit of decoupling the integration layer, gateway layer, and capability layer.
