SKIntelligence 是一个面向 Swift 的 LLM 能力库,提供会话编排、流式输出、工具调用、MCP 接入、记忆与检索能力。
dependencies: [
.package(url: "https://github.com/linhay/SKIntelligence.git", from: "2.0.0")
]在 target 中按需添加:
.target(
name: "YourApp",
dependencies: [
"SKIntelligence",
"SKIClients",
"SKITools"
]
)import SKIntelligence
import SKIClients
let client = OpenAIClient().profiles([
.init(
url: URL(string: "https://api.openai.com/v1/chat/completions")!,
token: "<OPENAI_API_KEY>",
model: "gpt-4o-mini"
)
])let session = SKILanguageModelSession(client: client)
let text = try await session.respond(to: "用一句话介绍 SKIntelligence")
print(text)let stream = try await session.streamResponse(to: "分三点说明如何接入 MCP")
for try await chunk in stream {
if let text = chunk.text {
print(text, terminator: "")
}
}Package.swift
// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "SKIDemo",
platforms: [.macOS(.v14)],
dependencies: [
.package(url: "https://github.com/linhay/SKIntelligence.git", from: "2.0.0")
],
targets: [
.executableTarget(
name: "SKIDemo",
dependencies: ["SKIntelligence", "SKIClients"]
)
]
)Sources/SKIDemo/main.swift
import Foundation
import SKIntelligence
import SKIClients
@main
struct SKIDemoApp {
static func main() async throws {
let client = OpenAIClient().profiles([
.init(
url: URL(string: "https://api.openai.com/v1/chat/completions")!,
token: ProcessInfo.processInfo.environment["OPENAI_API_KEY"] ?? "",
model: "gpt-4o-mini"
)
])
let session = SKILanguageModelSession(client: client)
let text = try await session.respond(to: "用一句话介绍 SKIntelligence")
print(text)
}
}运行:
OPENAI_API_KEY=<your_key> swift run- 流式输出与增量渲染
- 文档:
docs-dev/dev/Streaming.md
- 文档:
- 工具调用(Tool Calling)
- 文档:
docs-dev/dev/Getting-Started.md
- 文档:
- MCP 工具接入
- 文档:
docs-dev/dev/MCP.md
- 文档:
- 会话记忆(Memory)
- 文档:
docs-dev/dev/Getting-Started.md
- 文档:
- 文本检索/索引(SKITextIndex)
- 文档:
docs-dev/features/SKITextIndex.md
- 文档:
- 可以在
SKILanguageModelSession中注册工具,让模型按需触发函数调用。 - 内置工具实现位于:
Sources/SKITools/ - 入口文档:
docs-dev/dev/Getting-Started.md
import SKIntelligence
import SKIClients
import SKITools
let client = OpenAIClient().profiles([
.init(
url: URL(string: "https://api.openai.com/v1/chat/completions")!,
token: "<OPENAI_API_KEY>",
model: "gpt-4o-mini"
)
])
let session = SKILanguageModelSession(
client: client,
tools: [
SKIToolLocalDate(),
SKIToolLocalLocation()
]
)
let text = try await session.respond(to: "现在几点?并告诉我你所在位置")
print(text)let stream = try await session.streamResponse(to: "先告诉我现在时间,再告诉我城市")
for try await chunk in stream {
if let text = chunk.text {
print(text, terminator: "")
}
}import Foundation
import JSONSchemaBuilder
import SKIntelligence
struct WeatherTool: SKITool {
@Schemable
struct Arguments {
@SchemaOptions(.description("城市名,例如 Beijing"))
let city: String
}
@Schemable
struct ToolOutput: Codable {
@SchemaOptions(.description("天气描述"))
let summary: String
@SchemaOptions(.description("温度(摄氏度)"))
let temperatureC: Int
}
let name = "get_weather"
let description = "根据城市查询当前天气"
func displayName(for arguments: Arguments) async -> String {
"查询天气 [\(arguments.city)]"
}
func call(_ arguments: Arguments) async throws -> ToolOutput {
// 这里替换为你的真实天气 API 逻辑
.init(summary: "sunny", temperatureC: 26)
}
}注册并使用:
let session = SKILanguageModelSession(
client: client,
tools: [WeatherTool()]
)
let text = try await session.respond(to: "帮我查一下北京天气")
print(text)import SKIntelligence
import SKIClients
let client = OpenAIClient().profiles([
.init(
url: URL(string: "https://api.openai.com/v1/chat/completions")!,
token: "<OPENAI_API_KEY>",
model: "gpt-4o-mini"
)
])
let manager = SKIMCPManager.shared
try await manager.register(
id: "filesystem-server",
endpoint: URL(string: "http://localhost:3000/sse")!
)
let mcpTools = try await manager.getAllTools()
let session = SKILanguageModelSession(client: client)
await session.register(mcpTools: mcpTools)
let text = try await session.respond(to: "列出当前目录文件")
print(text)let session = SKILanguageModelSession(client: client)
await session.register(mcpTools: try await SKIMCPManager.shared.getAllTools())
_ = try await session.respond(to: "先查看目录")
let followup = try await session.respond(to: "再读取 README.md 前 20 行")
print(followup)- 提供 ACP Agent/Client/Transport 与
ski acpCLI 工作流。 ski根命令显示 help;服务端入口为ski acp serve。- 终端用户安装(macOS):
# Homebrew Tap(推荐)
brew tap linhay/tap https://github.com/linhay/homebrew-tap
brew install linhay/tap/ski
# Homebrew(按发布版本安装单文件 formula)
brew install --formula https://github.com/linhay/SKIntelligence/releases/download/2.0.2/ski.rb
# 安装最新版本(从 GitHub Release 下载对应架构二进制)
curl -fsSL https://raw.githubusercontent.com/linhay/SKIntelligence/main/scripts/install_ski.sh | bash
# 或安装指定版本
curl -fsSL https://raw.githubusercontent.com/linhay/SKIntelligence/main/scripts/install_ski.sh | bash -s -- --version 2.0.2- 开发态(源码运行)常用命令:
# 查看命令帮助
swift run ski --help
# 启动 ACP 服务端(stdio)
swift run ski acp serve --transport stdio
# 以客户端连接并发起一次 prompt(stdio)
swift run ski acp client connect --transport stdio --cmd ski --args=acp --args=serve --args=--transport --args=stdio --prompt "hello"
# 启动 ACP 服务端(ws)
swift run ski acp serve --transport ws --listen 127.0.0.1:8900
# 以客户端连接并发起一次 prompt(ws)
swift run ski acp client connect --transport ws --endpoint ws://127.0.0.1:8900 --prompt "hello"# 终端 A:启动服务
swift run ski acp serve --transport stdio
# 终端 B:连接并发起请求
swift run ski acp client connect \
--transport stdio \
--cmd ski \
--args=acp --args=serve --args=--transport --args=stdio \
--prompt "请列出可用工具并执行一个示例"本仓库提供可直接给智能体(agents)使用的 skills 包:
- 技能源码目录:
skills/skintelligence/ - 分发包:
skills/dist/skintelligence.skill - 入口文件:
skills/skintelligence/SKILL.md - Release 下载页:
https://github.com/linhay/SKIntelligence/releases - 2.0.2 直链(发布后可用):
https://github.com/linhay/SKIntelligence/releases/download/2.0.2/skintelligence.skill
适用于支持技能包/SKILL.md 机制的 agent 运行环境。
可将 skintelligence.skill 导入你的 agent 平台,获得面向本仓库的测试、回归、发布编排等标准化工作流。
- Release 2.0.0
- Release 2.0.0 GitHub Short
- Release 2.0.0 GitHub Full
- Release 2.0.1 GitHub Short
- Release 2.0.2 GitHub Short
- 发布脚本:
scripts/release_major.sh