Building a Personal AI Assistant: A Multi-Device Integration Practice

    This article explains how to build a personal AI assistant that works inside the messaging platforms you already use, rather than requiring a separate app. It breaks the problem into four layers—integration, orchestration, execution, and governance—and compares two common approaches: a message-gateway open-source toolbox and an all-in-one personal agent workbench. You will find a reference architecture, engineering details for office IM bot integration, sandbox security practices, layered context and memory management, multi-device synchronization, observability and cost control, and a phased rollout roadmap.

    1. Introduction: Why an Always-Available Assistant Matters

    Most people picture an AI assistant as the ever-ready, all-capable smart butler from science fiction. It manages schedules and projects, analyzes data, retrieves information, and helps you think through a vague idea during a few spare minutes. Translating that vision into engineering reality is less about a “smarter model” and more about accessibility: the assistant has to show up where you already are, instead of asking you to open a dedicated client.

    Consumer instant messaging turned “messages” into the default interaction entry point. Today, workplace collaboration platforms play the same role for workflows. A practical personal AI assistant architecture therefore usually does not start a new app; it attaches agent capabilities to an existing messaging channel. This article takes a general technical view of how to complete that integration in an office IM such as WeCom, and how to extend the pattern to multi-device scenarios.

    2. Problem Modeling: From “Can Chat” to “Can Get Work Done”

    Connecting a large language model to a chat window is only the first step. The hard part is turning a single message into a task that is executable, traceable, and reversible. Four layers need to be abstracted:

    1. Integration layer: connects to the IM platform, sends and receives messages, handles event callbacks, and maintains session identifiers.
    2. Orchestration layer: handles intent recognition, task decomposition, tool selection, context assembly, and multi-turn state management.
    3. Execution layer: runs commands, reads and writes files, and calls external APIs inside a controlled sandbox, producing structured results.
    4. Governance layer: identity mapping, permission checks, audit logs, rate limiting, and cost control.

    Most “toy-grade” implementations only build the integration layer plus a single model call. Without the last two layers, they cannot handle long-running tasks, nor answer “who sent that instruction, and which files were changed.”

    3. Two Routes in the Reference Landscape

    Common industry approaches fall into two categories.

    Route A: A message-gateway open-source toolbox. Protocol adapters expose the agent to multiple chat platforms. Coverage is broad, typically offering hundreds of CLI subcommands, scheduled jobs, multi-agent routing, and a gateway service, with an active community and solid documentation. The advantage is flexibility; the cost is some operations and configuration effort, which suits teams with platform engineering capability building their own infrastructure.

    Route B: An all-in-one personal agent workbench. IM integration, task orchestration, the tool ecosystem, and the interface are packaged into a finished experience. Users configure almost nothing and can start assigning work in an office IM out of the box. The advantage is a fast start and a consistent experience; the cost is that customization boundaries are decided by the product.

    The two routes are not mutually exclusive: a team can validate value with Route B first, then turn high-frequency scenarios into Route A-style in-house capabilities.

    4. Target Architecture

    The recommended structure is layered: “thin integration + thick orchestration + strong isolation.”

    1. IM (WeCom / other channels)
    2. │ Event callback / long connection
    3. ▼
    4. Integration adapter ── Session mapping (external session ID ↔ internal thread ID)
    5. ▼
    6. Orchestration scheduler ── Intent classification / plan generation / tool selection
    7. ▼
    8. Execution sandbox (container) ── File system / commands / API clients
    9. ▼
    10. Governance components: authentication, audit, rate limiting, cost metering, observability

    Key design points:

    • Session mapping table: IM sessions are flat, while tasks are tree-shaped. Each user needs a “main thread + subtask threads” structure to keep contexts from contaminating each other.
    • Idempotency and deduplication: message callbacks may be retried, so the unique message identifier must serve as the idempotency key.
    • Asynchronous acknowledgment: long tasks first return “accepted + task ID,” then push a result card when finished.

    A sketch of the message-handling skeleton:

    1. def on_message(event):
    2. if not verify_signature(event): # Governance layer: signature verification
    3. return reject(event)
    4. key = event.msg_id # Idempotency key
    5. if seen(key):
    6. return ack(event)
    7. thread = mapper.get_or_create(event.user_id)
    8. task = planner.submit(thread, event.text)
    9. reply(event, f"Task {task.id} accepted; results will be pushed when done")

    5. Engineering Details of IM Integration

    Using an office IM bot as the example, the general flow is: create a bot application in the platform console → configure the callback URL for receiving messages → complete domain ownership and signature verification → request the required APIs according to permissions → roll out gradually.

    Issues that need particular attention include:

    • Callback reachability: internal services must expose a public entry point through a reverse proxy or gateway, allowing only platform-originated traffic.
    • Signature verification and decryption: platforms typically encrypt callback bodies and attach a signature, so verification must come before parsing.
    • Rate limits and quotas: APIs for sending messages and uploading media have call-frequency limits, so a local token bucket is needed as a fallback, along with retry and backoff on failure.
    • Message format: plain text is a poor fit for long results; card-style messages should carry summaries, status, and action buttons.

    6. Tool Invocation and Sandbox Security

    An agent’s capability ceiling is set by its toolset, and so is its risk. Follow the principle of least privilege:

    • Run in containers as a non-root user, mount system directories read-only, and give each task a separate volume.
    • Use a network egress allowlist and block arbitrary outbound connections; require a second confirmation for write operations.
    • Route high-risk commands (deletion, bulk rewrites, permission changes) through an approval flow, or disable them outright.
    • Log the inputs, a summary of outputs, and elapsed time for every tool call to form a traceable chain.
    1. sandbox:
    2. image: agent-runtime:latest
    3. user: "1000:1000"
    4. read_only_rootfs: true
    5. network: allowlist
    6. resources: {cpu: "1", memory: "1Gi", timeout: "300s"}

    7. Context and Memory Management

    Conversations in spare moments often span hours or even days, so memory needs to be layered:

    1. Short-term context: the most recent turns in the current thread, trimmed on a sliding basis against a token budget.
    2. Task memory: the structured plan, completed steps, and artifact paths.
    3. Long-term memory: user preferences and common workflows, extracted into itemized summaries and injected by retrieval rather than concatenated in full.

    The practical advice is to “allocate a budget” across context: system instructions, long-term memory, task state, and recent conversation each take a fixed share. When the limit is exceeded, compress the conversation first rather than dropping task state.

    8. Multi-Device Coordination

    The same assistant needs to switch seamlessly between phone, desktop, and web. The key is a unified session core plus multiple front-end adapters: the core holds the single source of task state, and each device is only a view. Mobile leans on cards and voice input; desktop leans on file and terminal capabilities. When switching devices, resume by task ID instead of re-describing the background.

    9. Observability and Cost Governance

    After launch, three questions must be answerable: where is it slow, where is it wrong, and how much did it cost. Recommended telemetry: end-to-end latency, model call volume, tool success rate, and cost per task. Keep a snapshot of failed tasks for replay and diagnosis. On the cost side, optimize with a small model for intent classification, caching of repeated queries, and limits on context length.

    10. Rollout Roadmap

    • Phase 1: single-channel integration plus read-only tools (retrieval, summarization, schedule lookup) to validate the experience.
    • Phase 2: introduce write operations and a sandbox, and complete audit and approval.
    • Phase 3: unify multiple channels and devices, and build up a reusable tool marketplace.
    • Phase 4: scheduled jobs and proactive pushes, moving from “passive responses” to “proactive collaboration.”

    11. Conclusion

    The difficulty of a “personal Jarvis” was never the model itself, but placing the model inside an engineering system that is secure, traceable, and reachable everywhere. Using the general capabilities of cloud platforms such as Baidu AI Cloud (container platform, message queue, logging service, monitoring and alerting, object storage) as the foundation, together with a layered architecture and strict governance, individuals and small teams can build their own multi-device AI workbench at a controllable cost.