← Agent building

Agent building · Reference project

Calendar Agent

From natural language to a real macOS Calendar: an engineering record of a Mac-first Personal Agent.

This is not an “LLM + Calendar API” demo. It is a real project built around Task, State, Tool Calling, Persistence, Verification, Remote Access, and Agent QA.

00 · PROJECT OVERVIEW

What did I build?

User
iPhone · Siri · Apple Watch
→
Shortcut
HTTPS
→
AgentRuntime
analysis · state · clarification · planner
→
Tool Execution Layer
MacAgentHost
→
EventKit
macOS Calendar
→
Verification
Final response

The user submits a natural-language session request, AgentRuntime manages task and parameter state, the Tool Execution Layer sends a constrained operation to MacAgentHost, EventKit creates real Calendar state, and Verification decides the final response.

Current capability status

✅ Calendar CreateImplemented

MacAgentHost + EventKit, followed by state verification.

✅ Calendar QueryImplemented

Currently used mainly for Create verification.

✅ Real EventKit ExecutionImplemented

The real execution boundary exists; the capability scope is still narrow.

✅ VerificationImplemented

Tool success is not automatically Task success.

✅ iPhone Shortcut / HTTPImplemented

The user entry point and HTTP API exist; device access needs separate acceptance.

🟡 Remote HTTPS / SiriIn progress

The code path exists; public and device regression is not claimed as complete.

🟡 Clarification / ResumeImplemented / device validation in progress

Implemented in code; real device validation is still pending.

⏳ Production LLMPlanned

DemoLLM is a deterministic development adapter.

⏳ Reminder / Update / DeletePlanned

Contracts exist, but these are not executable capabilities yet.

⏳ Mail / Files / BrowserRoadmap

Future Personal Agent capabilities.

01 · FROM IDEA TO PROTOTYPE

From idea to the first Agent Prototype

The first question was: if I speak a natural-language request to Siri, can my own agent understand it and operate Calendar? The first abstraction had three layers: Natural Language → Agent → Calendar Action.

UserRequest
    ↓
AgentRuntime
    ↓
LLM / Semantic Analysis
    ↓
Planner
    ↓
Mock Tool
    ↓
Final

The Mock Tool came first so the Agent Core, Task, Parameter, Planner, and Tool Contract could be validated before adding macOS permissions, EventKit, networking, and Siri.

02 · BUILDING THE AGENT CORE

What makes an agent more than an API?

“Create a one-hour meeting tomorrow at 3 PM” cannot simply become an API parameter. It must pass semantic analysis, task state, and planning. Parameters carry value, source, and status; tasks carry conversation, task, and step identity.

User Request
    ↓
Semantic Analysis
    intent = create
    object = calendar_event
    date = tomorrow
    start = 15:00
    duration = 60
    ↓
Task / Parameter State
    ↓
Planner → Tool Contract
IntentQuery, create, update, or delete?
StateNot plain key=value: parameters carry provenance and status.
IDsconversation_id · task_id · step_id · operation_id · execution_id

03 · CONNECTING TO THE REAL WORLD

From Mock Tool to a real macOS Calendar

A Mock Tool only proves that the agent believes it executed an operation. It cannot prove that Calendar changed. The execution boundary therefore moved into a native host with macOS permissions.

AgentRuntime → Tool Request
             → MacAgentHost.app
             → EventKit
             → macOS Calendar
             → query_calendar / Verification

The Python Runtime and the macOS Calendar permission boundary are different boundaries, so MacAgentHost, EventKit, and a JSON-lines contract connect them.

A real engineering turn

The persistent NSApplication lifecycle conflicted with subprocess.run timeouts. The boundary evolved into stdin request → stdout ToolResult → controlled termination.

04 · FROM MAC TO IPHONE & SIRI

From Mac localhost to Siri and iPhone

Running on a Mac was only the beginning. A Personal Agent needs to move from the Terminal to iPhone, Shortcuts, and Siri.

localhost 127.0.0.1:8000
        ↓
LAN access
        ↓
DHCP address changed
        ↓
stable HTTPS endpoint
        ↓
Cloudflare Named Tunnel → 127.0.0.1:8000

This path introduced authentication, Bearer tokens, HTTPS, a localhost-only Agent Server, and no public port 8000. Public and real-device connectivity still require separate acceptance.

05 · MULTI-TURN AGENT

From one-shot commands to a multi-turn agent

When the user says “Create a meeting tomorrow,” the agent must not guess. It enters waiting_clarification, asks a question, and uses the same conversation to find the original task.

same conversation → find waiting task
        ↓
same task_id → analyzing_clarification
        ↓
parameter merge → planning → tool → verification

Clarification Resume is implemented in code, but real iPhone/Siri multi-turn regression is still in progress.

06 · ARCHITECTURE EVOLUTION: V1 → V2

From Protocol V1 to V2: a real architecture reconciliation

Protocol V1 · historical / frozen
Client → Agent → Tool Request
       → Client executes Tool
       → Tool Result → Agent
Protocol V2 · current / canonical
Client → AgentRuntime
       → Tool Execution Layer
       → MacAgentHost → EventKit

As the real implementation formed, Specification ≠ Implementation and architecture drift became visible. That led to audit, reconciliation, an ADR, and Protocol V2. V1 was not deleted; it remains as historical context.

BoundaryClient-side execution → Runtime → Tool Execution Layer → MacAgentHost
IDsoperation_id = logical write; retry uses a new execution_id
ContractTool Request / Result become internal execution contracts.

07 · RELIABILITY & VERIFICATION

How does the agent prove it completed the task?

The core rule is: Tool Success ≠ Task Success. Only real-state Verification can justify Final.success.

Tool Execution → Tool Result
              ↓
       query_calendar / verify_state
              ↓
 compare event_id · title · start · end
              ↓
Verified → success | mismatch → failure | unknown → unknown

This boundary also covers operation_id, duplicate prevention, retry, unknown state, pre-execution safety, and real EventKit state. The system does not claim exactly-once.

08 · AGENT QA & EVALUATION

How do I test the agent?

Agent QA is not a final test run. It runs through the build: deterministic testing, Agent Evaluation, Observability, Integration, E2E, and Regression.

Agent QA
  • Deterministic Testing
  • Agent Evaluation
  • Observability
  • Integration / E2E
  • Regression
Read: Calendar Agent QA and test strategy →

09 · WHAT BROKE ALONG THE WAY

What broke along the way

问题暴露的问题最终改进
Event time shiftedTimezone contextExplicit IANA timezone
iPhone could not connectLocalhost boundaryHTTP / LAN
DHCP broke the ShortcutIP dependencyNamed Tunnel
Tool success was uncertainMissing verificationVerificationService
English request got Chinese replyLanguage propagationLanguage handling
Clarification answer disappearedResume / observabilityTraceability
V1 diverged from implementationArchitecture driftProtocol V2

NEXT · PERSONAL AGENT

Calendar is only the first capability

Next come a production LLM, an evaluation dataset, automated evaluation, and continuous evaluation; later come Reminder, Mail, Files, Obsidian, Browser, and Computer Use on the path to a Personal Agent.

Continue to Agent QA →