Skip to content

Add on_request_start() / on_request_end() hooks to Chat #413

Description

@cpsievert

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

Activity

  1. added
    Priority: LowLow-impact bug, docs polish, papercut, or unclear low-severity request.
    ai-triage:doneMarks an issue whose AI triage workflow is complete.
    on Sep 3, 2026
  2. AbarnaaSree commented on Sep 9, 2026

    @AbarnaaSree

    Hi, I’d like to work on this issue. I can implement the on_request_start() and on_request_end() hooks for both chat() and chat_async(), integrate them into the model request/tool-calling loop, and add tests covering requests with and without tool calls. Please let me know if I can take this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: LowLow-impact bug, docs polish, papercut, or unclear low-severity request.ai-triage:doneMarks an issue whose AI triage workflow is complete.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions