You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ee01804
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,8 +88,12 @@ async for event in result.get_tool_stream():
88
88
89
89
asyncfor call in result.get_tool_calls_stream():
90
90
print(call.name, call.arguments)
91
+
92
+
usage =await result.get_usage() # totals across every model call in the run
91
93
```
92
94
95
+
`get_response()` returns only the **final** round's response, so in a multi-round tool loop its `usage` covers one generation. `get_usage()` returns the aggregate across every model call the run made (`model_calls`, `input_tokens`, `output_tokens`, `total_tokens`, `cached_tokens`, `reasoning_tokens`, and `cost` when reported) — the same numbers as the `SessionEnd` hook's `total_usage`, with no hooks required. It never raises for a failed run, so it is safe in a `finally` block.
96
+
93
97
## Tool Variants
94
98
95
99
Regular tools execute automatically when the model emits a matching `function_call`.
@@ -115,6 +119,8 @@ analysis = tool(
115
119
)
116
120
```
117
121
122
+
Pass `strict=True` (or `False`) to forward provider strict-schema adherence onto the wire tool definition; omit it to keep the provider default. OpenAI-style strict mode requires every declared property to be listed as required.
123
+
118
124
Manual tools are advertised to the model but not auto-executed.
119
125
120
126
```python
@@ -191,9 +197,13 @@ The built-ins mirror the TypeScript package and OR together when provided as a l
191
197
192
198
When a stop condition fires while the model is still emitting tool calls, `call_model` makes one more turn with `tool_choice="none"` by default (tools stay in the request so the prompt-cache prefix survives) so the run ends with a natural-language answer. `allow_final_response` tunes this: `True` or omitted appends `DEFAULT_FINAL_RESPONSE_DIRECTIVE` as a user message, a non-empty string replaces the wording, `""` appends nothing, and `False` disables the extra turn entirely.
193
199
200
+
A forced `tool_choice` (`"required"`, a specific tool, or `allowed_tools` with `mode: "required"`) applies until a response made under it calls a tool; follow-up turns then send the relaxed form (`"auto"`, or the same `allowed_tools` set with `mode: "auto"`) so the model can answer in text. A tool can set the next turn's choice via `next_turn_params={"tool_choice": fn}` (for example to widen an `allowed_tools` set without changing `tools`, which keeps the prompt-cache prefix intact).
201
+
202
+
Tool calls are only executed from responses whose status is `completed`; a response cut off at `max_output_tokens` (status `incomplete`) ends the run with none of its calls executed.
203
+
194
204
## Format Compatibility
195
205
196
-
Use `from_claude_messages` / `to_claude_message` for Anthropic-style messages and `from_chat_messages` / `to_chat_message` for OpenAI Chat-style messages. Content that cannot be represented directly is carried as `unsupported_content` instead of being silently discarded.
206
+
Use `from_claude_messages` / `to_claude_message` for Anthropic-style messages and `from_chat_messages` / `to_chat_message` for OpenAI Chat-style messages (assistant `tool_calls` become `function_call` items, so replayed tool-calling history keeps each output paired with its call). Content that cannot be represented directly is carried as `unsupported_content` instead of being silently discarded.
0 commit comments