Local-first AI Agent Runtime for Swift
Build powerful, safe, and efficient AI agents that run entirely on-device with Apple's Foundation Models
Features โข Quick Start โข Architecture โข Examples โข Documentation
Colony is a Deep Agents-style runtime built from the ground up for local-first AI agent execution. Unlike cloud-dependent solutions, Colony runs entirely on your user's device using Apple's on-device Foundation Modelsโno API keys, no network latency, no privacy concerns.
| Feature | Colony | Other Agents |
|---|---|---|
| Privacy | 100% on-device | Cloud-dependent |
| Latency | Zero network round-trips | API calls add 100-500ms+ |
| Cost | Free forever | Pay-per-use APIs |
| Offline | Works without internet | Requires connectivity |
| Safety | Capability-gated tools with human approval | Often unrestricted |
- Capability-gated tools โ Tools only available when explicitly enabled
- Human-in-the-loop approval โ Approve, reject, or cancel risky tool calls
- Isolated subagents โ Delegate to sandboxed runtime instances
- Smart context management โ 4k token budget with automatic compaction
- Intelligent summarization โ Offloads old context to
/conversation_history - Large result eviction โ Auto-offloads big outputs to
/large_tool_results
๐ Filesystem โ ls, read_file, write_file, edit_file, glob, grep
๐ Planning โ write_todos, read_todos
๐ป Shell โ execute (sandboxed)
๐ Scratchbook โ scratch_read, scratch_add, scratch_update...
๐ฅ Subagents โ task (isolated delegation)// Strict 4k budget for on-device Foundation Models
profile: .onDevice4k
// Generous limits for cloud deployments
profile: .cloudโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Colony Runtime Loop โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โ preModel โโโโโถโ model โโโโโถโ routeAfterModel โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโโ โ
โ โฒ โ โ
โ โ โผ โ
โ โโโโโโดโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โtoolExec โโโโโโ tools โโโโโโ (interrupts?) โ โ
โ โโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Module Separation โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ ColonyCore โโโโโโโโโโโ Colony โ โ
โ โ (Pure Values) โ โ (Runtime/Orchestration)โ โ
โ โ โ โ โ โ
โ โ โข Capabilities โ โ โข Agent Graph โ โ
โ โ โข Configuration โ โ โข Foundation Models โ โ
โ โ โข Tool Contractsโ โ โข Subagent Registry โ โ
โ โ โข Scratchbook โ โ โข Run Control โ โ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ Built on HiveCore (../hive) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Swift 6.2
- iOS 26+ or macOS 26+
- Hive at
../hive
# Clone with Hive dependency
git clone https://github.com/christopherkarani/Colony.git
cd Colony
# Ensure ../hive exists (git clone https://github.com/christopherkarani/hive.git ../hive)
# Build & Test
swift package resolve
swift testimport Colony
@main
struct MyFirstAgent {
static func main() async throws {
// Check if on-device Foundation Models are available
guard ColonyFoundationModelsClient.isAvailable else {
print("Foundation Models not available on this device")
return
}
// Create a runtime with on-device 4k profile
let factory = ColonyAgentFactory()
let runtime = try factory.makeRuntime(
profile: .onDevice4k,
modelName: "test-model",
model: AnyHiveModelClient(ColonyFoundationModelsClient())
)
// Start the agent
let handle = await runtime.runControl.start(
.init(input: "List all Swift files in this project and summarize what they do.")
)
// Get the result
let outcome = try await handle.outcome.value
print(outcome)
}
}import Colony
let factory = ColonyAgentFactory()
let runtime = try factory.makeRuntime(
profile: .onDevice4k,
modelName: "test-model",
model: AnyHiveModelClient(ColonyFoundationModelsClient()),
configure: { config in
// Require approval for all tool calls
config.toolApprovalPolicy = .always
}
)
let handle = await runtime.runControl.start(
.init(input: "Create a deployment checklist at /deploy.md")
)
let outcome = try await handle.outcome.value
// Handle approval interrupt
if case let .interrupted(interruption) = outcome,
case let .toolApprovalRequired(toolCalls) = interruption.interrupt.payload {
print("๐ Approve these tools?", toolCalls.map(\.name))
// Approve, reject, or cancel
let resumed = await runtime.runControl.resume(
.init(
interruptID: interruption.interrupt.id,
decision: .approved // or .rejected / .cancelled
)
)
let finalOutcome = try await resumed.outcome.value
print(finalOutcome)
}let runtime = try factory.makeRuntime(
profile: .onDevice4k,
modelName: "test-model",
model: model,
filesystem: myFileSystem, // Enable filesystem tools
shell: myShellBackend, // Enable shell execution
subagents: myRegistry, // Enable subagent delegation
configure: { config in
// Customize capabilities
config.capabilities = [.planning, .filesystem, .scratchbook]
// Fine-tune approval policy
config.toolApprovalPolicy = .allowList([
"ls", "read_file", "scratch_read", "scratch_add"
])
}
)The Scratchbook is Colony's persistent memory system for tracking state across context windows:
// The agent can automatically:
// - Add notes: "Found 3 critical bugs in Auth.swift"
// - Track todos: "Fix race condition in NetworkManager"
// - Monitor tasks: "Refactoring Database layer (45% complete)"
// All items are persisted and survive context compaction
// Pinned items always stay visible in the context windowEvery major feature is backed by comprehensive tests:
| Behavior | Test Location |
|---|---|
| Tool approval interrupts + resume | ColonyAgentTests.swift, ColonyRunControlTests.swift |
| 4k token budget enforcement | ColonyContextBudgetTests.swift |
| History summarization + offload | ColonySummarizationTests.swift |
| Large tool result eviction | ColonyToolResultEvictionTests.swift |
| Scratchbook persistence | ColonyScratchbookCoreAndStorageTests.swift |
| Isolated subagent execution | DefaultSubagentRegistryTests.swift |
# Run all tests
swift test
# Run specific test
swift test --filter ColonyContextBudgetTests- CLAUDE.md โ Detailed architecture and development guide
- API Documentation (coming soon)
- Example Projects โ Research Assistant CLI
| Issue | Solution |
|---|---|
swift package resolve fails |
Verify ../hive/Package.swift exists |
foundationModelsUnavailable |
On-device models require iOS 26+/macOS 26+ |
| Missing tools in prompts | Check capability + backend wiring |
| Build errors | Ensure Swift 6.2 toolchain |
- SwiftPM package distribution (remove local
../hivedependency) - visionOS support
- Additional model provider integrations
- Visual debugging tools
- More built-in tool families
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please ensure your code follows the existing style and includes tests for new functionality.
This project is licensed under the MIT License - see the LICENSE file for details.
If you find Colony useful, please consider giving it a star! It helps others discover the project and motivates continued development.
Built with โค๏ธ for the Swift AI community