ChappieHarness, then attach a ChappieHostTool handler to the client.
Register a host tool
Inspect tool call arguments
Every handler receives aChappieToolCall value. Use argumentsJSON to get a parsed ChappieJSONValue? rather than decoding the raw JSON string yourself.
ChappieToolCall fields
ChappieToolCall fields
String?
The response-level output item ID assigned by the backend. May be
nil for some transport paths.String
The unique call identifier used to correlate the result with the request. Always present.
String
The tool name as declared in the harness — used by the registry to route to your handler.
String
The raw JSON string the model produced for this call’s input arguments.
ChappieJSONValue?
A convenience computed property that parses
arguments into a ChappieJSONValue tree. Returns nil if the string is not valid JSON.ChappieToolResult. Because ChappieToolResult conforms to ExpressibleByStringLiteral, you can return a plain string literal from your handler when you don’t need the output: label:
ChappieJSONValue — schema building and argument parsing
ChappieJSONValue is the enum used both for defining input schemas and for parsing the arguments the model sends back. Its cases map one-to-one with JSON primitives:
Use nested
.object and .array values to express any JSON Schema structure your tool requires. ChappieJSONValue is Codable, so you can also decode model-produced arguments directly.
Tool approval policies
By default Chappie runs tools automatically. UseChappieToolPolicy to require user approval or block a tool entirely.
Policy factories
Policy factories
static property
Runs the tool without prompting. This is the default when you omit the
policy parameter.static factory
Emits an
.approvalRequested stream event and calls your toolApprovalHandler before running the tool. Provide at least one ChappieToolPermissionScope to describe what the tool accesses.static factory
Blocks the tool unconditionally. The handler is never called; the stream receives a
.toolCallCompleted event with status == .denied.Permission scopes
Pass one or moreChappieToolPermissionScope values to .ask or .deny so your approval UI can present a meaningful description of what the tool needs:
Requiring approval before a destructive action
Providing an approval handler
When any tool uses.ask, supply a toolApprovalHandler closure on the client. Chappie calls it with a ChappieApprovalRequest describing the pending call — display your confirmation UI there, then return a ChappieApprovalDecision:
Observing tool execution with stream events
When you useclient.stream(_:) or client.streamHandle(_:), Chappie emits stream events at each stage of tool execution so your UI can show real-time feedback:
Tool call round limit
Chappie allows up to 6 tool-call rounds persend, stream, or response call. If the model requests more consecutive rounds than that limit, the client throws ChappieClientError.toolLoopLimitExceeded. Design your tools to return complete, actionable results so the model can reach a final answer within a few rounds.