AI in Actions
AI in Actions
This article covers use of Artificial Intelligence (AI) services in Drafts actions. If you are interested in integration of your Draft library with desktop AI clients, like Claude Desktop, see information on our Model Context Protocol server. For using AI in Drafts directly through a chat-style interface, see the Chat Console article.
Drafts extensible platform makes it a great way to work with a variety of AI tools, both through REST APIs and directly on-device with Apple’s own Foundation Models.
Table of Contents
Apple Intelligence - Foundation Models
Requirements
This section discusses integrations added in Drafts 54, and requires OS 27.
Drafts provides a ModelSession script object to work with multiple LLMs from different providers with the same access to extended tools for integration with both Drafts and system APIs as the Chat Console. This is the preferred method to integrate with AIs when running OS 27 or greater, as it provides flexibility to work with different providers and models from the same API.
A few example actions are the best way to get started with the ModelSession object:
- Move to Reminders: Takes the text in the selected lines in the editor, and generates reminders in the Reminders app. The base instructions support identifying due dates, and lists. This action also demonstrates using a single
ModelSessionobject with multiple prompts to maintain context. - Modify Selection: Ask user for a transformation to apply to the selected text in the editor, and apply it.
- Ask Model: Simple action that asks for an input prompt from the user, submits it to the model, and displays the response.
Online AI Services
About API Keys
Drafts provides integration points with a number of APIs, but in most cases you will need to use your own API key and account. For more details, see linked integration guides for each service below.
Integrating with LLMs provided by large players in AI, like OpenAI and Google, can provide useful actions for getting answers to prompts, or manipulating text you have captured in Drafts…or even getting chat responses to world-knowledge questions.
Currently, Drafts supports integration directly with the APIs of the following platforms. Follow the links for integration guides and example actions for each:
- OpenAI - ChatGPT
- Google Gemini
- Anthropic Claude
- Perplexity.ai: Note, that Perplexity supports the same API as OpenAI, so the example integrations are part of that article. See the Perplexity heading for details.
Note that other platforms which utilize the OpenAI API (like xAI and Deepseek) can also be integrated using the OpenAI script object.
If a particular AI tool is available through web-based APIs, but is not already integrated into Drafts, you will likely find it is possible to integrate directly using scripting and Drafts’ HTTP object – or you may find available examples by searching the directory.
On-Device AI (Legacy Support for OS 26)
Requirements
If you are running OS 27 or greater, see the above “Apple Intelligence” section. This section covers support initially introduced with OS 26, but the more advanced options above are preferred.
Starting with the version 26 releases of iOS, iPadOS, and macOS, Apple also provides private, on-device Foundation Models. These models are more focused and not suitable all the same tasks, such as answering world-knowledge questions, as larger, server side models, but they are fast and private, and work great for smaller tasks – such as summarizing text, suggesting tags, and correcting grammar.
Integration with Foundation Models is provided through scripts using the SystemLanguageModel object.
Some example actions that demonstrate use cases:
- Ask Model: Mostly a debugging tool, the action asks you for a prompt, submits it to the model and displays a reply.
- Suggest Tags: Ask the local model to analyze the text of the current draft and suggest organizational tags to assign, then prompts you to select from those suggestions.
- Summarize Draft: Prompt model to provide a short summary of the content of the current draft, then displays it.
- Modify Selection: Prompt for text transformations description, and apply that transformation to the selected text in the editor, replacing the selection with the result.
- Random Numbers: Asks the local, on-device model to generate an array of random integer numbers. Not terribly useful in an of itself, but provided as an example of ways to retreive structured data from the model.
Drafts Data in Foundation Models
The local Foundation Models support the concept of “Tools” which provide the model access to application data to assist in answering questions. Currently, Drafts provides two experimental “tools” to allow the model to respond to inquiries about your drafts and workspaces.
Drafts currently ships with tools that can perform the following (each with representative prompts):
- Find drafts by tag, content
Do I have any drafts with the tag "project"Find drafts which contain the text "hello"
- Find a draft by UUID
Get the draft with the ID "UUID"
- Create a new draft with text
Create a draft with the text "This is my draft"
- Open a draft in the editor
Create a draft with the text "Foo" and open it in the editor
- Moving drafts to inbox, archive, trash
Move the draft with the ID "UUID" to the archive
- Appending/Prepending to the content of a draft.
Append the text "Foo" to the draft
- Run actions on a draft
Run the action "Save to iCloud Drive" on the draft
These tools can be combined in complex prompts to perform mulitple tasks, like:
Create a draft with the text "Hello", open it in the editor, move it to the archive, and run the action "Post to Mastodon" on it.
In order to use these tools, your SystemLanguageModel object must have the appropriate tools enabled. In most cases, this is done by calling model.enableAllTools() before running a prompt. For details, see scripting docs. The “Ask Model” action linked above defaults to including tools, so is a great way to test capabilities.