Deferred (async) tool approval: pause a turn and resume later
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 38/100
Hướng nghiên cứu
Bắt đầu với _chat_impl và _chat_impl_async trong chatlas/_chat.py, sau đó đọc phần xử lý phê duyệt công cụ trong chatlas/_tools.py và việc tuần tự hóa các yêu cầu đang chờ trong chatlas/_turn.py. Xem lại docs/tool-calling/approval.qmd và theo dõi luồng phê duyệt đồng bộ hiện có. Done cần bao quát một thiết kế tạm dừng/tiếp tục được xác định rõ cho các chat đồng bộ và streaming, đồng thời giữ nguyên hành vi từ chối hiện tại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Motivation
chatlas already supports synchronous tool approval: raising ToolRejectError from a Chat.on_tool_request() callback (chatlas/_tools.py) rejects a call before it's invoked (see docs/tool-calling/approval.qmd, which currently ends with "### Chatbots — Coming soon"). But this only works when the approval decision is available immediately, in-process — the callback in _invoke_tool/_invoke_tool_async (chatlas/_chat.py) must return synchronously. There's no way to pause a turn mid-tool-loop, return control to the caller (e.g. a Shiny app rendering an "Approve/Deny" button, or a human who reviews the request hours later), and resume the same conversation once a decision arrives.
Three frameworks now solve exactly this: llm 0.32a3's llm.PauseChain mechanism (https://llm.datasette.io/en/latest/changelog.html), Pydantic AI's requires_approval=True tools that raise ApprovalRequired, ending the run with a DeferredToolRequests object resumed later via DeferredToolResults (https://ai.pydantic.dev/deferred-tools/), and LangChain's HumanInTheLoopMiddleware / interrupts. chatlas's own docs flag this gap already ("Chatbots: Coming soon" in approval.qmd), so this issue proposes closing it.
Proposed approach
import chatlas as ctl
chat = ctl.ChatAnthropic()
def delete_file(path: str):
"Delete a file"
...
# Mark a tool (or a specific request) as requiring deferred approval,
# analogous to Pydantic AI's `requires_approval=True`.
chat.register_tool(delete_file, annotations={"destructiveHint": True}, requires_approval=True)
result = chat.chat("Delete scratch.csv")
# `.chat()`/`.stream()` returns/raises early instead of looping forever:
if chat.pending_approvals:
for req in chat.pending_approvals: # list[ContentToolRequest]
print(req.name, req.arguments)
# ... hand `req.id` to a UI, persist `chat.export_state()` if the process
# might restart, wait for a human ...
# Resume with decisions, keyed by ContentToolRequest.id
chat.resume(
approvals={req.id: True}, # or ToolRejectError(reason) to deny
)
Implementation sketch, grounded in the existing tool loop:
_chat_impl/_chat_impl_asyncinchatlas/_chat.pyiterateturn.contentsforContentToolRequests and call_invoke_tool/_invoke_tool_asyncsynchronously. A deferred request would short-circuit that loop: leave theContentToolRequestin the lastAssistantTurnwithout a matchingContentToolResult, record it in a newChat._pending_approvals: dict[str, ContentToolRequest], and return/stop the generator instead of raising (deliberately distinct fromToolNotInvokedErrorinchatlas/_turn.py, which represents an abandoned request, not a paused one).- A new
Tool.requires_approvalflag (chatlas/_tools.py) or anon_tool_requestcallback that can raise/return a newToolDeferError(parallel toToolRejectError) marks a request as deferred rather than rejected. Chat.resume(approvals=...)suppliesbool | ToolRejectErrorper request id, constructs the resultingContentToolResults (reusing_handle_tool_error_resultfor denials), appends aUserTurn, and re-enters_chat_impl.Turn/AssistantTurn(chatlas/_turn.py) already serializes cleanly via pydantic; a turn with danglingContentToolRequests round-trips today (seecomplete_dangling_tool_requests), so persisting a paused chat via the save/load mechanism from a companion issue should "just work" as long as_pending_approvalsis reconstructed from the last turn on load rather than stored separately.
Explicitly out of scope: durable, cross-process-restart workflow engines (LangGraph-style checkpointing with retries/queues). This is in-process/session-level pause-resume only — if the process dies, the caller is responsible for persisting turns and resuming with a fresh Chat.
Alternatives / prior art
- ellmer has no equivalent issue yet (searched
tidyverse/ellmerfor "approval", "human in the loop", "pause resume" — no hits), so this would be a case of chatlas leading rather than following ellmer, worth flagging upstream once designed. - Keep the existing synchronous
ToolRejectErrorpath unchanged; this is additive.
Open questions
- Should deferral be declared per-tool (
register_tool(..., requires_approval=True)) or per-request (raised dynamically fromon_tool_request, so the same tool can be sometimes-deferred based on arguments)? Pydantic AI supports both. - How does this interact with streaming (
.stream())? Presumably the generator ends cleanly at the pause point. - Should
chat.pending_approvalspower a first-class shinychat affordance, or stay a plain data structure that app authors wire up themselves? - Timeout/expiry semantics for a request that's never resumed?
Drafted from a competitive review of llm / Pydantic AI / LangChain / LiteLLM (July 2026); filed via Claude Code on behalf of @cpsievert.
- Ngôn ngữ chính
- Python
- Star
- 179
- Fork
- 32
- Merge trung bình
- 1 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 10
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của posit-dev/chatlas
-
A streaming text delta that repeats everything streamed so far is missing from the recorded turnCó thể đã có người làm @cpsievert đã nhận 81 ngày trước. Đang mởai-triage:done Priority: Medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-triage:needs-review documentation
Độ khó 2/5 1-2 ngày Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-triage:done Priority: Low
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của posit-dev/chatlas
Issue tương tự
-
bot-triaged module: decompositions module: edge cases module: int overflow module: primTorch oncall: pt2 triage review
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[TV SHOW]: Dynasty (1981)Đang mởcountry:US rating:6 request-theme type:TV SHOW
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
LizardByte/ThemerrDB#10501 · 1 bình luận ·
-
triage/confirmed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
agentscope-ai/agentscope#4563 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
comp/desktop desktop/chat P3 type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
NousResearch/hermes-agent#164451 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
external integration integration-submission
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
langchain-ai/docs#8426 ·
Maintainer thường phản hồi trong vòng 1 ngày