From 3c4072541f2bd10ae4ceb939ea81ac5bb23005e0 Mon Sep 17 00:00:00 2001 From: Rasic2 <1051987201@qq.com> Date: Sun, 21 Sep 2025 22:48:02 +0800 Subject: [PATCH 1/5] ci: improve update-pre-commit workflow by adding explicit permissions and conditional pull request creation --- .github/workflows/update-pre-commit.yml | 30 ++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/.github/workflows/update-pre-commit.yml b/.github/workflows/update-pre-commit.yml index 9d6a4310..868109e0 100644 --- a/.github/workflows/update-pre-commit.yml +++ b/.github/workflows/update-pre-commit.yml @@ -5,18 +5,19 @@ on: - cron: '0 0 * * 0' # 每周日 UTC 时间 00:00 workflow_dispatch: # 允许手动触发 +permissions: + contents: write + pull-requests: write + jobs: update-pre-commit: runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write steps: - name: Checkout code uses: actions/checkout@v4 with: - token: ${{ secrets.GITHUB_TOKEN }} + fetch-depth: 0 # 获取所有历史记录和分支 - name: Set up Python uses: actions/setup-python@v5 @@ -29,7 +30,18 @@ jobs: - name: Update pre-commit hooks run: pre-commit autoupdate - - name: Create Pull Request if changes + - name: Check for changes + id: changes + run: | + if git diff --exit-code .pre-commit-config.yaml; then + echo "changes=false" >> $GITHUB_OUTPUT + else + echo "changes=true" >> $GITHUB_OUTPUT + git diff .pre-commit-config.yaml + fi + + - name: Create Pull Request + if: steps.changes.outputs.changes == 'true' uses: peter-evans/create-pull-request@v5 with: commit-message: "chore: update pre-commit hooks" @@ -37,8 +49,10 @@ jobs: body: | Automated update of pre-commit hooks via pre-commit autoupdate. - **Changes:** - - Updated hook versions in .pre-commit-config.yaml - branch: "update/pre-commit-hooks" + **Changes made:** + - Updated versions in .pre-commit-config.yaml + branch: "update/pre-commit-hooks-$(date +%s)" + base: main # 根据你的默认分支修改,可能是 main 或 master labels: "dependencies" delete-branch: true + token: ${{ secrets.GITHUB_TOKEN }} From 40157a43f5339a94e51e7db7fc6e3d6cdf4719b2 Mon Sep 17 00:00:00 2001 From: Rasic2 <1051987201@qq.com> Date: Sun, 21 Sep 2025 22:51:00 +0800 Subject: [PATCH 2/5] chore: simplify update-pre-commit workflow by removing change detection step --- .github/workflows/update-pre-commit.yml | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/.github/workflows/update-pre-commit.yml b/.github/workflows/update-pre-commit.yml index 868109e0..dc53d274 100644 --- a/.github/workflows/update-pre-commit.yml +++ b/.github/workflows/update-pre-commit.yml @@ -2,8 +2,8 @@ name: Update pre-commit hooks on: schedule: - - cron: '0 0 * * 0' # 每周日 UTC 时间 00:00 - workflow_dispatch: # 允许手动触发 + - cron: '0 0 * * 0' + workflow_dispatch: permissions: contents: write @@ -17,7 +17,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: 0 # 获取所有历史记录和分支 + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v5 @@ -30,29 +30,14 @@ jobs: - name: Update pre-commit hooks run: pre-commit autoupdate - - name: Check for changes - id: changes - run: | - if git diff --exit-code .pre-commit-config.yaml; then - echo "changes=false" >> $GITHUB_OUTPUT - else - echo "changes=true" >> $GITHUB_OUTPUT - git diff .pre-commit-config.yaml - fi - - name: Create Pull Request - if: steps.changes.outputs.changes == 'true' uses: peter-evans/create-pull-request@v5 with: commit-message: "chore: update pre-commit hooks" title: "chore: update pre-commit hooks" body: | Automated update of pre-commit hooks via pre-commit autoupdate. - - **Changes made:** - - Updated versions in .pre-commit-config.yaml - branch: "update/pre-commit-hooks-$(date +%s)" - base: main # 根据你的默认分支修改,可能是 main 或 master + branch: "update/pre-commit-hooks" + base: main labels: "dependencies" delete-branch: true - token: ${{ secrets.GITHUB_TOKEN }} From e556a6df43b1e5d50b1f6cf0b6fe5484d49657fd Mon Sep 17 00:00:00 2001 From: Rasic2 <1051987201@qq.com> Date: Sun, 21 Sep 2025 22:52:59 +0800 Subject: [PATCH 3/5] ci: streamline workflow by removing permissions and consolidating pull request creation steps --- .github/workflows/update-pre-commit.yml | 48 ++++++++++++++----------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/.github/workflows/update-pre-commit.yml b/.github/workflows/update-pre-commit.yml index dc53d274..4f619191 100644 --- a/.github/workflows/update-pre-commit.yml +++ b/.github/workflows/update-pre-commit.yml @@ -5,10 +5,6 @@ on: - cron: '0 0 * * 0' workflow_dispatch: -permissions: - contents: write - pull-requests: write - jobs: update-pre-commit: runs-on: ubuntu-latest @@ -16,8 +12,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v5 @@ -27,17 +21,31 @@ jobs: - name: Install pre-commit run: pip install pre-commit - - name: Update pre-commit hooks - run: pre-commit autoupdate - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 - with: - commit-message: "chore: update pre-commit hooks" - title: "chore: update pre-commit hooks" - body: | - Automated update of pre-commit hooks via pre-commit autoupdate. - branch: "update/pre-commit-hooks" - base: main - labels: "dependencies" - delete-branch: true + - name: Update pre-commit hooks and create PR + run: | + # 更新 hooks + pre-commit autoupdate + + # 检查是否有变化 + if git diff --exit-code .pre-commit-config.yaml; then + echo "No updates available" + exit 0 + fi + + # 配置 git + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + + # 提交更改 + git add .pre-commit-config.yaml + git commit -m "chore: update pre-commit hooks" + git push origin HEAD:update-pre-commit-hooks + + # 使用 GitHub CLI 创建 PR(需要先设置 GH_TOKEN) + echo "Please create PR manually or setup GitHub CLI with token" + + - name: Output instructions + if: failure() + run: | + echo "Changes were made but PR creation failed." + echo "Please manually create a PR from the update-pre-commit-hooks branch" From bb901c177801dcf94532df5aba7d4beee5a9ec2a Mon Sep 17 00:00:00 2001 From: Rasic2 <1051987201@qq.com> Date: Sun, 21 Sep 2025 22:57:35 +0800 Subject: [PATCH 4/5] chore: remove scheduled workflow for pre-commit hook updates and update pre-commit hook versions --- .github/workflows/update-pre-commit.yml | 51 ------------------------- .pre-commit-config.yaml | 8 ++-- 2 files changed, 4 insertions(+), 55 deletions(-) delete mode 100644 .github/workflows/update-pre-commit.yml diff --git a/.github/workflows/update-pre-commit.yml b/.github/workflows/update-pre-commit.yml deleted file mode 100644 index 4f619191..00000000 --- a/.github/workflows/update-pre-commit.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Update pre-commit hooks - -on: - schedule: - - cron: '0 0 * * 0' - workflow_dispatch: - -jobs: - update-pre-commit: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - - name: Install pre-commit - run: pip install pre-commit - - - name: Update pre-commit hooks and create PR - run: | - # 更新 hooks - pre-commit autoupdate - - # 检查是否有变化 - if git diff --exit-code .pre-commit-config.yaml; then - echo "No updates available" - exit 0 - fi - - # 配置 git - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git config --local user.name "github-actions[bot]" - - # 提交更改 - git add .pre-commit-config.yaml - git commit -m "chore: update pre-commit hooks" - git push origin HEAD:update-pre-commit-hooks - - # 使用 GitHub CLI 创建 PR(需要先设置 GH_TOKEN) - echo "Please create PR manually or setup GitHub CLI with token" - - - name: Output instructions - if: failure() - run: | - echo "Changes were made but PR creation failed." - echo "Please manually create a PR from the update-pre-commit-hooks branch" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3a01585f..e323ea1e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -63,19 +63,19 @@ repos: - id: pyupgrade - repo: https://github.com/psf/black - rev: 23.9.1 + rev: 25.9.0 hooks: - id: black args: [ --skip-string-normalization, --line-length=88 ] - repo: https://github.com/pycqa/isort - rev: 5.12.0 + rev: 6.0.1 hooks: - id: isort args: [ "--profile", "black" ] - repo: https://github.com/pycqa/autoflake - rev: v2.2.1 + rev: v2.3.1 hooks: - id: autoflake args: @@ -84,7 +84,7 @@ repos: - --remove-unused-variables - repo: https://github.com/pycqa/flake8 - rev: 6.1.0 + rev: 7.3.0 hooks: - id: flake8 additional_dependencies: [ flake8-bugbear ] From dd6ed2a1673495f328c43fab2d05b5e18447e22c Mon Sep 17 00:00:00 2001 From: Rasic2 <1051987201@qq.com> Date: Sun, 21 Sep 2025 23:01:37 +0800 Subject: [PATCH 5/5] style: fix wrapping in async code for improved readability and alignment --- agents/matmaster_agent/base_agents/job_agent.py | 6 +++--- agents/matmaster_agent/callback.py | 6 +++--- agents/matmaster_agent/chembrain_agent/base.py | 4 +++- .../smiles_conversion_agent/callback.py | 8 +++++--- agents/matmaster_agent/ssebrain_agent/base.py | 4 +++- agents/matmaster_agent/ssebrain_agent/callback.py | 4 +++- agents/matmaster_agent/utils/helper_func.py | 8 ++++++-- evaluate/base/human_simulator.py | 10 ++++++---- 8 files changed, 32 insertions(+), 18 deletions(-) diff --git a/agents/matmaster_agent/base_agents/job_agent.py b/agents/matmaster_agent/base_agents/job_agent.py index b1a169ba..8a494c74 100644 --- a/agents/matmaster_agent/base_agents/job_agent.py +++ b/agents/matmaster_agent/base_agents/job_agent.py @@ -870,9 +870,9 @@ async def _run_async_impl( if not params_check_completed: # Call ParamsCheckInfoAgent to generate params needing check - async for params_check_info_event in self.params_check_info_agent.run_async( - ctx - ): + async for ( + params_check_info_event + ) in self.params_check_info_agent.run_async(ctx): yield params_check_info_event else: async for submit_event in self.submit_agent.run_async(ctx): diff --git a/agents/matmaster_agent/callback.py b/agents/matmaster_agent/callback.py index 46f3bc78..02d7279d 100644 --- a/agents/matmaster_agent/callback.py +++ b/agents/matmaster_agent/callback.py @@ -149,9 +149,9 @@ async def matmaster_check_job_status( llm_response.content = None break if not reset: - callback_context.state[ - 'special_llm_response' - ] = True # 标记开始处理原来消息的非流式版本 + callback_context.state['special_llm_response'] = ( + True # 标记开始处理原来消息的非流式版本 + ) llm_response.content.parts = [] reset = True function_call_id = f"call_{str(uuid.uuid4()).replace('-', '')[:24]}" diff --git a/agents/matmaster_agent/chembrain_agent/base.py b/agents/matmaster_agent/chembrain_agent/base.py index 4f280cde..47aa66f3 100644 --- a/agents/matmaster_agent/chembrain_agent/base.py +++ b/agents/matmaster_agent/chembrain_agent/base.py @@ -147,7 +147,9 @@ async def _run_async_impl( and event.content.parts and event.content.parts[0].function_response ): - logger.info(f"{event.content.parts[0].function_response.name} 调用结束") + logger.info( + f"{event.content.parts[0].function_response.name} 调用结束" + ) yield Event( author=self.name, actions=EventActions( diff --git a/agents/matmaster_agent/chembrain_agent/smiles_conversion_agent/callback.py b/agents/matmaster_agent/chembrain_agent/smiles_conversion_agent/callback.py index 9f8cebf3..b04aa636 100644 --- a/agents/matmaster_agent/chembrain_agent/smiles_conversion_agent/callback.py +++ b/agents/matmaster_agent/chembrain_agent/smiles_conversion_agent/callback.py @@ -26,9 +26,11 @@ async def smiles_conversion_after_tool( 'after': { 'tool_name': tool.name, 'tool_args': args, - 'tool_response': tool_response.content[0].text - if (tool_response and len(tool_response.content)) - else None, + 'tool_response': ( + tool_response.content[0].text + if (tool_response and len(tool_response.content)) + else None + ), } } diff --git a/agents/matmaster_agent/ssebrain_agent/base.py b/agents/matmaster_agent/ssebrain_agent/base.py index f540bd66..ad0834cd 100644 --- a/agents/matmaster_agent/ssebrain_agent/base.py +++ b/agents/matmaster_agent/ssebrain_agent/base.py @@ -144,7 +144,9 @@ async def _run_async_impl( and event.content.parts and event.content.parts[0].function_response ): - logger.info(f"{event.content.parts[0].function_response.name} 调用结束") + logger.info( + f"{event.content.parts[0].function_response.name} 调用结束" + ) yield Event( author=self.name, actions=EventActions( diff --git a/agents/matmaster_agent/ssebrain_agent/callback.py b/agents/matmaster_agent/ssebrain_agent/callback.py index e2fb8a47..ee064cba 100644 --- a/agents/matmaster_agent/ssebrain_agent/callback.py +++ b/agents/matmaster_agent/ssebrain_agent/callback.py @@ -54,7 +54,9 @@ async def ssebrain_before_agent( callback_context.state['current_time'] = datetime.now().strftime( '%Y-%m-%d %H:%M:%S' ) - callback_context.state['db_name'] = 'solid_state_electrolyte_db' # 使用默认数据库 + callback_context.state['db_name'] = ( + 'solid_state_electrolyte_db' # 使用默认数据库 + ) db_manager = DatabaseManager('solid_state_electrolyte_db') await db_manager.async_init() # Call the async init method callback_context.state['available_tables'] = db_manager.table_schema diff --git a/agents/matmaster_agent/utils/helper_func.py b/agents/matmaster_agent/utils/helper_func.py index dfa54753..4aa8c17f 100644 --- a/agents/matmaster_agent/utils/helper_func.py +++ b/agents/matmaster_agent/utils/helper_func.py @@ -34,7 +34,9 @@ async def update_session_state(ctx: InvocationContext, author: str): author=f"{filename}:{lineno}", actions=actions_with_update, ) - await ctx.session_service.append_event(ctx.session, system_event) # 会引入一个空消息 + await ctx.session_service.append_event( + ctx.session, system_event + ) # 会引入一个空消息 def update_llm_response( @@ -339,7 +341,9 @@ def get_new_function_call_indices( def check_None_wrapper(func): def wrapper(*args, **kwargs): - result = func(*args, **kwargs) # 注意这里应该是 *args, **kwargs 而不是 args, kwargs + result = func( + *args, **kwargs + ) # 注意这里应该是 *args, **kwargs 而不是 args, kwargs if result is None: raise ValueError( f"'{func.__name__.replace('_get_', '')}' was not found, please provide it!" diff --git a/evaluate/base/human_simulator.py b/evaluate/base/human_simulator.py index 944fa7c9..dbd8263b 100644 --- a/evaluate/base/human_simulator.py +++ b/evaluate/base/human_simulator.py @@ -115,7 +115,9 @@ def _generate_user_response(self, agent_message: str) -> Tuple[str, bool]: user_response = result.get('response', '我理解了。') should_continue = result.get('continue', True) - logger.info(f"用户响应生成 - 轮次: {self.turn_count}, 继续: {should_continue}") + logger.info( + f"用户响应生成 - 轮次: {self.turn_count}, 继续: {should_continue}" + ) return user_response, should_continue @@ -199,9 +201,9 @@ def get_conversation_summary(self) -> Dict[str, Any]: 'goal': self.goal.initial_question if self.goal else None, 'total_turns': self.turn_count, 'final_state': self.current_state.value, - 'duration_minutes': ((time.time() - self.start_time) / 60) - if self.start_time - else 0, + 'duration_minutes': ( + ((time.time() - self.start_time) / 60) if self.start_time else 0 + ), 'conversation_history': self.conversation_history, }