@modelprofile.com/swiftsupport

Swift for modelprofile.com. First of all FlexHarness for Apple apps: the agent loop of FlexHarness's runAgent, a model protocol with the Anthropic Messages API, and tools — for apps such as invoice.bot that run an agent on Mac, iPad and iPhone without a Node.js process.

Issue Reporting and Security

For reporting bugs, issues, or security vulnerabilities, please visit community.foss.global/. This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a code.foss.global/ account to submit Pull Requests directly.

Install

The Swift package (Swift 6; iOS 17, macOS 14, visionOS 1):

dependencies: [
  .package(url: "https://code.foss.global/modelprofile.com/swiftsupport.git", from: "0.1.0"),
],
targets: [
  .target(name: "MyApp", dependencies: [.product(name: "FlexHarness", package: "swiftsupport")]),
]

Releases are tagged vX.Y.Z, which SwiftPM reads as version X.Y.Z.

A task with a tool

import FlexHarness

let add = Tool(
  name: "add",
  description: "Adds two numbers.",
  inputSchema: ["type": "object", "properties": ["a": ["type": "number"], "b": ["type": "number"]], "required": ["a", "b"]]
) { input in
  struct Input: Decodable { let a: Double; let b: Double }
  let numbers = try input.decode(as: Input.self)
  return ["sum": .number(numbers.a + numbers.b)]
}

let model = AnthropicModel(model: "claude-opus-5-5", apiKey: apiKey)
let result = try await runAgent(model: model, system: "Use the tools.", prompt: "2 + 3?", tools: [add], maxSteps: 8)
print(result.text, result.usage, result.toolCalls)
  • The loop asks the model, runs every tool it calls in order, answers with their results, and ends when the model answers without tools. A tool that throws answers the model with the error's description as a failed result (is_error); a tool the model names but nobody registered answers "no tool named …"; the run goes on either way.
  • maxSteps (default 20) counts model calls; a model that still calls tools then ends the run with AgentError.stepLimit. Cancelling the calling task ends the run between model calls and between tool calls (CancellationError), so a tool that decides the work is done can end it.
  • onToolCall sees every call with its input, output and whether it failed — for a live view of the run.
  • AnthropicModel posts to /v1/messages (anthropic-version: 2023-06-01) without streaming. A refusal throws ModelError with the HTTP status and the provider's own message; the request (the conversation) and the key are never part of an error.
  • LanguageModel is one method; a test scripts it (see Tests/FlexHarnessTests/AgentTests.swift).

Development

swift build
swift test

The tests need no network: the agent runs against a scripted model, AnthropicModel against a stubbed URLProtocol.

This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the license.md file.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.

Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.

Company Information

Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany

For any legal inquiries or further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

S
Description
No description provided
Readme
44 KiB
Languages
Swift 100%