Summary
ellmer recently added on_request_start() / on_request_end() hooks on Chat (tidyverse/ellmer#1052). These fire around each model request within the tool-calling loop (not just around individual tool calls), letting callers inspect or rewrite the conversation between tool rounds within a single chat()/chat_async() call — e.g. to compact turns as the context window fills up.
chatlas currently only exposes tool-level callbacks: Chat.on_tool_request() and Chat.on_tool_result() (see chatlas/_chat.py). There's no equivalent hook that fires before/after each model request in the tool loop.
Proposed behavior (mirroring ellmer)
on_request_start(callback): callback receives the list of turns about to be sent, fired at the top of each tool-loop iteration (before the request is dispatched). Return value (if any) could allow rewriting the turns, mirroring ellmer's design.
on_request_end(callback): callback receives the resulting turn after each model request completes.
- Should fire correctly in both sync (
chat()) and async (chat_async()) paths, and work whether or not a tool loop actually runs.
References
Summary
ellmer recently added
on_request_start()/on_request_end()hooks onChat(tidyverse/ellmer#1052). These fire around each model request within the tool-calling loop (not just around individual tool calls), letting callers inspect or rewrite the conversation between tool rounds within a singlechat()/chat_async()call — e.g. to compact turns as the context window fills up.chatlas currently only exposes tool-level callbacks:
Chat.on_tool_request()andChat.on_tool_result()(seechatlas/_chat.py). There's no equivalent hook that fires before/after each model request in the tool loop.Proposed behavior (mirroring ellmer)
on_request_start(callback): callback receives the list of turns about to be sent, fired at the top of each tool-loop iteration (before the request is dispatched). Return value (if any) could allow rewriting the turns, mirroring ellmer's design.on_request_end(callback): callback receives the resulting turn after each model request completes.chat()) and async (chat_async()) paths, and work whether or not a tool loop actually runs.References
on_request_start()andon_request_end()hooks tidyverse/ellmer#1052chatlas/_chat.py(on_tool_request,on_tool_result,_on_tool_request_callbacks,_on_tool_result_callbacks)