Swift Examples

July 17, 2026 · View on GitHub

Runnable Swift scripts for the AgentSDK, mirroring the TypeScript and Python SDK examples.

Prerequisites

  • macOS 14+ with Swift 6.0+
  • An OpenAI or OpenRouter API key

Set your API key:

export OPENAI_API_KEY="sk-..."

Run

From the AgentSDK directory:

swift run 01-hello-agent
swift run 02-streaming-query
swift run 03-code-reviewer
swift run 04-bash-command
swift run 05-file-editor
swift run 06-prompt-skills
swift run 07-direct-skills
swift run 08-memory-management
swift run 10-multi-tool-reasoning
swift run 13-permissions
swift run 20-sdlc-discovery-plan
swift run 21-sdlc-gated-implementation
swift run 22-sdlc-release-readiness
swift run 23-system-prompts
swift run 24-high-level-agent
swift run 25-structured-json
swift run 27-autoresearch-ledger
swift run loop-strategies
swift run sdk-control-features
swift run basic-agent

Example Index

#FileDescription
0101-hello-agent.swiftMinimal prompt with Runner.runSync()
0202-streaming-query.swiftReal-time event streaming with Runner.runStream()
0303-code-reviewer.swiftFile-aware review with edit capabilities
0404-bash-command.swiftShell command execution flow
0505-file-editor.swiftFile editing with permission routing
0606-prompt-skills.swiftSkills referenced in prompt text
0707-direct-skills.swiftDirect skill names via customInstructions
0808-memory-management.swiftMemory persistence across sessions
1010-multi-tool-reasoning.swiftMulti-step codebase analysis with multiple tools
1313-permissions.swiftPermission modes: yolo, ask, deny comparison
2020-sdlc-discovery-plan.swiftSDLC discovery and planning phase
2121-sdlc-gated-implementation.swiftGated implementation: plan → review → execute
2222-sdlc-release-readiness.swiftRelease readiness check with tool summary
2323-system-prompts.swiftSystem prompt append/replace configuration
2424-high-level-agent.swiftHigh-level Agent API with clean lifecycle
2525-structured-json.swiftStructured JSON output with Codable validation
2727-autoresearch-ledger.swiftTyped replayable autoresearch lifecycle and ledger operations
loop-strategies.swiftAll four loop strategies compared
sdk-control-features.swiftRuntime configuration and control methods
basic-agent.swiftFull agent setup with all configuration options

Examples that create or edit files use /tmp/ for scratch output.