Add on_request_start() / on_request_end() hooks to Chat

未关闭
#413 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@AbarnaaSree 已经在做这个了。

开始于 2026年9月9日。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
68/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
python

调研方向

从 chatlas/_chat.py 开始,阅读 on_tool_request()、on_tool_result()、它们的 callback 存储方式,以及 chat() 和 chat_async() 路径。将提议的生命周期与 tidyverse/ellmer#1052 进行比较,然后定义每次模型请求的开始和结束 callback 行为,包括工具循环和无工具的情况。完成的标准是两条路径都能一致地提供并调用这些 hook。

由索引模型根据 Issue 内容生成。

描述

ai-triage:done Priority: Low

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

  • ellmer PR: tidyverse/ellmer#1052
  • chatlas tool-level callbacks for comparison: chatlas/_chat.py (on_tool_request, on_tool_result, _on_tool_request_callbacks, _on_tool_result_callbacks)
主要语言
Python
星标
179
派生
32
平均合并
1 天 3 小时
30 天内合并 PR
10

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

posit-dev/chatlas 的其他 Issue

查看 posit-dev/chatlas 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。