← All courses ← Course home

Lesson 02 of 05

Name context, tools, model, guardrail

Use four hop names on every AI request: context pack, tool call, model, and guardrail. Keep the names stable.

Agent brief (llms.md)

Stable names let two engineers read the same trace. Use these four, in this order, unless a hop did not run.

1Context pack
1Context pack
2Tool call
1Context pack
2Tool call
3Model
1Context pack
2Tool call
3Model
4Guardrail
HopWhat you timeWhat goes wrong
Context packBuild instructions, attachments, and history for this requestA long transcript, a fat Dynamic Profile, or a late disk read
Tool callEach tool the session invoked, including your code inside the toolA slow fetch, a retry loop, or the wrong tool
ModelThe Foundation Models inference itselfA long prompt, a profile switch that drops the KV cache, or a PCC round trip
GuardrailYour check after the model, before the UIA blocked reply, a retry, or a silent rewrite
enum AIHop: String, Sendable {
    case request = "ai.request"
    case contextPack = "ai.context_pack"
    case tool = "ai.tool"
    case model = "ai.model"
    case guardrail = "ai.guardrail"
}

func answer(_ question: String, session: LanguageModelSession) async throws -> String {
    // Same four names you will wrap with OSSignposter in lesson 04.
    let packed = packContext(question)          // ai.context_pack
    let reply = try await session.respond(to: packed) // ai.model (tools nest under this)
    return try applyGuardrail(reply)            // ai.guardrail
}

Context pack includes Dynamic Instructions and any historyTransform you run. Tool call includes Apple system tools and your tools. Model is the inference lane you will see in Instruments. Guardrail is yours. Apple does not ship your product policy.

Put the prompt version and the profile name on the request, not inside the hop name. Hop names stay short. Version prompts like product copy is where those versions live.

Rule. Same four hop names in every feature. Do not invent a new name per screen.

Next, see what Apple already draws for you.

Key concepts

  • The four hops in order are context pack, tool call, model, and guardrail.
  • Context pack includes instructions, attachments, history, and historyTransform.
  • Tool call includes Apple system tools and your tools.
  • Prompt version and profile name go on the request, not in hop names.

Takeaways

  • Use the same four hop names in every feature.
  • Put prompt version and profile name on request attributes.
  • Dynamic Instructions and history work belong in context pack.