diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml
index 98e2fc9d..fba9b693 100644
--- a/.github/workflows/doc.yaml
+++ b/.github/workflows/doc.yaml
@@ -59,4 +59,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
- uses: actions/deploy-pages@v4
\ No newline at end of file
+ uses: actions/deploy-pages@v4
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 0e78eeb7..6f5736a8 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -11,30 +11,17 @@ repos:
- id: check-merge-conflict
- id: detect-private-key
- - repo: https://github.com/psf/black
- rev: 23.7.0
- hooks:
- - id: black
- language_version: python3.10
- args: [--line-length=100]
- - repo: https://github.com/pycqa/isort
- rev: 5.12.0
- hooks:
- - id: isort
- args: ["--profile", "black", "--filter-files"]
- - repo: https://github.com/pycqa/flake8
- rev: 6.1.0
+ - repo: https://github.com/myint/autoflake
+ rev: v2.2.0
hooks:
- - id: flake8
- additional_dependencies: [flake8-docstrings]
- args: [
- "--max-line-length=100",
- "--max-complexity=20",
- "--select=C,E,F,W,B,B950",
- "--ignore=E203,E266,E501,W503",
- ]
+ - id: autoflake
+ args: [
+ --in-place,
+ --remove-all-unused-imports,
+ --ignore-init-module-imports
+ ]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.0
diff --git a/README.md b/README.md
index f2b520f5..b01cff25 100644
--- a/README.md
+++ b/README.md
@@ -152,4 +152,4 @@ If you use AgentJet in your research, please cite:
[⭐ Star Us](https://github.com/modelscope/AgentJet) · [Report Bug](https://github.com/modelscope/AgentJet/issues) · [Request Feature](https://github.com/modelscope/AgentJet/issues)
-
\ No newline at end of file
+
diff --git a/ajet/backbone/main_vllm.py b/ajet/backbone/main_vllm.py
index 3f0a724c..686a35cd 100644
--- a/ajet/backbone/main_vllm.py
+++ b/ajet/backbone/main_vllm.py
@@ -1,4 +1,3 @@
-import atexit
import os
import sys
from types import SimpleNamespace
@@ -83,7 +82,7 @@ def submit_chat_completions(self, messages, sampling_params, request_id, tools=[
"content": message["content"],
"tool_calls": message.get("tool_calls", None),
"tokens": [
- TokenAndProbVllmDebug(t) for t in completion.choices[0].logprobs.content # type: ignore
+ TokenAndProbVllmDebug(t) for t in completion.choices[0].logprobs.content # type: ignore
],
}
)
@@ -131,7 +130,7 @@ async def submit_chat_completions_async(self, messages, sampling_params, request
"content": message["content"],
"tool_calls": message.get("tool_calls", None),
"tokens": [
- TokenAndProbVllmDebug(t) for t in completion.choices[0].logprobs.content # type: ignore
+ TokenAndProbVllmDebug(t) for t in completion.choices[0].logprobs.content # type: ignore
],
}
)
diff --git a/ajet/backbone/trainer_trinity.py b/ajet/backbone/trainer_trinity.py
index 1a75a1bc..8000a636 100644
--- a/ajet/backbone/trainer_trinity.py
+++ b/ajet/backbone/trainer_trinity.py
@@ -1,12 +1,12 @@
-import asyncio
import os
-from typing import Dict, List, Literal, Optional, cast
-
+import asyncio
import datasets
import openai
import swanlab
+
from loguru import logger
from transformers import AutoTokenizer
+from typing import Dict, List, Literal, Optional, cast
from trinity.buffer.reader import READER
from trinity.buffer.reader.file_reader import TaskFileReader, _HFBatchReader
from trinity.buffer.schema import FORMATTER
@@ -19,9 +19,7 @@
from trinity.utils.monitor import MONITOR, Monitor
from ajet.backbone.warm_up import warm_up_process
-from ajet.context_tracker.multiagent_tracking import (
- MultiAgentContextTracker,
-)
+from ajet.context_tracker.multiagent_tracking import MultiAgentContextTracker
from ajet.schema.trajectory import Sample
from ajet.task_reader import dict_to_ajet_task
from ajet.task_rollout.native_parallel_worker import DynamicRolloutManager
@@ -65,7 +63,6 @@ def __init__(
)
def convert_task(self, task: TrinityTask):
- from ajet.schema.task import Task
assert isinstance(task.raw_task, dict)
return dict_to_ajet_task(task.raw_task)
diff --git a/ajet/backbone/warm_up.py b/ajet/backbone/warm_up.py
index f4c2973e..fcae673f 100644
--- a/ajet/backbone/warm_up.py
+++ b/ajet/backbone/warm_up.py
@@ -101,4 +101,4 @@ def warm_up_process(config):
experiment_name = config.ajet.experiment_name
init_parallel_rollout_logger(experiment_name)
warm_up_task_judge_when_needed(config)
- clean_up_tmp_ajet_dir(config)
\ No newline at end of file
+ clean_up_tmp_ajet_dir(config)
diff --git a/ajet/context_tracker/base_tracker.py b/ajet/context_tracker/base_tracker.py
index 0ff706fa..948aee3e 100644
--- a/ajet/context_tracker/base_tracker.py
+++ b/ajet/context_tracker/base_tracker.py
@@ -1,5 +1,5 @@
from typing import List, Tuple, Union
-from typing import List, Union, Tuple, Dict, Optional, Any
+from typing import List, Union, Tuple, Dict, Optional
from ajet.schema.task import WorkflowTask
from ajet.schema.extended_msg import (
diff --git a/ajet/context_tracker/timeline_merging/timeline_merging.py b/ajet/context_tracker/timeline_merging/timeline_merging.py
index e81475dd..4fb19baa 100644
--- a/ajet/context_tracker/timeline_merging/timeline_merging.py
+++ b/ajet/context_tracker/timeline_merging/timeline_merging.py
@@ -1,6 +1,5 @@
from typing import List
-from beast_logger import print_listofdict
from ajet.context_tracker.basic_tracker import ExtendedMessage
diff --git a/ajet/schema/convertion.py b/ajet/schema/convertion.py
index e2a6a2c0..408bbcdb 100644
--- a/ajet/schema/convertion.py
+++ b/ajet/schema/convertion.py
@@ -4,11 +4,10 @@
from openai.types.chat.chat_completion_message import ChatCompletionMessage
from agentscope.model import ChatResponse as AgentScopeChatResponse
from openai.types.completion_usage import CompletionUsage
-from typing import Any, Callable, Dict, List, Literal, Type, Union
+from typing import List, Type
from agentscope.message import TextBlock, ToolUseBlock
from agentscope._utils._common import _json_loads_with_repair
from pydantic import BaseModel
-from agentscope.model import ChatResponse
def convert_llm_proxy_response_to_oai_response(llm_proxy_response):
@@ -106,4 +105,3 @@ def convert_llm_proxy_response_to_agentscope_response(
)
return parsed_response
-
diff --git a/ajet/schema/logprob.py b/ajet/schema/logprob.py
index 42d2c572..dc736fb8 100644
--- a/ajet/schema/logprob.py
+++ b/ajet/schema/logprob.py
@@ -11,4 +11,4 @@
class TokenAndProb(BaseModel):
token_id: int
logprob: float
- decoded_string: str
\ No newline at end of file
+ decoded_string: str
diff --git a/ajet/task_reader/__init__.py b/ajet/task_reader/__init__.py
index 19a1a8e3..2d7d7322 100644
--- a/ajet/task_reader/__init__.py
+++ b/ajet/task_reader/__init__.py
@@ -123,4 +123,4 @@ def dict_to_ajet_task(task_dict: dict) -> Task:
task_id=task_dict.get("task_id", ""),
env_type=task_dict.get("env_type", ""),
metadata=task_dict.get("metadata", {}),
- )
\ No newline at end of file
+ )
diff --git a/ajet/task_rollout/async_llm_bridge.py b/ajet/task_rollout/async_llm_bridge.py
index f43ba1c8..ff494844 100644
--- a/ajet/task_rollout/async_llm_bridge.py
+++ b/ajet/task_rollout/async_llm_bridge.py
@@ -3,14 +3,13 @@
import json
import time
import uuid
-from typing import Any, Callable, Dict, List, Literal, Type, Union
+from typing import Any, Callable, Dict, List, Literal, Union
from loguru import logger
from omegaconf import DictConfig
from pydantic import BaseModel
-from transformers.tokenization_utils import PreTrainedTokenizer
from vllm.entrypoints.openai.tool_parsers.hermes_tool_parser import Hermes2ProToolParser
from vllm.outputs import RequestOutput as VerlVllmRequestOutput
diff --git a/ajet/task_runner/base_runner.py b/ajet/task_runner/base_runner.py
index 65aa5c13..d8c15492 100644
--- a/ajet/task_runner/base_runner.py
+++ b/ajet/task_runner/base_runner.py
@@ -3,7 +3,6 @@
from threading import Lock
from typing import Any, Callable, Union, Type
from multiprocessing import Process, Queue
-from unittest import result
from ajet.context_tracker.basic_tracker import BaseContextTracker
from ajet.schema.task import WorkflowOutput, WorkflowTask
@@ -117,4 +116,3 @@ def run_user_workflow(
else:
raise ValueError(f"Unsupported wrapper type: {self.wrapper_type}")
-
diff --git a/ajet/task_runner/general_runner.py b/ajet/task_runner/general_runner.py
index 2904cfae..7ea76710 100644
--- a/ajet/task_runner/general_runner.py
+++ b/ajet/task_runner/general_runner.py
@@ -1,7 +1,6 @@
-from venv import logger
from ajet import AjetTuner
-from ajet import Workflow, WorkflowOutput
+from ajet import WorkflowOutput
from ajet.context_tracker.multiagent_tracking import (
MultiAgentContextTracker,
)
diff --git a/ajet/tuner.py b/ajet/tuner.py
index 93602d05..aacc3ab9 100644
--- a/ajet/tuner.py
+++ b/ajet/tuner.py
@@ -1,4 +1,4 @@
-from typing import TYPE_CHECKING, Any, Literal, Callable, Union, Type
+from typing import TYPE_CHECKING, Callable, Union, Type
from ajet.context_tracker.multiagent_tracking import (
MultiAgentContextTracker,
diff --git a/ajet/tuner_lib/weight_tuner/__init__.py b/ajet/tuner_lib/weight_tuner/__init__.py
index 317e8699..abb540c1 100644
--- a/ajet/tuner_lib/weight_tuner/__init__.py
+++ b/ajet/tuner_lib/weight_tuner/__init__.py
@@ -1,4 +1,3 @@
from ajet.tuner_lib.weight_tuner.as_agentscope_model import AgentScopeModelTuner
from ajet.tuner_lib.weight_tuner.as_oai_sdk_model import OpenaiClientModelTuner
-
diff --git a/ajet/tuner_lib/weight_tuner/as_agentscope_model.py b/ajet/tuner_lib/weight_tuner/as_agentscope_model.py
index 4af1754c..67a5ef8b 100644
--- a/ajet/tuner_lib/weight_tuner/as_agentscope_model.py
+++ b/ajet/tuner_lib/weight_tuner/as_agentscope_model.py
@@ -1,7 +1,7 @@
-from typing import TYPE_CHECKING, Any, Literal, Type
+from typing import Any, Literal, Type
from agentscope._utils._common import _create_tool_from_base_model
-from agentscope.model import ChatModelBase, ChatResponse, DashScopeChatModel
+from agentscope.model import ChatResponse, DashScopeChatModel
from loguru import logger
from pydantic import BaseModel
@@ -10,9 +10,6 @@
)
from ajet.task_rollout.async_llm_bridge import AgentScopeLlmProxyWithTracker
-if TYPE_CHECKING:
- from ajet import Workflow
-
class AgentScopeModelTuner(DashScopeChatModel):
"""
diff --git a/ajet/tuner_lib/weight_tuner/as_oai_baseurl_apikey.py b/ajet/tuner_lib/weight_tuner/as_oai_baseurl_apikey.py
index ba3e9693..90c2cc72 100644
--- a/ajet/tuner_lib/weight_tuner/as_oai_baseurl_apikey.py
+++ b/ajet/tuner_lib/weight_tuner/as_oai_baseurl_apikey.py
@@ -1,22 +1,13 @@
import os
-import asyncio
-from typing import TYPE_CHECKING, Any, List, Callable, Literal, Type, Union
-from loguru import logger
+from typing import Any
from pydantic import BaseModel, Field
from ajet.context_tracker.multiagent_tracking import (
MultiAgentContextTracker,
)
-from ajet.task_rollout.async_llm_bridge import OpenaiLlmProxyWithTracker
-from ajet.utils.magic_mock import SpecialMagicMock
-from openai.types.chat.chat_completion import ChatCompletion
-from openai.resources.chat.chat import Chat, AsyncChat
+from openai.resources.chat.chat import AsyncChat
from openai.resources.completions import AsyncCompletions
-from openai import OpenAI, AsyncOpenAI
-from ajet.utils.networking import find_free_port
from .experimental.as_oai_model_client import generate_auth_token
-if TYPE_CHECKING:
- from ajet import Workflow
class MockAsyncCompletions(AsyncCompletions):
async def create(self, *args, **kwargs) -> Any: # type: ignore
diff --git a/ajet/tuner_lib/weight_tuner/as_oai_sdk_model.py b/ajet/tuner_lib/weight_tuner/as_oai_sdk_model.py
index 943d5c2c..59248fee 100644
--- a/ajet/tuner_lib/weight_tuner/as_oai_sdk_model.py
+++ b/ajet/tuner_lib/weight_tuner/as_oai_sdk_model.py
@@ -1,19 +1,12 @@
-import asyncio
-from typing import TYPE_CHECKING, Any, List, Callable, Literal, Type, Union
-from loguru import logger
-from pydantic import BaseModel
+from typing import Any, List, Callable
from ajet.context_tracker.multiagent_tracking import (
MultiAgentContextTracker,
)
from ajet.task_rollout.async_llm_bridge import OpenaiLlmProxyWithTracker
-from ajet.utils.magic_mock import SpecialMagicMock
from openai.types.chat.chat_completion import ChatCompletion
-from openai.resources.chat.chat import Chat, AsyncChat
+from openai.resources.chat.chat import AsyncChat
from openai.resources.completions import AsyncCompletions
-from openai import OpenAI, AsyncOpenAI
-
-if TYPE_CHECKING:
- from ajet import Workflow
+from openai import AsyncOpenAI
class MockAsyncCompletions(AsyncCompletions):
@@ -80,5 +73,3 @@ async def create(
)
assert isinstance(response_gen, ChatCompletion)
return response_gen
-
-
diff --git a/ajet/tuner_lib/weight_tuner/experimental/as_oai_model_server.py b/ajet/tuner_lib/weight_tuner/experimental/as_oai_model_server.py
index 0c652c69..089d11eb 100644
--- a/ajet/tuner_lib/weight_tuner/experimental/as_oai_model_server.py
+++ b/ajet/tuner_lib/weight_tuner/experimental/as_oai_model_server.py
@@ -24,7 +24,7 @@
from loguru import logger
from pydantic import BaseModel
-from fastapi import FastAPI, Header, HTTPException, Request, Body
+from fastapi import FastAPI, Header, HTTPException, Request
from contextlib import asynccontextmanager
from multiprocessing import Process
from concurrent.futures import ThreadPoolExecutor
@@ -239,5 +239,3 @@ def start_interchange_server(config) -> int:
# return port
return port
-
-
diff --git a/ajet/utils/async_utils.py b/ajet/utils/async_utils.py
index 3bb1b67e..219aba9c 100644
--- a/ajet/utils/async_utils.py
+++ b/ajet/utils/async_utils.py
@@ -67,4 +67,4 @@ def _patched_del(self) -> None:
AsyncHttpxClientWrapper.__del__ = _patched_del
print("Applied httpx aclose patch.")
except ImportError:
- pass
\ No newline at end of file
+ pass
diff --git a/ajet/utils/lowlevel_hook.py b/ajet/utils/lowlevel_hook.py
index bdd536d0..006f17b9 100644
--- a/ajet/utils/lowlevel_hook.py
+++ b/ajet/utils/lowlevel_hook.py
@@ -44,4 +44,4 @@ def debug_task_init(self, coro, loop=None, name=None, context=None):
asyncio.create_task = debug_create_task
asyncio.AbstractEventLoop.create_task = debug_loop_create_task
-patch_task_creation()
\ No newline at end of file
+patch_task_creation()
diff --git a/ajet/utils/metric_helper/__init__.py b/ajet/utils/metric_helper/__init__.py
index a9702d5d..70ce2818 100644
--- a/ajet/utils/metric_helper/__init__.py
+++ b/ajet/utils/metric_helper/__init__.py
@@ -14,4 +14,4 @@ def update_metrics(context_tracker_arr, metrics:dict):
metrics.update(tool_metrics)
if reward_metrics:
metrics.update(reward_metrics)
- return
\ No newline at end of file
+ return
diff --git a/ajet/utils/metric_helper/reward_metric_helper.py b/ajet/utils/metric_helper/reward_metric_helper.py
index b6cf5918..49e069bf 100644
--- a/ajet/utils/metric_helper/reward_metric_helper.py
+++ b/ajet/utils/metric_helper/reward_metric_helper.py
@@ -11,17 +11,17 @@
- judge_time/ Judge time consumption statistics
"""
-from typing import List, Dict, Any, Optional
+from typing import List, Dict, Any
import numpy as np
def extract_reward_stats_from_trajectories(trajectories: List[Any]) -> List[Dict[str, Any]]:
"""
Extract reward_stats from trajectories list.
-
+
Args:
trajectories: List of trajectory objects containing workflow_metadata
-
+
Returns:
List of reward_stats dictionaries
"""
@@ -36,10 +36,10 @@ def extract_reward_stats_from_trajectories(trajectories: List[Any]) -> List[Dict
def extract_reward_stats_from_cmts(cmts: List[Any]) -> tuple[List[Dict[str, Any]], Dict[str, int]]:
"""
Extract reward_stats from cmts list and return debug statistics.
-
+
Args:
cmts: List of cmt objects containing workflow_metadata
-
+
Returns:
Tuple of (reward_stats_list, debug_stats)
"""
@@ -49,47 +49,47 @@ def extract_reward_stats_from_cmts(cmts: List[Any]) -> tuple[List[Dict[str, Any]
'has_workflow_metadata': 0,
'has_reward_stats': 0,
}
-
+
for _cmt in cmts:
if hasattr(_cmt, 'workflow_metadata') and _cmt.workflow_metadata:
debug_stats['has_workflow_metadata'] += 1
if 'reward_stats' in _cmt.workflow_metadata:
debug_stats['has_reward_stats'] += 1
reward_stats_list.append(_cmt.workflow_metadata['reward_stats'])
-
+
return reward_stats_list, debug_stats
def compute_reward_metrics(reward_stats_list: List[Dict[str, Any]], prefix: str = "") -> Dict[str, float]:
"""
Compute SwanLab metrics from reward_stats list.
-
+
Supports two data sources:
1. RM Gallery RewardStats fields (rm_raw, etc.)
2. OpenJudge fields (openjudge_xxx_raw, openjudge_xxx_contribution, etc.)
-
+
Args:
reward_stats_list: List of reward_stats dictionaries
prefix: Metric name prefix (e.g., "val/" for validation phase)
-
+
Returns:
Formatted metrics dictionary ready for SwanLab reporting
"""
if not reward_stats_list:
return {}
-
+
n = len(reward_stats_list)
metrics = {}
-
+
# ========== Top-level Scores (General) ==========
final_reward_list = [rs.get('final_reward', 0.0) for rs in reward_stats_list]
fused_reward_list = [rs.get('fused_reward', 0.0) for rs in reward_stats_list]
penalty_list = [rs.get('penalty', 0.0) for rs in reward_stats_list]
step_reward_list = [rs.get('step_reward', 0.0) for rs in reward_stats_list]
-
+
# Penalty statistics
non_zero_penalties = [p for p in penalty_list if p != 0.0]
-
+
# Top-level metrics
metrics[f"{prefix}rewards/final_reward_mean"] = float(np.mean(final_reward_list))
metrics[f"{prefix}rewards/fused_reward_mean"] = float(np.mean(fused_reward_list))
@@ -97,110 +97,110 @@ def compute_reward_metrics(reward_stats_list: List[Dict[str, Any]], prefix: str
metrics[f"{prefix}rewards/step_reward_mean"] = float(np.mean(step_reward_list))
metrics[f"{prefix}rewards/penalty_count"] = len(non_zero_penalties)
metrics[f"{prefix}rewards/penalty_rate"] = len(non_zero_penalties) / n * 100 if n > 0 else 0.0
-
+
# ========== Detect OpenJudge Usage ==========
openjudge_enabled_count = sum(1 for rs in reward_stats_list if rs.get('openjudge_enabled', False))
-
+
if openjudge_enabled_count > 0:
# ========== OpenJudge Metrics ==========
metrics[f"{prefix}rewards/openjudge_enabled_rate"] = openjudge_enabled_count / n * 100
-
+
# Dynamically extract OpenJudge grader fields
- # Currently supported graders: report_resolution, trajectory_faithfulness,
+ # Currently supported graders: report_resolution, trajectory_faithfulness,
# rubrics_performance, trajectory_comprehensive, information_gain, action_loop
openjudge_graders = [
"report_resolution",
- "trajectory_faithfulness",
+ "trajectory_faithfulness",
"rubrics_performance",
"trajectory_comprehensive",
"information_gain",
"action_loop",
]
-
+
for grader_name in openjudge_graders:
raw_key = f"openjudge_{grader_name}_raw"
contrib_key = f"openjudge_{grader_name}_contribution"
-
+
raw_list = [rs.get(raw_key, 0.0) for rs in reward_stats_list]
contrib_list = [rs.get(contrib_key, 0.0) for rs in reward_stats_list]
-
+
# Only report when non-zero values exist
if any(v != 0.0 for v in raw_list):
metrics[f"{prefix}rewards/openjudge/{grader_name}_raw_mean"] = float(np.mean(raw_list))
if any(v != 0.0 for v in contrib_list):
metrics[f"{prefix}rewards/openjudge/{grader_name}_contribution_mean"] = float(np.mean(contrib_list))
-
+
# OpenJudge time consumption statistics
grading_time_list = [rs.get('grading_time', 0.0) for rs in reward_stats_list]
if any(v != 0.0 for v in grading_time_list):
metrics[f"{prefix}judge_time/openjudge_grading_time_mean"] = float(np.mean(grading_time_list))
metrics[f"{prefix}judge_time/openjudge_grading_time_max"] = float(np.max(grading_time_list))
-
+
# ========== RM Gallery Metrics ==========
# RM Gallery
rm_raw_list = [rs.get('rm_raw', 0.0) for rs in reward_stats_list]
rm_contribution_list = [rs.get('rm_contribution', 0.0) for rs in reward_stats_list]
-
+
# RefJudge
ref_final_raw_list = [rs.get('ref_final_raw', 0.0) for rs in reward_stats_list]
ref_citation_raw_list = [rs.get('ref_citation_raw', 0.0) for rs in reward_stats_list]
ref_grounding_raw_list = [rs.get('ref_grounding_raw', 0.0) for rs in reward_stats_list]
ref_contribution_list = [rs.get('ref_contribution', 0.0) for rs in reward_stats_list]
-
+
# StructureJudge
structure_raw_list = [rs.get('structure_raw', 0.0) for rs in reward_stats_list]
structure_contribution_list = [rs.get('structure_contribution', 0.0) for rs in reward_stats_list]
-
+
# dimensions/ raw scores
metrics[f"{prefix}rewards/dimensions/rm_raw_mean"] = float(np.mean(rm_raw_list))
metrics[f"{prefix}rewards/dimensions/ref_final_raw_mean"] = float(np.mean(ref_final_raw_list))
metrics[f"{prefix}rewards/dimensions/ref_citation_raw_mean"] = float(np.mean(ref_citation_raw_list))
metrics[f"{prefix}rewards/dimensions/ref_grounding_raw_mean"] = float(np.mean(ref_grounding_raw_list))
metrics[f"{prefix}rewards/dimensions/structure_raw_mean"] = float(np.mean(structure_raw_list))
-
+
# contribution/ weighted contributions
metrics[f"{prefix}rewards/contribution/rm_contribution_mean"] = float(np.mean(rm_contribution_list))
metrics[f"{prefix}rewards/contribution/ref_contribution_mean"] = float(np.mean(ref_contribution_list))
metrics[f"{prefix}rewards/contribution/structure_contribution_mean"] = float(np.mean(structure_contribution_list))
-
+
# Enabled state statistics
ref_judge_enabled_count = sum(1 for rs in reward_stats_list if rs.get('ref_judge_enabled', False))
if ref_judge_enabled_count > 0:
metrics[f"{prefix}rewards/ref_judge_enabled_rate"] = ref_judge_enabled_count / n * 100
-
+
structure_judge_enabled_count = sum(1 for rs in reward_stats_list if rs.get('structure_judge_enabled', False))
if structure_judge_enabled_count > 0:
metrics[f"{prefix}rewards/structure_judge_enabled_rate"] = structure_judge_enabled_count / n * 100
-
+
# Time consumption statistics
rm_time_list = [rs.get('rm_time', 0.0) for rs in reward_stats_list]
refstruc_time_list = [rs.get('refstruc_time', 0.0) for rs in reward_stats_list]
-
+
metrics[f"{prefix}judge_time/rm_time_mean"] = float(np.mean(rm_time_list))
metrics[f"{prefix}judge_time/refstruc_time_mean"] = float(np.mean(refstruc_time_list))
-
+
if rm_time_list:
metrics[f"{prefix}judge_time/rm_time_max"] = float(np.max(rm_time_list))
if refstruc_time_list:
metrics[f"{prefix}judge_time/refstruc_time_max"] = float(np.max(refstruc_time_list))
-
+
# ========== General Time Consumption Statistics ==========
judge_total_time_list = [rs.get('judge_total_time', 0.0) for rs in reward_stats_list]
if any(v != 0.0 for v in judge_total_time_list):
metrics[f"{prefix}judge_time/judge_total_time_mean"] = float(np.mean(judge_total_time_list))
metrics[f"{prefix}judge_time/judge_total_time_max"] = float(np.max(judge_total_time_list))
-
+
return metrics
def compute_reward_metrics_from_trajectories(trajectories: List[Any]) -> Dict[str, float]:
"""
Training phase: Extract reward_stats from trajectories and compute metrics.
-
+
Args:
trajectories: List of trajectory objects
-
+
Returns:
Formatted metrics dictionary
"""
@@ -211,21 +211,21 @@ def compute_reward_metrics_from_trajectories(trajectories: List[Any]) -> Dict[st
def compute_reward_metrics_from_cmts(cmts: List[Any], print_debug: bool = True) -> Dict[str, float]:
"""
Validation phase: Extract reward_stats from cmts and compute metrics.
-
+
Args:
cmts: List of cmt objects
print_debug: Whether to print debug information
-
+
Returns:
Formatted metrics dictionary (with "val_reward/" prefix)
"""
reward_stats_list, debug_stats = extract_reward_stats_from_cmts(cmts)
-
+
if print_debug:
print(f"\n[DEBUG eval_dataset()] reward_stats statistics:")
print(f" - Total cmts count: {debug_stats['total_cmts']}")
print(f" - Has workflow_metadata: {debug_stats['has_workflow_metadata']}")
print(f" - Has reward_stats: {debug_stats['has_reward_stats']}")
print(f" - Extracted samples count: {len(reward_stats_list)}")
-
+
return compute_reward_metrics(reward_stats_list, prefix="val_")
diff --git a/ajet/utils/metric_helper/save_trajectory_as_json.py b/ajet/utils/metric_helper/save_trajectory_as_json.py
index 0e380abc..344a6ab4 100644
--- a/ajet/utils/metric_helper/save_trajectory_as_json.py
+++ b/ajet/utils/metric_helper/save_trajectory_as_json.py
@@ -53,4 +53,4 @@ def save_trajectory_as_json(ctx_trackers, global_steps, prefix="train"):
# Print confirmation for evaluation trajectories
if prefix != "train":
- print(f"Saved trajectory to {traj_file_path}")
\ No newline at end of file
+ print(f"Saved trajectory to {traj_file_path}")
diff --git a/ajet/utils/msg_converter.py b/ajet/utils/msg_converter.py
index 0437f5ca..46c02128 100644
--- a/ajet/utils/msg_converter.py
+++ b/ajet/utils/msg_converter.py
@@ -21,8 +21,7 @@
{"role": "user/assistant/system", "content": "..."}
"""
-import json
-from typing import List, Dict, Any, Union
+from typing import List, Dict, Any
diff --git a/ajet/utils/networking.py b/ajet/utils/networking.py
index 9ed29c74..f2fed5ac 100644
--- a/ajet/utils/networking.py
+++ b/ajet/utils/networking.py
@@ -34,4 +34,4 @@ def get_host_ip(interface=None):
except Exception:
- return "127.0.0.1"
\ No newline at end of file
+ return "127.0.0.1"
diff --git a/ajet/utils/testing_utils.py b/ajet/utils/testing_utils.py
index 22be6092..31f006c2 100644
--- a/ajet/utils/testing_utils.py
+++ b/ajet/utils/testing_utils.py
@@ -11,7 +11,6 @@
from loguru import logger
from ajet.utils.dynamic_import import dynamic_import
-from ajet.utils.sington import singleton
class TestSuccessException(Exception):
@@ -19,7 +18,6 @@ class TestSuccessException(Exception):
All test is done, end the program early with exception.
"""
- pass
class TestFailException(Exception):
@@ -27,7 +25,6 @@ class TestFailException(Exception):
Test has failed, end the program early with exception.
"""
- pass
class BaseProbe(object):
diff --git a/ajet/utils/thread_executors.py b/ajet/utils/thread_executors.py
index 9c8ea634..1ab02baf 100644
--- a/ajet/utils/thread_executors.py
+++ b/ajet/utils/thread_executors.py
@@ -19,4 +19,4 @@ def __init__(self, max_workers=64):
self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=max_workers)
def get_shared_executor(self) -> concurrent.futures.ThreadPoolExecutor:
- return self.executor
\ No newline at end of file
+ return self.executor
diff --git a/docs/_toc.yml b/docs/_toc.yml
index ffa745f4..7eb76610 100644
--- a/docs/_toc.yml
+++ b/docs/_toc.yml
@@ -8,7 +8,7 @@ parts:
- file: en/installation.md
- file: en/quickstart.md
- file: en/tune_your_first_agent.md
-
+
- caption: Example
chapters:
- file: en/example_math_agent.md
@@ -17,13 +17,13 @@ parts:
- file: en/example_learning_to_ask.md
- file: en/example_frozenlake.md
- file: en/example_countdown.md
-
+
- caption: Component
chapters:
- file: en/workflow.md
- file: en/data_pipeline.md
- file: en/task_judger.md
-
+
- caption: Deep Dive
chapters:
- file: en/configuration.md
@@ -31,7 +31,7 @@ parts:
- file: en/beast_logger.md
- file: en/data_generation.md
- file: en/example_tracing_feedback_loop.md
-
+
# --- 中文部分 ---
- caption: 教程
@@ -40,7 +40,7 @@ parts:
- file: zh/installation.md
- file: zh/quickstart.md
- file: zh/tune_your_first_agent.md
-
+
- caption: 示例
chapters:
- file: zh/example_math_agent.md
@@ -49,13 +49,13 @@ parts:
- file: zh/example_learning_to_ask.md
- file: zh/example_frozenlake.md
- file: zh/example_countdown.md
-
+
- caption: 组件
chapters:
- file: zh/workflow.md
- file: zh/data_pipeline.md
- file: zh/task_judger.md
-
+
- caption: 深入探索
chapters:
- file: zh/configuration.md
@@ -63,4 +63,3 @@ parts:
- file: zh/beast_logger.md
- file: zh/data_generation.md
- file: zh/example_tracing_feedback_loop.md
-
diff --git a/docs/en/debugging_guide.md b/docs/en/debugging_guide.md
index 0a938004..ff7563a2 100644
--- a/docs/en/debugging_guide.md
+++ b/docs/en/debugging_guide.md
@@ -104,4 +104,3 @@ Then, the modified launch.json will be
| **VSCode Extension** | Python | Python + Ray Distributed Debugger |
| **Launch Mode** | `F5` standard launch (via `launch.json`) | Command line execution with `ajet ... --debug="TAG"` |
| **Commandline** | `--backbone=debug` | `--debug="TAG1\|TAG2\|TAG3"` |
-
diff --git a/docs/en/example_countdown.md b/docs/en/example_countdown.md
index e214e4d5..ff8ec4e3 100644
--- a/docs/en/example_countdown.md
+++ b/docs/en/example_countdown.md
@@ -201,4 +201,3 @@ However, tuning resolves these issues, as shown in the example below:

> **Token-level Visualization:** These detailed logs are generated by Beast-Logger. See [Beast-Logger Usage](./beast_logger.md) for more details.
-
diff --git a/docs/en/example_learning_to_ask.md b/docs/en/example_learning_to_ask.md
index c3d4bcf9..d5a17abe 100644
--- a/docs/en/example_learning_to_ask.md
+++ b/docs/en/example_learning_to_ask.md
@@ -135,7 +135,7 @@ We provide two implmentations of the agent based on AgentScope and langchain:
```python
# get the trainable llm
llm_info=tuner.as_oai_baseurl_apikey()
-
+
# create the langchain agent
llm=ChatOpenAI(
base_url=llm_info.base_url,
@@ -145,7 +145,7 @@ We provide two implmentations of the agent based on AgentScope and langchain:
model=llm,
system_prompt=system_prompt,
)
-
+
# build messages and send to the agent
msg=[
{"role": x["role"], "content": x["content"]} for x in messages
@@ -153,7 +153,7 @@ We provide two implmentations of the agent based on AgentScope and langchain:
result = agent.invoke({
"messages": msg, # type: ignore
})
-
+
response = result["messages"][-1].content
reward = await reward_fn_with_semaphore(msg, response, truth_action, truth_info)
return WorkflowOutput(reward=reward)
@@ -221,4 +221,4 @@ Agent: Has itching or reddening appeared around this bite site recently without
The question becomes more precise and informative, guiding the user to provide clinically relevant details.
-> To learn more about the task and results on larger models, refer to [Grounded in Reality: Learning and Deploying Proactive LLM from Offline Logs](https://arxiv.org/abs/2510.25441).
\ No newline at end of file
+> To learn more about the task and results on larger models, refer to [Grounded in Reality: Learning and Deploying Proactive LLM from Offline Logs](https://arxiv.org/abs/2510.25441).
diff --git a/docs/en/hardware_related_solution.md b/docs/en/hardware_related_solution.md
index c2cad4a3..9743d384 100644
--- a/docs/en/hardware_related_solution.md
+++ b/docs/en/hardware_related_solution.md
@@ -17,4 +17,4 @@ This document records a list of **Hardware Related** issues for future reference
```bash
export NCCL_NVLS_ENABLE=0
- ```
\ No newline at end of file
+ ```
diff --git a/docs/en/support_agentscope.md b/docs/en/support_agentscope.md
index b3129191..e551e4d9 100644
--- a/docs/en/support_agentscope.md
+++ b/docs/en/support_agentscope.md
@@ -223,4 +223,3 @@ This article introduce the way to convert different types of ways to convert you
else: is_success = False
return WorkflowOutput(reward=(1.0 if is_success else 0.0), metadata={"final_answer": final_answer})
```
-
diff --git a/docs/en/support_http.md b/docs/en/support_http.md
index 32474904..0bf3ab3d 100644
--- a/docs/en/support_http.md
+++ b/docs/en/support_http.md
@@ -93,5 +93,3 @@ in this AI era, you can always start from scratch and build your own "high-scrap
...
```
-
-
diff --git a/docs/en/support_langchain.md b/docs/en/support_langchain.md
index 6e645dcc..d1e12890 100644
--- a/docs/en/support_langchain.md
+++ b/docs/en/support_langchain.md
@@ -84,5 +84,3 @@ This article introduce the way to convert different types of ways to convert you
...
```
-
-
diff --git a/docs/en/support_oaisdk.md b/docs/en/support_oaisdk.md
index 5268ab42..b60b03e3 100644
--- a/docs/en/support_oaisdk.md
+++ b/docs/en/support_oaisdk.md
@@ -88,6 +88,3 @@ This article introduce the way to convert different types of ways to convert you
...
```
-
-
-
diff --git a/docs/index.md b/docs/index.md
index ba98cd7f..5583fa69 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -170,4 +170,3 @@ The internal system orchestrates several specialized modules to handle the compl
-->
-
diff --git a/docs/javascripts/animations.js b/docs/javascripts/animations.js
index 00e3603b..a5dc584a 100644
--- a/docs/javascripts/animations.js
+++ b/docs/javascripts/animations.js
@@ -399,4 +399,3 @@
};
})();
-
diff --git a/docs/javascripts/code-zoom.js b/docs/javascripts/code-zoom.js
index e2a08f6d..22d3d624 100644
--- a/docs/javascripts/code-zoom.js
+++ b/docs/javascripts/code-zoom.js
@@ -1,2 +1 @@
/* Code zoom - placeholder */
-
diff --git a/docs/javascripts/responsive.js b/docs/javascripts/responsive.js
index 663e371f..d57c4db2 100644
--- a/docs/javascripts/responsive.js
+++ b/docs/javascripts/responsive.js
@@ -353,4 +353,3 @@
};
})();
-
diff --git a/docs/javascripts/search-fix.js b/docs/javascripts/search-fix.js
index e8436240..444f2af9 100644
--- a/docs/javascripts/search-fix.js
+++ b/docs/javascripts/search-fix.js
@@ -1,2 +1 @@
/* Search fix - placeholder */
-
diff --git a/docs/javascripts/tabbed-code.js b/docs/javascripts/tabbed-code.js
index 880ba944..cfd19559 100644
--- a/docs/javascripts/tabbed-code.js
+++ b/docs/javascripts/tabbed-code.js
@@ -174,4 +174,3 @@
// Export for manual re-initialization if needed
window.initTabbedSets = initTabbedSets;
})();
-
diff --git a/docs/requirements.txt b/docs/requirements.txt
index 968bb898..db4f637c 100644
--- a/docs/requirements.txt
+++ b/docs/requirements.txt
@@ -11,4 +11,3 @@ pymdown-extensions==10.16.1
# Syntax highlighting
Pygments>=2.18.0
-
diff --git a/docs/stylesheets/animations.css b/docs/stylesheets/animations.css
index 2129b6d8..9d390ff7 100644
--- a/docs/stylesheets/animations.css
+++ b/docs/stylesheets/animations.css
@@ -875,4 +875,3 @@ img {
.duration-fast { animation-duration: var(--rm-transition-fast); }
.duration-normal { animation-duration: var(--rm-transition-normal); }
.duration-slow { animation-duration: var(--rm-transition-slow); }
-
diff --git a/docs/stylesheets/feature-cards.css b/docs/stylesheets/feature-cards.css
index 03fe0464..5865ca73 100644
--- a/docs/stylesheets/feature-cards.css
+++ b/docs/stylesheets/feature-cards.css
@@ -540,4 +540,3 @@
.dark {
--inline-icon-filter: invert(1) hue-rotate(180deg);
}
-
diff --git a/docs/stylesheets/flowchart.css b/docs/stylesheets/flowchart.css
index 175dc123..345b94f1 100644
--- a/docs/stylesheets/flowchart.css
+++ b/docs/stylesheets/flowchart.css
@@ -400,4 +400,3 @@
font-size: 0.875rem;
margin-bottom: 0.5rem;
}
-
diff --git a/docs/stylesheets/jupyter-simple.css b/docs/stylesheets/jupyter-simple.css
index 401abf67..864c59bd 100644
--- a/docs/stylesheets/jupyter-simple.css
+++ b/docs/stylesheets/jupyter-simple.css
@@ -256,4 +256,3 @@ article .cell.markdown ol:last-child {
top: 0.75rem;
}
}
-
diff --git a/docs/stylesheets/syntax-highlight.css b/docs/stylesheets/syntax-highlight.css
index 3c651185..7cfcf6ba 100644
--- a/docs/stylesheets/syntax-highlight.css
+++ b/docs/stylesheets/syntax-highlight.css
@@ -303,4 +303,3 @@
.dark .codehilite .language-json .nd {
color: #79c0ff;
}
-
diff --git a/docs/stylesheets/tuner_v2.md b/docs/stylesheets/tuner_v2.md
index c8766e31..c19509cd 100644
--- a/docs/stylesheets/tuner_v2.md
+++ b/docs/stylesheets/tuner_v2.md
@@ -78,4 +78,4 @@ response = client.chat.completions.create(
)
-```
\ No newline at end of file
+```
diff --git a/install.sh b/install.sh
index bf0400b6..2306bad0 100755
--- a/install.sh
+++ b/install.sh
@@ -203,7 +203,7 @@ download_binary_and_run_installer() {
local _checksum_value
# destructure selected archive info into locals
- case "$_artifact_name" in
+ case "$_artifact_name" in
"uv-aarch64-apple-darwin.tar.gz")
_arch="aarch64-apple-darwin"
_zip_ext=".tar.gz"
@@ -529,7 +529,7 @@ replace_home() {
json_binary_aliases() {
local _arch="$1"
- case "$_arch" in
+ case "$_arch" in
"aarch64-apple-darwin")
echo '{}'
;;
@@ -612,7 +612,7 @@ aliases_for_binary() {
local _bin="$1"
local _arch="$2"
- case "$_arch" in
+ case "$_arch" in
"aarch64-apple-darwin")
case "$_bin" in
*)
@@ -793,7 +793,7 @@ select_archive_for_arch() {
# try each archive, checking runtime conditions like libc versions
# accepting the first one that matches, as it's the best match
- case "$_true_arch" in
+ case "$_true_arch" in
"aarch64-apple-darwin")
_archive="uv-aarch64-apple-darwin.tar.gz"
if [ -n "$_archive" ]; then
diff --git a/mkdocs.yml b/mkdocs.yml
index 6a06d4ad..a6fa0585 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -147,4 +147,3 @@ extra_javascript:
- javascripts/nav-scroll-fix.js
- javascripts/animations.js
- javascripts/responsive.js
-
diff --git a/pyproject.toml b/pyproject.toml
index aee28b2b..856cddca 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -113,4 +113,4 @@ known_third_party = ["wandb"]
[project.urls]
-"Homepage" = "https://github.com/modelscope/AgentJet"
\ No newline at end of file
+"Homepage" = "https://github.com/modelscope/AgentJet"
diff --git a/scripts/display_dataset.py b/scripts/display_dataset.py
index e3132bc4..6d125e5c 100644
--- a/scripts/display_dataset.py
+++ b/scripts/display_dataset.py
@@ -1,10 +1,5 @@
import argparse
-import glob
-import os
-import time
-from beast_logger import print_list
-from huggingface_hub import snapshot_download
parser = argparse.ArgumentParser(description="download Hugging Face dataset")
parser.add_argument("--target", default="openai/gsm8k", type=str, help="HuggingFace dataset name")
diff --git a/tests/bench/benchmark_math/benchmark_math.py b/tests/bench/benchmark_math/benchmark_math.py
index 9d8397ca..973f9ea2 100644
--- a/tests/bench/benchmark_math/benchmark_math.py
+++ b/tests/bench/benchmark_math/benchmark_math.py
@@ -1,5 +1,4 @@
# flake8: noqa
-import os
import time
from ajet.utils.testing_utils import BenchmarkProbe, singleton
diff --git a/tests/test_networking.py b/tests/test_networking.py
deleted file mode 100644
index 913fc341..00000000
--- a/tests/test_networking.py
+++ /dev/null
@@ -1,56 +0,0 @@
-import socket
-import unittest
-import sys
-import os
-import importlib.util
-
-# Load the module directly to avoid top-level package import issues
-# caused by broken dependencies in other parts of the codebase.
-# We are testing a standalone utility, so we don't need the whole app context.
-module_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'ajet', 'utils', 'networking.py'))
-spec = importlib.util.spec_from_file_location("networking", module_path)
-networking = importlib.util.module_from_spec(spec)
-spec.loader.exec_module(networking)
-
-find_free_port = networking.find_free_port
-get_host_ip = networking.get_host_ip
-
-class TestNetworking(unittest.TestCase):
- def test_find_free_port(self):
- """Test that find_free_port returns a valid integer port."""
- port = find_free_port()
- self.assertIsInstance(port, int)
- self.assertGreater(port, 0)
- self.assertLess(port, 65536)
-
- # Verify the port is valid to bind to (it should have been released)
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
- try:
- s.bind(('', port))
- except OSError:
- # It's possible the port was taken immediately by another process
- # but unlikely in a test environment.
- pass
-
- def test_get_host_ip(self):
- """Test that get_host_ip returns a valid IP string."""
- ip = get_host_ip()
- self.assertIsInstance(ip, str)
- parts = ip.split('.')
- self.assertEqual(len(parts), 4)
- for part in parts:
- if part == 'localhost':
- continue
- self.assertTrue(part.isdigit(), f"Part {part} is not a digit")
- self.assertTrue(0 <= int(part) <= 255)
-
- def test_get_host_ip_with_interface(self):
- """Test get_host_ip with a non-existent interface falls back to default behavior."""
- # This will likely fail the interface specific block and fall back to the connect method
- ip = get_host_ip(interface="invalid_interface_XYZ")
- self.assertIsInstance(ip, str)
- parts = ip.split('.')
- self.assertEqual(len(parts), 4)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/tutorial/README.md b/tutorial/README.md
index e5811d8d..8e5288a9 100644
--- a/tutorial/README.md
+++ b/tutorial/README.md
@@ -8,4 +8,4 @@ Explore our rich library of examples to kickstart your journey.
- Example Benchmark Tracking System:
- https://benchmark.agent-matrix.com/examples
\ No newline at end of file
+ https://benchmark.agent-matrix.com/examples
diff --git a/tutorial/example_appworld/appworld.py b/tutorial/example_appworld/appworld.py
index d8b647e7..01816e67 100644
--- a/tutorial/example_appworld/appworld.py
+++ b/tutorial/example_appworld/appworld.py
@@ -1,5 +1,4 @@
from agentscope.message import Msg
-from pydantic import Field
from ajet import AjetTuner, Workflow, WorkflowOutput, WorkflowTask
diff --git a/tutorial/example_appworld/appworld_oai_sdk.py b/tutorial/example_appworld/appworld_oai_sdk.py
index 534ec00b..dc18db34 100644
--- a/tutorial/example_appworld/appworld_oai_sdk.py
+++ b/tutorial/example_appworld/appworld_oai_sdk.py
@@ -1,5 +1,4 @@
from agentscope.message import Msg
-from pydantic import Field
from ajet import Workflow, WorkflowOutput, WorkflowTask
from ajet import AjetTuner
diff --git a/tutorial/example_learn2ask/data_preprocess/llm_info_extraction.py b/tutorial/example_learn2ask/data_preprocess/llm_info_extraction.py
index 75e76c87..070b1612 100644
--- a/tutorial/example_learn2ask/data_preprocess/llm_info_extraction.py
+++ b/tutorial/example_learn2ask/data_preprocess/llm_info_extraction.py
@@ -145,4 +145,4 @@ def parse_llm_output(output_str):
return result
except Exception as e:
- return f"Error parsing output: [{repr(output_str)}] error = {str(e)}"
\ No newline at end of file
+ return f"Error parsing output: [{repr(output_str)}] error = {str(e)}"
diff --git a/tutorial/example_learn2ask/data_preprocess/message_splitter.py b/tutorial/example_learn2ask/data_preprocess/message_splitter.py
index a82506a4..06362b05 100644
--- a/tutorial/example_learn2ask/data_preprocess/message_splitter.py
+++ b/tutorial/example_learn2ask/data_preprocess/message_splitter.py
@@ -97,4 +97,4 @@ def split_session_to_json_lines(session):
json_lines = split_session_to_json_lines(example_session)
print("JSON lines output:")
for i, line in enumerate(json_lines):
- print(f"Line {i + 1}: {line}")
\ No newline at end of file
+ print(f"Line {i + 1}: {line}")
diff --git a/tutorial/example_learn2ask/data_preprocess/step1.py b/tutorial/example_learn2ask/data_preprocess/step1.py
index d2ba27c6..d4533ffa 100644
--- a/tutorial/example_learn2ask/data_preprocess/step1.py
+++ b/tutorial/example_learn2ask/data_preprocess/step1.py
@@ -28,14 +28,14 @@ def process_jsonl_file(
str: Success message or error information
"""
progress_file = output_file + ".progress"
-
+
def load_progress():
"""Load progress from progress file. Returns set of completed line numbers."""
if os.path.exists(progress_file):
with open(progress_file, "r", encoding="utf-8") as f:
return set(int(line.strip()) for line in f if line.strip())
return set()
-
+
def process_single_session(args):
"""Worker function to process a single session."""
line_num, line = args
@@ -54,41 +54,41 @@ def process_single_session(args):
return line_num, None, f"Warning: Skipping invalid JSON at line {line_num}: {e}"
except Exception as e:
return line_num, None, f"Warning: Error processing session at line {line_num}: {e}"
-
+
try:
# Load previous progress
completed_lines = load_progress()
if completed_lines:
print(f"Resuming from previous progress. {len(completed_lines)} lines already completed.")
-
+
# Read all lines first
with open(input_file, "r", encoding="utf-8") as infile:
all_lines = list(enumerate(infile, 1))
-
+
total_lines = len(all_lines)
# Filter out already completed lines
lines_to_process = [(num, line) for num, line in all_lines if num not in completed_lines]
-
+
if not lines_to_process:
print("All lines already processed.")
# Clean up progress file
if os.path.exists(progress_file):
os.remove(progress_file)
return f"All lines already processed. Results in {output_file}"
-
+
print(f"Processing {len(lines_to_process)} remaining lines out of {total_lines} total.")
-
+
# State for ordered writing
results_buffer = {} # line_num -> processed_lines
next_line_to_write = min(num for num, _ in lines_to_process)
write_lock = threading.Lock()
progress_lock = threading.Lock()
-
+
# Open output file in append mode if resuming, otherwise write mode
file_mode = "a" if completed_lines else "w"
outfile = open(output_file, file_mode, encoding="utf-8")
progress_out = open(progress_file, "a", encoding="utf-8")
-
+
def flush_buffer():
"""Write all consecutive completed results from buffer to file."""
nonlocal next_line_to_write
@@ -106,28 +106,28 @@ def flush_buffer():
# Skip lines that were already completed or empty
while next_line_to_write <= total_lines and next_line_to_write not in dict(lines_to_process):
next_line_to_write += 1
-
+
try:
# Process sessions in parallel using ThreadPoolExecutor
with ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = {executor.submit(process_single_session, item): item[0] for item in lines_to_process}
-
+
for future in as_completed(futures):
line_num, processed_lines, error = future.result()
if error:
print(error)
-
+
with write_lock:
results_buffer[line_num] = processed_lines
flush_buffer()
finally:
outfile.close()
progress_out.close()
-
+
# Clean up progress file on successful completion
if os.path.exists(progress_file):
os.remove(progress_file)
-
+
return f"Successfully processed. Results saved to {output_file}"
except Exception as e:
@@ -177,7 +177,7 @@ def process_session(session, model_call_mode="online_api", max_retries=3, **kwar
print(f"Attempt {attempt + 1} failed with exception: {str(e)}")
if attempt < max_retries - 1:
time.sleep(24) # Shorter wait for testing
-
+
if info_set is None:
raise Exception(f"failed to generate {session}")
data["info_set"] = info_set
@@ -206,4 +206,4 @@ def process_session(session, model_call_mode="online_api", max_retries=3, **kwar
model_call_mode=args.model_call_mode,
# Additional parameters for API calls
)
- )
\ No newline at end of file
+ )
diff --git a/tutorial/example_learn2ask/data_preprocess/step2.py b/tutorial/example_learn2ask/data_preprocess/step2.py
index 849aa510..9d546b0c 100644
--- a/tutorial/example_learn2ask/data_preprocess/step2.py
+++ b/tutorial/example_learn2ask/data_preprocess/step2.py
@@ -26,7 +26,7 @@ def main(input_file_path, output_file_path):
if_keep, info_set, decision = process_message(data)
if not if_keep:
continue
-
+
new_item = {
'main_query':'[no query]',
'init_messages': data['messages'],
@@ -56,4 +56,4 @@ def main(input_file_path, output_file_path):
args = parser.parse_args()
- main(args.input_file, args.output_file)
\ No newline at end of file
+ main(args.input_file, args.output_file)
diff --git a/tutorial/example_learn2ask/learn2ask.md b/tutorial/example_learn2ask/learn2ask.md
index d5afd08f..811d37f9 100644
--- a/tutorial/example_learn2ask/learn2ask.md
+++ b/tutorial/example_learn2ask/learn2ask.md
@@ -99,4 +99,4 @@ The agent's question is more precise and informative, providing two specific and
## Next
-To learn more about the task and results on larger models, refer to [Grounded in Reality: Learning and Deploying Proactive LLM from Offline Logs](https://arxiv.org/abs/2510.25441).
\ No newline at end of file
+To learn more about the task and results on larger models, refer to [Grounded in Reality: Learning and Deploying Proactive LLM from Offline Logs](https://arxiv.org/abs/2510.25441).
diff --git a/tutorial/example_learn2ask/learn2ask_langchain.py b/tutorial/example_learn2ask/learn2ask_langchain.py
index d728ac64..b15d7309 100644
--- a/tutorial/example_learn2ask/learn2ask_langchain.py
+++ b/tutorial/example_learn2ask/learn2ask_langchain.py
@@ -4,7 +4,6 @@
import asyncio
import threading
-from agentscope.message import Msg
from loguru import logger
from ajet import AjetTuner, Workflow, WorkflowOutput, WorkflowTask
@@ -174,26 +173,26 @@ async def execute(self, workflow_task: WorkflowTask, tuner: AjetTuner) -> Workfl
assert isinstance(messages, list)
truth_action = workflow_task.task.metadata["decision_truth"] or "continue"
truth_info = workflow_task.task.metadata["info_truth"]
-
+
llm_info=tuner.as_oai_baseurl_apikey()
-
+
llm=ChatOpenAI(
base_url=llm_info.base_url,
api_key=lambda:llm_info.api_key,
)
-
+
agent=create_agent(
model=llm,
system_prompt=system_prompt,
)
-
+
msg=[
{"role": x["role"], "content": x["content"]} for x in messages
]
result = agent.invoke({
"messages": msg, # type: ignore
})
-
+
response = result["messages"][-1].content
reward = await reward_fn_with_semaphore(msg, response, truth_action, truth_info)
return WorkflowOutput(reward=reward)
diff --git a/tutorial/example_ma_deepresearch/ma_deepresearch.py b/tutorial/example_ma_deepresearch/ma_deepresearch.py
index 9eaba34c..d044458b 100644
--- a/tutorial/example_ma_deepresearch/ma_deepresearch.py
+++ b/tutorial/example_ma_deepresearch/ma_deepresearch.py
@@ -2,13 +2,8 @@
from loguru import logger
from pydantic import BaseModel, Field
from ajet import AjetTuner, Workflow, WorkflowOutput, WorkflowTask
-from openai.types.chat.chat_completion import ChatCompletion
-from openai.types.chat import ChatCompletionMessageToolCall
-from textwrap import dedent
-import json
import os
-import asyncio
import requests
diff --git a/tutorial/example_math_agent/math_agent_langchain.py b/tutorial/example_math_agent/math_agent_langchain.py
index c47fc355..4c99d240 100644
--- a/tutorial/example_math_agent/math_agent_langchain.py
+++ b/tutorial/example_math_agent/math_agent_langchain.py
@@ -1,12 +1,6 @@
-from loguru import logger
from ajet import AjetTuner, Workflow, WorkflowOutput, WorkflowTask
-from openai.types.chat.chat_completion import ChatCompletion
-from openai.types.chat import ChatCompletionMessageToolCall
from textwrap import dedent
-import json
-import asyncio
-import requests
from langchain.agents import create_agent
@@ -30,7 +24,7 @@ async def execute(self, workflow_task: WorkflowTask, tuner: AjetTuner) -> Workfl
url_and_apikey = tuner.as_oai_baseurl_apikey()
base_url = url_and_apikey.base_url
api_key = url_and_apikey.api_key
-
+
from langchain_openai import ChatOpenAI
llm=ChatOpenAI(
base_url=base_url,
@@ -40,10 +34,10 @@ async def execute(self, workflow_task: WorkflowTask, tuner: AjetTuner) -> Workfl
model=llm,
system_prompt=self.system_prompt,
)
-
+
# take out query
query = workflow_task.task.main_query
-
+
response = agent.invoke({
"messages": [
{
@@ -52,6 +46,6 @@ async def execute(self, workflow_task: WorkflowTask, tuner: AjetTuner) -> Workfl
}
],
})
-
+
final_answer = response['messages'][-1].content
- return WorkflowOutput(reward=None, metadata={"final_answer": final_answer})
\ No newline at end of file
+ return WorkflowOutput(reward=None, metadata={"final_answer": final_answer})
diff --git a/tutorial/example_math_agent/math_agent_oai_sdk.py b/tutorial/example_math_agent/math_agent_oai_sdk.py
index 8304f14d..24bf47ec 100644
--- a/tutorial/example_math_agent/math_agent_oai_sdk.py
+++ b/tutorial/example_math_agent/math_agent_oai_sdk.py
@@ -1,4 +1,3 @@
-from loguru import logger
from ajet import AjetTuner, Workflow, WorkflowOutput, WorkflowTask
from openai.types.chat.chat_completion import ChatCompletion
from openai.types.chat import ChatCompletionMessageToolCall
diff --git a/tutorial/example_math_agent/math_agent_raw_http.py b/tutorial/example_math_agent/math_agent_raw_http.py
index 6608e2be..69dfd949 100644
--- a/tutorial/example_math_agent/math_agent_raw_http.py
+++ b/tutorial/example_math_agent/math_agent_raw_http.py
@@ -1,11 +1,6 @@
-from loguru import logger
from ajet import AjetTuner, Workflow, WorkflowOutput, WorkflowTask
-from openai.types.chat.chat_completion import ChatCompletion
-from openai.types.chat import ChatCompletionMessageToolCall
from textwrap import dedent
-import json
-import asyncio
import requests
@@ -57,8 +52,3 @@ async def execute(self, workflow_task: WorkflowTask, tuner: AjetTuner) -> Workfl
)
final_answer = response.json()['choices'][0]['message']['content']
return WorkflowOutput(reward=None, metadata={"final_answer": final_answer})
-
-
-
-
-
diff --git a/tutorial/example_werewolves/start.py b/tutorial/example_werewolves/start.py
index 554b0977..879b6101 100644
--- a/tutorial/example_werewolves/start.py
+++ b/tutorial/example_werewolves/start.py
@@ -12,7 +12,7 @@
from agentscope.agent import ReActAgent
from agentscope.formatter import DashScopeMultiAgentFormatter, OpenAIMultiAgentFormatter
-from agentscope.model import DashScopeChatModel, OpenAIChatModel
+from agentscope.model import OpenAIChatModel
from loguru import logger
from pydantic import Field