Skip to content

feat: session-level "always allow" for tool approvals - #7

Open
Feelings0220 wants to merge 1 commit into
mainfrom
claude/kagent-session-approvals
Open

Feelings0220 wants to merge 1 commit into
mainfrom
claude/kagent-session-approvals

Conversation

@Feelings0220

Copy link
Copy Markdown
Owner

概述

工具审批卡片新增 Always allow (session) 按钮:本次批准后,同一会话内该工具后续调用不再弹出审批,直接执行。会话结束后失效(作用域严格为单个会话)。

实现

Go 运行时(go/adk)

  • pkg/a2a/hitl.go:HitlConfirmationPayload 新增 always_allow 字段,随 HITL 决策消息透传(ToMap / ParseHitlConfirmationPayload / ProcessHitlDecision 全链路)。
  • pkg/agent/approval.go:
    • 新增会话状态键 kagent_approved_tools(无 app:/user: 前缀 ⇒ 会话级作用域)。
    • MakeApprovalCallback:调用前先查会话允许列表,命中则跳过确认;批准时若 payload 带 always_allow=true 则把工具名记入允许列表。
  • pkg/agent/approval_test.go:表驱动测试 7 个用例(未纳管工具直通 / 首次请求确认 / 普通批准 / always_allow 记忆 / 已记忆跳过 / JSON 回环形状 / 拒绝返回原因)。

UI

  • ToolDisplay.tsx:审批卡片新增次级按钮 "Always allow (session)"。
  • ToolCallDisplay.tsx / ChatMessage.tsx / ChatInterface.tsx:onApproveAlways 回调逐层下传,最终发送 { decision_type: "approve", always_allow: true }。

验证

  • go build ./adk/...、go test ./adk/pkg/agent/ ./adk/pkg/a2a/ ✅(7/7 新用例通过)
  • npx tsc --noEmit(源代码无新增错误)、npx jest(282 通过)、npx eslint(改动文件 0 问题)、npm run build ✅

设计文档

见 reports/session-approvals-plan.md。

🤖 Generated with Claude Code

https://claude.ai/code/session_016d9SxeefoRSLZmQ1oKo17j


Generated by Claude Code

Adds an 'Always allow (session)' option to the tool approval card. When
chosen, the approval decision carries always_allow=true through the HITL
payload; the Go runtime records the tool name in session state
(kagent_approved_tools) and skips the confirmation round-trip for that
tool for the rest of the session.

- go/adk hitl: plumb always_allow through HitlConfirmationPayload
- go/adk approval callback: consult/record session allow list
- UI: new secondary button on the approval card wired through
  ToolCallDisplay/ChatMessage/ChatInterface

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016d9SxeefoRSLZmQ1oKo17j
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants