This directory contains a port of the pi-mono project from Mario Zechner to Swift, as I need to embed this into an iPad app:
https://github.com/badlogic/pi-mono
It is split up slightly differently.
PiSwift supports delegating work to specialized subagents without spawning a subprocess. Subagents are defined by user-editable Markdown files and run in-process with isolated context.
- User agents:
~/.pi/agent/agents - Project agents:
.pi/agents(nearest parent of the current working directory)
Each agent is a .md file with YAML-style frontmatter. The body becomes the agent’s system prompt.
Example:
---
name: worker
description: General-purpose subagent
model: gpt-5.2
tools: read,edit,write,bash
outputFormat: |
## Completed
## Files Changed
## Notes
---
You are a worker agent with full capabilities.
Supported frontmatter keys:
name(required): agent name used in tool calls.description: shown in listings and error messages.tools: comma-separated tool names. Useallto enable all built-in tools (excludingsubagent).model: model pattern (e.g.openai/gpt-5.2orgpt-5.2).outputFormat: appended to the system prompt as an “Output format” section.
The subagent tool supports three modes:
- Single:
{ "agent": "worker", "task": "Summarize the tests in Tests/." }
- Parallel:
{ "tasks": [
{ "agent": "worker", "task": "Scan Sources/ for concurrency violations." },
{ "agent": "reviewer", "task": "Review README for updates." }
] }
- Chain:
{ "chain": [
{ "agent": "planner", "task": "Plan the fix for X." },
{ "agent": "worker", "task": "Implement the plan:\n{previous}" }
] }
Optional parameters:
agentScope:user,project, orboth(default:user).cwd: per-task working directory (single/parallel/chain items).
- Subagents run in-process; no subprocess is spawned.
- If
toolsis omitted, the default coding toolset is used. - If
modelis omitted, the main agent’s selected model is used.
Prompt templates are Markdown files that expand when you type /name in the prompt.
Locations:
- User templates:
~/.pi/agent/prompts - Project templates:
.pi/prompts(nearest parent of the current working directory)
Template body supports $1, $2, $ARGUMENTS, and $@ substitutions.
When no model is selected, the default fallback order is:
- anthropic:
claude-sonnet-4-5 - openai:
gpt-5.2 - openai-codex:
gpt-5.2-codex - opencode:
claude-opus-4-5
This port uses strict concurrency (no @unchecked Sendable). Data races are fixed at the source.
Errors use Swift enums that conform to LocalizedError instead of NSError.
See examples/subagents/fetcher.md for a sample agent that uses curl via the bash tool to fetch files from the internet.