feat: update permission handling to delegate event context in guarded tools#9001
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
astrbot-docs | 3828ebd | Commit Preview URL Branch Preview URL |
Jun 25 2026, 08:19 AM |
There was a problem hiding this comment.
Code Review
This pull request modifies FunctionToolManager to pass the event object (extracted from context.context.event) instead of the full context to tool handlers, updating the associated unit tests accordingly. Feedback suggests using defensive attribute retrieval (getattr) when accessing context.context.event to prevent potential AttributeError exceptions if context or its nested properties are None.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| # @filter.llm_tool decorated tools have a handler attribute, which is the actual callable. | ||
| if self._wrapped.handler is not None: | ||
| result = self._wrapped.handler(context, **kwargs) | ||
| event = context.context.event |
There was a problem hiding this comment.
To prevent potential AttributeError exceptions when context is None or does not contain the expected nested attributes, it is safer to use defensive attribute retrieval (e.g., using getattr). This aligns with defensive programming practices for handling nullable or duck-typed references.
| event = context.context.event | |
| event = getattr(getattr(context, "context", None), "event", None) |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
FunctionToolManager.call, the handler path now assumescontext.context.eventis always present; consider adding a small guard or clearer type hints aroundcontextto avoid brittle attribute access when used in different calling environments. - For the legacy
runfallback, ensure the implementation actually invokesrun(event, **kwargs)and handles coroutine/async-generator results in a similar way to the handler path to keep tool execution behavior consistent across interfaces.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `FunctionToolManager.call`, the handler path now assumes `context.context.event` is always present; consider adding a small guard or clearer type hints around `context` to avoid brittle attribute access when used in different calling environments.
- For the legacy `run` fallback, ensure the implementation actually invokes `run(event, **kwargs)` and handles coroutine/async-generator results in a similar way to the handler path to keep tool execution behavior consistent across interfaces.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Modifications / 改动点
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Delegate event objects instead of full contexts to tool handlers and extend tool invocation compatibility in the function tool manager.
Enhancements:
Tests: