Community Discussion · Tracks

Built a private Mac AI assistant in Swift over the weekend

Sister QingSister QingAug 122026/08/12 158 views

Conclusion first: macOS has more built-in capabilities than most people realize. Writing a persistent AI agent in Swift, running it on your own hardware, and pairing it with a Telegram bot as a remote control—this can be done in a weekend. No renting servers, no installing Docker, no touching Python.

Last week I saw someone write such a project in pure Swift, connecting a private Telegram bot with your chosen LLM (Large Language Model, the tech behind ChatGPT). The whole program is a daemon. A daemon is a background resident process, similar to those programs on your Mac that run automatically at startup without taking up window space. I watched and tried along, hit a few pitfalls, and am writing this down for those who want to give it a shot.

Preparation Phase

First, confirm three things.

System version. Apple's FoundationModels framework is built-in starting from macOS 26. This framework allows you to directly call the system's native language model capabilities without connecting to external APIs yourself. You can check the version number via the Apple icon in the top-left corner → About This Mac. If it's below 26, upgrading is recommended.

Install Xcode. Search for Xcode in the App Store and install it; it's roughly several GBs. Open it once after installation to let it initialize. Swift is Apple's programming language, and Xcode is the official IDE (Integrated Development Environment, the software where you write code and run programs); you need both.

Create a Telegram bot. Search for @BotFather on Telegram, send it /newbot, follow the prompts to name it, and it will reply with a token string (a character sequence, essentially the key to your bot). Copy the token to your notes; you'll need it later.

Getting Started

Open Xcode, select Create New Project, choose Command Line Tool under macOS, and select Swift as the language. This project type is ideal for daemons—no windows, runs purely via command line.

After creation, Xcode generates a main.swift file. Clear the default code inside and first write a simple HTTP service whose purpose is to confirm "I'm alive" to the Telegram server. The mechanism for Telegram bots is polling; your program asks the server for new messages every second or two, so you don't need to open ports yourself.

The core code consists of roughly three parts:

1. Use URLSession to request the Telegram API, including your token

2. Parse the returned JSON (a common data exchange format) to get the message text

3. Send the text to the LLM, then send the reply back to Telegram

Don't write anything complex for the first working version. I suggest hardcoding a reply, e.g., responding "hello" to any message, to confirm the link works before integrating the model.

Press Cmd + R in Xcode to run; logs will print to the console. Then go to Telegram and send a message to your bot. If you see it reply "hello," congratulations, the link is established.

Pitfall Log

I got stuck in three places here.

Pitfall 1: The program dies when closed. Processes running in Xcode die when Xcode closes. To make it persistent, you must place the compiled binary in /usr/local/bin/ and register it as a startup item using launchctl. This step isn't complex, but beginners often miss it. launchctl is a macOS built-in service management command, effectively telling the system, "This program needs to keep running."

Pitfall 2: Permission prompts on first run. macOS controls permissions for network requests and notifications. On the first run, pop-ups will ask for permission; remember to click Allow. If you accidentally clicked Deny, go to System Settings → Privacy & Security to enable it manually.

Pitfall 3: Model selection. You can connect to remote APIs like OpenAI, or local models. Local models use the MLX framework, a machine learning toolkit released by Apple. The benefit is data stays on-device; the downside is fans spin wildly when running large models. On my end, a 7B parameter model (a unit measuring model size; larger means smarter but more resource-intensive) already makes the MacBook hot. Some sources mention achieving a complete agent package of just 35.5MB, which is very lightweight, but that requires cutting features to the extreme. I recommend using a remote API for the first pass to get it working, then researching local options.

What to Try Next

Integrate voice input; macOS has a built-in Speech framework that lets the bot understand voice messages. Or search GitHub for swift agent macos to see other open-source projects and modify one with more features. One developer in the source material knew zero Swift but completed the entire app in Xcode with AI assistance, proving this path is viable.


📌 This article is compiled from Hacker News. Original source: https://github.com/ivan-magda/swift-claw

Copyright belongs to the original authors. This is a compilation and independent analysis based on public reports.

2 replies

?
Ctrl + Enter to reply
Weiwei's Shop

Haha, I got stuck on the system version too... My old Mac couldn't run FoundationModels; it only worked after upgrading.

Luguo
LuguoAug 12

Wait, how effective are the system's built-in models? Will they be significantly worse compared to APIs? I just got an AI Agent running last week and am curious about the actual experience with this local solution.