Conversation
审阅者指南此PR引入了一个新AI目标域模型和持久层,将GoalManager集成到核心逻辑管道中,扩展了意识控制模式,增加了“manage_goals”操作,并在提示中显示当前目标,以及少量日志清理。 文件级变更
提示和命令与Sourcery交互
自定义您的体验访问您的仪表盘以:
获取帮助Original review guide in EnglishReviewer's GuideThis PR introduces a new domain model and persistence layer for AI goals, integrates a GoalManager into the core logic pipeline, expands the consciousness-control schema with a “manage_goals” action, and surfaces current goals in prompts, alongside minor logging cleanups. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Summary of Changes
Hello @Dax233, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a new "Goal Management" capability for the AI system, allowing it to dynamically set, track, and manage its own short-term objectives. This enhancement aims to improve the AI's ability to maintain focus and pursue specific tasks by integrating goal awareness directly into its decision-making and prompt generation processes, backed by persistent storage.
Highlights
- Core Goal Management Logic: A new
GoalManagercomponent has been implemented to handle the creation, retrieval, and completion of AI-defined goals. - Persistent Storage for Goals: Dedicated data models (
GoalDocument) and aGoalStorageServicehave been added to ensure that AI goals are persistently stored and retrieved from the database. - Integrated AI State Awareness: The
AIStateManagernow incorporates theGoalManager, and the system prompt template has been updated to expose current goals to the AI, enabling goal-oriented reasoning. - AI-Driven Goal Manipulation: The
decision_dispatchernow supports newmanage_goalscommands, allowing the AI to programmatically add or remove its own goals based on its internal logic and evolving needs. - Refactored State Management: The
AIStateManagerhas been streamlined by removing theget_current_state_for_promptmethod, centralizing state initialization and management around the newinitializemethod andGoalManager.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
AI, with purpose, takes its flight, Goals it sets, both day and night. From code's deep core, new thoughts ignite, To guide its path, and make things right.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Hey @Dax233 - 我已审阅了你的更改,发现了一些需要解决的问题。
- 在
_handle_goal_management中,你调用了异步的add_goals/remove_goals方法而没有await它们——请添加await以确保这些操作在继续之前完成。 - 由于
add_goals和remove_goals返回已处理的 ID 列表,请考虑使用这些返回的 ID 进行更精确的日志记录或下游逻辑,而不是仅仅记录输入长度。
供AI代理使用的提示
请解决此代码审查中的评论:
## 总体评论
- 在 `_handle_goal_management` 中,你调用了异步的 `add_goals`/`remove_goals` 方法而没有 `await` 它们——请添加 `await` 以确保这些操作在继续之前完成。
- 由于 `add_goals` 和 `remove_goals` 返回已处理的 ID 列表,请考虑使用这些返回的 ID 进行更精确的日志记录或下游逻辑,而不是仅仅记录输入长度。
## 单独评论
### 评论 1
<location> `src/core_logic/goal_manager.py:60` </location>
<code_context>
+ f"下一个ID将是 G{self._next_id}。"
+ )
+
+ def _generate_next_id(self) -> str:
+ """生成一个格式化的、唯一的、递增的目标ID."""
+ goal_id = f"G{self._next_id}"
</code_context>
<issue_to_address>
`_next_id` 可能存在并发问题。
并发的 `add_goals` 调用可能由于非原子递增而导致重复的 ID。请使用原子计数器或数据库生成的 ID 来防止这种情况。
建议的实现:
```python
self._next_id = max_id_num + 1
self._id_lock = threading.Lock()
logger.info(
f"GoalManager 初始化完成,加载了 {len(self._goals)} 个活动目标。"
f"下一个ID将是 G{self._next_id}。"
)
```
```python
def _generate_next_id(self) -> str:
"""生成一个格式化的、唯一的、递增的目标ID."""
with self._id_lock:
goal_id = f"G{self._next_id}"
self._next_id += 1
return goal_id
```
如果文件中尚未包含 `import threading`,则需要将其添加到文件顶部:
```python
import threading
```
如果您的环境是异步的,并且您期望来自异步协程(而不是线程)的并发访问,请考虑使用 `asyncio.Lock` 而不是 `threading.Lock`。请相应地调整锁定机制。
</issue_to_address>帮助我变得更有用!请点击每个评论旁边的 👍 或 👎,我将根据您的反馈改进您的评论。
Original comment in English
Hey @Dax233 - I've reviewed your changes and found some issues that need to be addressed.
- In _handle_goal_management you’re calling the async add_goals/remove_goals methods without awaiting them—add awaits to ensure those operations complete before moving on.
- Since add_goals and remove_goals return lists of processed IDs, consider using those returned IDs for more precise logging or downstream logic instead of just logging the input length.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In _handle_goal_management you’re calling the async add_goals/remove_goals methods without awaiting them—add awaits to ensure those operations complete before moving on.
- Since add_goals and remove_goals return lists of processed IDs, consider using those returned IDs for more precise logging or downstream logic instead of just logging the input length.
## Individual Comments
### Comment 1
<location> `src/core_logic/goal_manager.py:60` </location>
<code_context>
+ f"下一个ID将是 G{self._next_id}。"
+ )
+
+ def _generate_next_id(self) -> str:
+ """生成一个格式化的、唯一的、递增的目标ID."""
+ goal_id = f"G{self._next_id}"
</code_context>
<issue_to_address>
Potential concurrency issue with _next_id.
Concurrent add_goals calls could result in duplicate IDs due to non-atomic increments. Use an atomic counter or database-generated IDs to prevent this.
Suggested implementation:
```python
self._next_id = max_id_num + 1
self._id_lock = threading.Lock()
logger.info(
f"GoalManager 初始化完成,加载了 {len(self._goals)} 个活动目标。"
f"下一个ID将是 G{self._next_id}。"
)
```
```python
def _generate_next_id(self) -> str:
"""生成一个格式化的、唯一的、递增的目标ID."""
with self._id_lock:
goal_id = f"G{self._next_id}"
self._next_id += 1
return goal_id
```
You need to add `import threading` at the top of the file if it is not already present:
```python
import threading
```
If your environment is async and you expect concurrent access from async coroutines (not threads), consider using `asyncio.Lock` instead of `threading.Lock`. Adjust the locking mechanism accordingly.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
本次代码审查主要关注新引入的目标管理功能。整体实现结构清晰,将目标管理逻辑有效地分离到了 GoalManager 和 GoalStorageService 中,并与现有的状态管理和决策流程进行了整合。审查中发现一个严重的功能性 bug,即在 decision_dispatcher.py 中调用异步函数时缺少 await,这将导致目标管理功能无法正常工作。此外,我还提出了一些关于性能优化和降低代码耦合度的建议,以提高代码的健壮性和可维护性。修复关键问题后,此拉取请求将是一次出色的功能增强。
Sourcery 总结
通过定义新的数据库模型和服务,将 GoalManager 连接到核心 AI 状态和决策工作流中,并在提示和模式中暴露目标控制,从而引入短期目标管理功能。
新功能:
改进:
杂项任务:
goal_storage_service添加到服务容器初始化中Original summary in English
Summary by Sourcery
Introduce a short-term goal management feature by defining new database models and services, connecting a GoalManager into the core AI state and decision workflows, and exposing goal controls in prompts and schemas
New Features:
Enhancements:
Chores: