|
|
@@ -38,9 +38,10 @@ from agent.trace import (
|
|
|
)
|
|
|
from agent.llm import create_openrouter_llm_call
|
|
|
from agent.cli import InteractiveController
|
|
|
+from agent.utils import setup_logging
|
|
|
|
|
|
# 导入项目配置
|
|
|
-from config import RUNNER_CONFIG, setup_logging
|
|
|
+from config import RUN_CONFIG, SKILLS_DIR, TRACE_STORE_PATH, DEBUG, LOG_LEVEL, LOG_FILE
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
@@ -59,15 +60,11 @@ async def main():
|
|
|
output_dir = base_dir / "output_1"
|
|
|
output_dir.mkdir(exist_ok=True)
|
|
|
|
|
|
- # 1. 使用配置
|
|
|
- print("1. 加载配置...")
|
|
|
- runner_config = RUNNER_CONFIG
|
|
|
- print(f" - 已加载配置")
|
|
|
+ # 1. 配置日志
|
|
|
+ setup_logging(level=LOG_LEVEL, file=LOG_FILE)
|
|
|
|
|
|
- # 配置日志
|
|
|
- setup_logging(runner_config.logging)
|
|
|
-
|
|
|
- # 加载项目级 presets
|
|
|
+ # 2. 加载项目级 presets
|
|
|
+ print("2. 加载 presets...")
|
|
|
presets_path = base_dir / "presets.json"
|
|
|
if presets_path.exists():
|
|
|
import json
|
|
|
@@ -77,63 +74,57 @@ async def main():
|
|
|
register_preset(name, AgentPreset(**cfg))
|
|
|
print(f" - 已加载项目 presets: {list(project_presets.keys())}")
|
|
|
|
|
|
- # Skills 目录
|
|
|
- skills_dir = runner_config.skills_dir
|
|
|
-
|
|
|
- # 任务名称
|
|
|
- task_name = runner_config.name or base_dir.name
|
|
|
- print("=" * 60)
|
|
|
- print(f"{task_name} (Agent 模式 + 交互增强)")
|
|
|
- print("=" * 60)
|
|
|
- print()
|
|
|
- print("💡 交互提示:")
|
|
|
- print(" - 执行过程中输入 'p' 或 'pause' 暂停并进入交互模式")
|
|
|
- print(" - 执行过程中输入 'q' 或 'quit' 停止执行")
|
|
|
- print("=" * 60)
|
|
|
- print()
|
|
|
-
|
|
|
- # 2. 加载 prompt
|
|
|
- print("2. 加载 prompt 配置...")
|
|
|
+ # 3. 加载 prompt
|
|
|
+ print("3. 加载 prompt...")
|
|
|
prompt = SimplePrompt(prompt_path)
|
|
|
|
|
|
- # 3. 构建消息
|
|
|
- print("3. 构建任务消息...")
|
|
|
+ # 4. 构建任务消息
|
|
|
+ print("4. 构建任务消息...")
|
|
|
messages = prompt.build_messages()
|
|
|
|
|
|
- # 4. 创建 Agent Runner
|
|
|
- print("4. 创建 Agent Runner...")
|
|
|
- print(f" - Skills 目录: {skills_dir}")
|
|
|
- print(f" - 模型: {runner_config.model}")
|
|
|
- print(f" - 日志级别: {runner_config.logging.level}")
|
|
|
+ # 5. 创建 Agent Runner
|
|
|
+ print("5. 创建 Agent Runner...")
|
|
|
+ print(f" - Skills 目录: {SKILLS_DIR}")
|
|
|
+ print(f" - 模型: {RUN_CONFIG.model}")
|
|
|
|
|
|
- store = FileSystemTraceStore(base_path=runner_config.trace_store_path)
|
|
|
+ store = FileSystemTraceStore(base_path=TRACE_STORE_PATH)
|
|
|
runner = AgentRunner(
|
|
|
trace_store=store,
|
|
|
- llm_call=create_openrouter_llm_call(model=f"anthropic/claude-{runner_config.model}"),
|
|
|
- skills_dir=skills_dir,
|
|
|
- debug=runner_config.debug,
|
|
|
- knowledge_config=runner_config.knowledge
|
|
|
+ llm_call=create_openrouter_llm_call(model=f"anthropic/{RUN_CONFIG.model}"),
|
|
|
+ skills_dir=SKILLS_DIR,
|
|
|
+ debug=DEBUG
|
|
|
)
|
|
|
|
|
|
- # 5. 创建交互控制器
|
|
|
+ # 6. 创建交互控制器
|
|
|
interactive = InteractiveController(
|
|
|
runner=runner,
|
|
|
store=store,
|
|
|
enable_stdin_check=True
|
|
|
)
|
|
|
|
|
|
- # 6. 判断是新建还是恢复
|
|
|
+ # 7. 任务信息
|
|
|
+ task_name = RUN_CONFIG.name or base_dir.name
|
|
|
+ print("=" * 60)
|
|
|
+ print(f"{task_name}")
|
|
|
+ print("=" * 60)
|
|
|
+ print("💡 交互提示:")
|
|
|
+ print(" - 执行过程中输入 'p' 或 'pause' 暂停并进入交互模式")
|
|
|
+ print(" - 执行过程中输入 'q' 或 'quit' 停止执行")
|
|
|
+ print("=" * 60)
|
|
|
+ print()
|
|
|
+
|
|
|
+ # 8. 判断是新建还是恢复
|
|
|
resume_trace_id = args.trace
|
|
|
if resume_trace_id:
|
|
|
existing_trace = await store.get_trace(resume_trace_id)
|
|
|
if not existing_trace:
|
|
|
print(f"\n错误: Trace 不存在: {resume_trace_id}")
|
|
|
sys.exit(1)
|
|
|
- print(f"5. 恢复已有 Trace: {resume_trace_id[:8]}...")
|
|
|
+ print(f"恢复已有 Trace: {resume_trace_id[:8]}...")
|
|
|
print(f" - 状态: {existing_trace.status}")
|
|
|
print(f" - 消息数: {existing_trace.total_messages}")
|
|
|
else:
|
|
|
- print(f"5. 启动新 Agent 模式...")
|
|
|
+ print(f"启动新 Agent...")
|
|
|
|
|
|
print()
|
|
|
|
|
|
@@ -144,22 +135,13 @@ async def main():
|
|
|
|
|
|
try:
|
|
|
# 配置
|
|
|
+ run_config = RUN_CONFIG
|
|
|
if resume_trace_id:
|
|
|
initial_messages = None
|
|
|
- run_config = RunConfig(
|
|
|
- model=f"claude-{runner_config.model}",
|
|
|
- temperature=runner_config.temperature,
|
|
|
- max_iterations=runner_config.max_iterations,
|
|
|
- trace_id=resume_trace_id,
|
|
|
- )
|
|
|
+ run_config.trace_id = resume_trace_id
|
|
|
else:
|
|
|
initial_messages = messages
|
|
|
- run_config = RunConfig(
|
|
|
- model=f"claude-{runner_config.model}",
|
|
|
- temperature=runner_config.temperature,
|
|
|
- max_iterations=runner_config.max_iterations,
|
|
|
- name=f"{task_name}:调研任务",
|
|
|
- )
|
|
|
+ run_config.name = f"{task_name}:调研任务"
|
|
|
|
|
|
while not should_exit:
|
|
|
if current_trace_id:
|
|
|
@@ -297,22 +279,6 @@ async def main():
|
|
|
|
|
|
# Runner 退出后显示交互菜单
|
|
|
if current_trace_id:
|
|
|
- # 自动触发反思(如果配置启用)
|
|
|
- check_trace = await store.get_trace(current_trace_id)
|
|
|
- if check_trace and check_trace.status in ("completed", "failed"):
|
|
|
- auto_reflect = runner_config.auto_reflect
|
|
|
- if auto_reflect.enabled:
|
|
|
- should_reflect = False
|
|
|
- if check_trace.status == "completed" and auto_reflect.on_completion:
|
|
|
- should_reflect = True
|
|
|
- elif check_trace.status == "failed" and auto_reflect.on_failure:
|
|
|
- should_reflect = True
|
|
|
-
|
|
|
- if should_reflect and check_trace.total_messages >= auto_reflect.min_messages:
|
|
|
- print(f"\n⚙️ 任务已结束 (状态: {check_trace.status}),正在自动触发经验总结...")
|
|
|
- auto_focus = auto_reflect.focus_on_failure if check_trace.status == "failed" else ""
|
|
|
- await interactive.perform_reflection(current_trace_id, focus=auto_focus)
|
|
|
-
|
|
|
menu_result = await interactive.show_menu(current_trace_id, current_sequence)
|
|
|
|
|
|
if menu_result["action"] == "stop":
|