gitmyhub

foundation-models-utilities

Swift ★ 148 updated 13d ago

Emerging and experimental patterns for building with the Foundation Models framework

This is an official Apple package that adds extra building blocks on top of Apple's Foundation Models framework, which is Apple's system for running AI language models on-device across its platforms. The utilities here cover three main areas: connecting to external AI servers, managing how much conversation history a session holds, and injecting task-specific instructions on demand.

The first feature, called ChatCompletionsLanguageModel, lets your app talk to any AI server that uses the standard chat completions protocol. That includes local AI servers you run on your own machine. You point it at a URL, give it a model name, and it works like any other language model session in the framework. This is useful because a large ecosystem of open-source AI tools already speaks that same protocol.

The second feature is history management. When you have a long back-and-forth conversation with an AI, the transcript can grow until it exceeds the model's memory limit. This package provides modifiers that compress the transcript automatically using different strategies: dropping tool calls that are already finished, keeping only the most recent entries via a rolling window, and summarizing older exchanges into a single compact entry. You compose these strategies together based on what your app needs, since there is no single approach that works for every case.

The third feature is called Skills. Instead of loading all your instructions into the AI session upfront, which wastes memory and slows down the first response, Skills inserts specific guidance into the conversation only when the model decides it is relevant. A skill might be a writing style guide, calendar rules, or any domain-specific prompt. The model activates a skill by generating a tool call, and the skill's content is then added to the transcript at that moment. This keeps the session leaner and faster.

The package works on Apple platforms and on some Linux distributions such as Ubuntu. Installation is through Xcode or Swift Package Manager.