Skip to content

Commit 2e36c5d

Browse files
committed
update(docs): document chat send and structured output contracts
1 parent 46c3e70 commit 2e36c5d

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

Sources/AgentRunKit/Documentation.docc/Articles/AgentAndChat.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Key behaviors:
3838

3939
``Chat`` handles multi-turn conversations without requiring a finish tool. Each `send()` call makes one LLM request and returns the response with updated history. Tool calls in the response are not automatically executed; use `stream()` for tool execution.
4040

41+
When the model does call tools in a `send()` response, the returned history ends with an unexecuted tool-call batch. Passing that history straight back to `send()` throws `AgentError.malformedHistory` with reason `.unfinishedToolCallBatch`: execute the calls yourself and append a `.tool` message for each call id before the next turn, or use `stream()`, which runs the tool loop for you.
42+
4143
```swift
4244
let chat = Chat<EmptyContext>(client: client, systemPrompt: "You are a helpful assistant.")
4345
let (response, history) = try await chat.send("What is 2 + 2?")
@@ -52,6 +54,8 @@ let (result, _) = try await chat.send("Analyze: 'Great product!'", returning: Se
5254
print(result.score) // 0.95
5355
```
5456

57+
Structured sends suppress tools for that turn: the request carries an empty tool list so the model produces the JSON payload instead of tool calls.
58+
5559
``Chat`` also supports streaming via `stream()` and tool execution (up to `maxToolRounds` per send). When `stream()` exhausts `maxToolRounds`, it emits `.finished(reason: .maxIterationsReached(limit: maxToolRounds))` and completes normally. ``Chat`` does not perform compaction or manage token budgets.
5660

5761
## Choosing an Entry Point

Sources/AgentRunKit/Documentation.docc/Articles/StructuredOutput.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ let (report, history) = try await chat.send(
2525
print(report.conditions) // "Partly cloudy"
2626
```
2727

28+
A structured send carries an empty tool list, suppressing the chat's tools for that turn so the model returns the JSON payload rather than calling them. Decoding failures throw `AgentError.structuredOutputDecodingFailed`.
29+
2830
### LLMClient (Manual Decoding)
2931

3032
Use ``LLMClient/generate(messages:tools:responseFormat:requestContext:)`` directly when you need full control:

0 commit comments

Comments
 (0)