ResponseHandler
Tool(response_handler=...) or to a factory’s builder.
Four properties of when it runs:
- Only on success. HTTP failures and declared envelope failures have already raised, so a handler never sees an error payload.
- It must be
async def. A non-async callable raisesDeclarationErrorat build time, naming the function. - It is timed separately. Its cost lands in
ToolCall.handler_ms, and what it returns is whatcontext_bytesmeasures — so the saving is visible. - It is per tool. The shape of one endpoint’s response is not the shape of another’s.
Pagination declaration reads — the
object id behind a derived cursor, and has_more even when it is False —
and keep whatever the model needs to make the next call, which is usually an
id it would otherwise have to guess.
decode_base64url
str
required
The encoded string. APIs that hand back base64url almost never pad it — Gmail,
JWT segments, Microsoft Graph attachments — and
base64.urlsafe_b64decode
requires padding, so this adds it back.str
default:"\"replace\""
Passed to
bytes.decode. The default degrades rather than raising, because a
handler should not fail a whole call over one malformed part.html_to_text
script, style, head and title
content, turns block-level tags into line breaks, decodes character entities,
and collapses runs of blank lines.
Malformed input degrades to the stripped raw markup rather than raising.
Stdlib-only, on purpose: an HTML-to-text pass this shallow does not justify a
parser dependency.
Related
- What a call cost — measuring what a handler saved
- Packs — handlers written against eleven real APIs