Back to OSS
Swift Package LLM / AI

swift-llm-client

プロバイダー非依存の LLM クライアント抽象化。実装を差し替え可能なコア層

Swift
llmaiclient

English | 日本語

LLMClient

A provider-agnostic LLM client abstraction Swift package

Swift Platforms License

Features

  • Provider Agnostic - Unified protocol allows swapping any LLM provider without changing call-site code
  • Swift Macro-based Tool Definition - Type-safe Function Calling with @Tool macro
  • Structured Output - Type-safe structured responses via @Structured macro and JSON Schema
  • Streaming - Real-time token output via AsyncThrowingStream
  • Chat Management - Unified API for message history and context management

Installation

// Package.swift
dependencies: [
    .package(url: "https://github.com/no-problem-dev/swift-llm-client.git", .upToNextMajor(from: "3.9.0"))
]

Module Structure

Import only the modules you need:

Module Purpose
LLMCore Pure domain layer (LLMMessage, LLMResponse, TokenUsage, ModelProfile, etc.)
LLMClient Client protocols, structured output, prompt DSL (@Structured, SystemPrompt, etc.)
LLMTool Swift Macro-based tool definitions (@Tool, @ToolArgument, ToolSet)
LLMAgentStep Agent loop contract (AgentCapableClient, StreamingAgentEvent)
LLMChat Conversation continuation (ChatCapableClient, ConversationHistory)
LLMContext Context window breakdown and occupancy tracking
LLMMediaKit Platform I/O (UIImage / AVFoundation conversions, etc.)

Quick Start

Structured Output

import LLMClient

// Define a type with the @Structured macro
@Structured("City information")
struct CityInfo {
    @StructuredField("City name")
    var name: String
    @StructuredField("Population (in ten thousands)")
    var population: Int
}

// Generate via a client (any provider implementation)
let client: any StructuredLLMClient<LLMModel> = // any provider implementation
let city: CityInfo = try await client.generate(
    input: "Tokyo has a population of approximately 14 million",
    model: .claude(.sonnet)
)
print(city.name)       // "Tokyo"
print(city.population) // 1400

Tool Definition

import LLMTool

@Tool("Get current weather")
struct GetWeather {
    @ToolArgument("City name")
    var city: String

    func call() async throws -> String {
        // Call weather API
        return "Tokyo: Sunny 25°C"
    }
}

let tools = ToolSet {
    GetWeather()
}

Documentation

See the DocC documentation for detailed guides and API reference.

Guide Description
API Reference Full public API

Requirements

  • iOS 17.0+ / macOS 14.0+
  • Swift 6.2+
  • Xcode 16.0+

License

MIT License - See LICENSE for details

Links

同じカテゴリの OSS — LLM / AI

swift-llm-cloud

Swift Package

Anthropic / OpenAI / Gemini を束ねるマルチプロバイダー LLM クラウドクライアント

Swift
· LLM / AI
llmanthropicopenaigemini

swift-llm-local

Swift Package

iOS / macOS のデバイス上でローカル LLM 推論を動かす Swift パッケージ

Swift
· LLM / AI
llmon-deviceinference

swift-llm-mcp

Swift Package

swift-llm-client 向けの MCP + ツール解決層。MCP サーバーと組み込みツールキットのアダプタ

Swift
· LLM / AI
llmmcptools

swift-structured-data

Swift Package

外部由来の JSON / YAML / XML を Swift の型システムへ安全に変換するレイヤー

Swift
· LLM / AI
jsonyamltype-safe

swift-research-agent

Swift Package

Web 検索・取得ツールと引用ゲートを備えたリサーチャー・エージェント

Swift
· LLM / AI
agentresearchweb-search

swift-media-agent

Swift Package

画像・チャート・動画生成ツールとセッション単位のメディアストアを持つビジュアライザー・エージェント

Swift
· LLM / AI
agentmediageneration

© 2026 Kyoichi Taniguchi. All rights reserved.