Building a Self-Evolving AI Assistant from Scratch and Connecting It to WeChat: A Practical Guide

    This guide walks through building a persistent, self-evolving personal AI assistant and connecting it to a personal messaging channel. It covers why a skill-learning loop matters, environment and resource requirements, credentials to prepare, model selection with context length as the primary constraint, installation and initialization on Unix-like systems, Windows, and mobile, messaging channel integration with session mapping and permission whitelists, operations and cost control, and common troubleshooting steps.

    1. Why “Self-Evolution” Is the Key Divide for Personal Assistants

    Traditional chatbots follow a stateless “one question, one answer” model: once a session ends, the context is discarded, and users have to repeatedly restate background, preferences, and operating conventions. A new generation of personal assistants built around a “skill learning loop” treats interactions as an accumulating asset: after a task completes, it automatically reviews the run, distills reusable steps into structured skills, and calls them directly in later similar tasks, producing an experience that gets smoother the more you use it.

    From an engineering perspective, this capability breaks down into a three-stage closed loop:

    • Experience extraction: compress the trajectory of a successful run (goal, tool call sequence, intermediate artifacts, verification method) into a searchable knowledge entry;
    • Skill generation and registration: turn frequent patterns into skill units with input/output signatures and add them to a local skill library;
    • Retrieval, reuse, and iteration: when a new task arrives, run a similarity match first; on a hit, reuse the skill; on a miss, fall back to the general reasoning path and distill again.

    The value of this design is that it turns a one-time investment like prompt tuning into a personal knowledge asset that keeps compounding. You can think of it as a “digital intern” on call 24/7: it can operate a terminal, read and write files, search the web, extend external capabilities through a standardized tool protocol, and carry periodic work via scheduled tasks.

    2. Environment Assessment and Preparation Before Deployment

    1. Operating System and Runtime Host

    This kind of always-on assistant typically depends on a Unix-like environment. Mainstream support includes major Linux distributions, macOS, and the Linux subsystem on Windows; on mobile, it can run in a terminal emulator environment. Native Windows is generally not used as a direct runtime because it lacks equivalent process and filesystem semantics.

    Selection guidance:

    • An old home laptop or an idle machine: suitable for installing a lightweight Linux as an always-on node;
    • A low-cost cloud host: suitable for scenarios that need public reachability and stable uptime;
    • A terminal emulator environment: suitable for temporary debugging, not recommended for long-term tasks.

    2. Resource and Network Baseline

    An always-on assistant itself has modest overhead; the bottleneck is usually model inference and tool execution. A practical rule of thumb: an entry-level cloud host with 1 core and 1G of memory is enough for a basic deployment; if the work involves local document parsing or batch file processing, start with 2 cores and 2G. For networking, you need stable access to the model service endpoint; otherwise tasks will break and you may be billed repeatedly.

    3. Credentials to Prepare in Advance

    • One large model API key (any mainstream model provider works, and it must support tool calling);
    • One personal instant messaging account for connecting via QR code;
    • One networked terminal that can complete the QR scan.

    One point deserves emphasis: a personal assistant holds your filesystem and terminal permissions, so credential management must be designed up front, not patched afterward.

    3. Model Integration: Context Length Is the First Constraint

    Many deployment failures are not installation problems but a mismatch in model selection. This kind of assistant needs to fit the system prompt, skill library, historical trajectory, and tool return results into the context at the same time, so it is sensitive to window capacity. The common industry recommendation is no less than 64K tokens; if tasks involve long documents or multi-step tool chains, 128K is safer.

    When evaluating a model, look at four dimensions:

    1. Whether the context window meets the needs after the skill library grows;
    2. Whether it natively supports function/tool calling and whether the output structure is stable;
    3. Instruction-following ability, especially constraint retention under long prompts;
    4. Cost and rate-limit policy, since scheduled tasks create predictable periodic consumption.

    Configuration is usually done through environment variables or a local config file, as shown below:

    1. # Model service endpoint and credentials (example fields; fill in per your provider's documentation)
    2. export LLM_BASE_URL="https://your-endpoint/v1"
    3. export LLM_API_KEY="<your-key>"
    4. export LLM_MODEL="<model-name>"
    5. export LLM_MAX_CONTEXT=131072

    If you use a model service from a domestic cloud provider, you can choose the general large model service category offered by Baidu AI Cloud and integrate through a standard compatible interface, avoiding the operational burden of self-hosted inference.

    4. Installation and Initialization

    1. Unix-like Environments

    The official installer is usually a one-click script that essentially does three things: verify dependencies, pull the runtime, and write the shell configuration. After running it, reload the configuration so the environment variables take effect:

    1. # Install (illustrative; use the address in the official documentation)
    2. curl -fsSL <official-install-script> | bash
    3. # Reload configuration
    4. source ~/.bashrc # zsh users run source ~/.zshrc
    5. # Verify
    6. hermes --version
    7. hermes doctor

    A doctor-style self-check subcommand is critical: it checks the runtime version, config file validity, model connectivity, and directory permissions, surfacing about 80% of configuration errors in advance.

    2. Windows Environments

    First enable the Linux subsystem in an administrator terminal and reboot. After setting a username and password, repeat the steps above inside the Linux subsystem. Note: keep files on the Linux-side directories; accessing /mnt/c across systems will noticeably slow down file-intensive tasks.

    3. Mobile

    Install in a terminal emulator environment, and pay extra attention to background keep-alive and wake policies. It is recommended to disable battery optimization restrictions; otherwise scheduled tasks will be silently terminated by the system.

    5. Connecting a Personal Messaging Channel

    The integration logic can be abstracted into three layers: “message gateway + session mapping + permission whitelist”:

    • Message gateway: use an adapter pattern to connect to the send/receive interfaces of different channels; personal WeChat-type channels typically rely on a QR scan to establish a session, and the QR code has a short validity, so it must be refreshed in real time on the terminal side;
    • Session mapping: map an external session ID to a local working directory and skill namespace, achieving “one session, one context” and avoiding cross-contamination;
    • Permission whitelist: only allow specified contacts and groups, and drop all other messages.

    Example configuration:

    1. channels:
    2. wechat:
    3. enabled: true
    4. auth_mode: qrcode
    5. allow_from: ["wxid_xxx"]
    6. group_policy: mention_only
    7. workspace:
    8. root: ~/.hermes/workspaces
    9. per_session_isolation: true

    There are three hard security recommendations: first, since the assistant has terminal permissions, always run it under a low-privilege account and never as root; second, isolate the working directory with quota limits to prevent a single session from filling the disk; third, require a second confirmation for all outbound messages by default to avoid accidentally triggering irreversible operations.

    6. Operations, Cost, and Risk Control

    An always-on service should be managed by a process manager to enable automatic restart on crash and log rotation:

    1. [Unit]
    2. Description=Personal AI Assistant
    3. After=network-online.target
    4. [Service]
    5. User=assistant
    6. Restart=always
    7. RestartSec=5
    8. EnvironmentFile=%h/.hermes/env
    9. ExecStart=/usr/local/bin/hermes daemon
    10. [Install]
    11. WantedBy=multi-user.target

    Three supporting measures: use a logging service and monitoring alerts to track task success rate and response latency; set a global concurrency limit and timeout for scheduled tasks; and set budget threshold alerts for model calls. The core of cost control is not saving on unit price but suppressing invalid loops—context bloat and failed retries are the main drivers of the bill.

    7. Troubleshooting Common Issues

    • No response after scanning: usually the callback address is unreachable or the port is not open; verify connectivity first;
    • Task interrupted midway: prioritize checking context overflow and tool timeouts;
    • Skill not taking effect: check whether the skill library index has been rebuilt and whether the namespace matches;
    • Slower responses: usually caused by an overly long historical trajectory; enable summary compression and rolling cleanup.

    Troubleshoot layer by layer in the order “environment self-check → model connectivity → channel callback → permissions and quotas,” and most problems can be resolved within ten minutes. After completing these steps, you have a personal AI assistant that continuously accumulates skills and can be dispatched at any time from your phone.