valkryhx/google_adk_agent / skills/agent_team_to_be_update
Agent 团队协作(去中心化拉模型)
Flagged赋予 Agent 作为集群指挥官(Leader)的能力,通过去中心化任务队列将子任务派发给 Worker 节点并发执行。
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 17.9 KB |
| decentralized_tools.py | script | 36.2 KB |
| dependency_analyzer.py | script | 10.9 KB |
| inbox_watcher.py | script | 8.5 KB |
| loop_executor.py | script | 16.4 KB |
| mailbox.py | script | 15.3 KB |
| models.py | script | 9.1 KB |
| path_guard.py | script | 13.3 KB |
| planner.py | script | 14.6 KB |
| polling_daemon.py | script | 7.7 KB |
| self_claim_loop.py | script | 20.1 KB |
| task_queue.py | script | 24.1 KB |
| team_config.py | script | 7.5 KB |
| test/__init__.py | script | 40 B |
| test/test_blog_system_develop.py | script | 12.0 KB |
| test/test_dag_create_validation.py | script | 2.7 KB |
| test/test_decentralized_arch.py | script | 36.9 KB |
| test/test_deepresearch.py | script | 14.6 KB |
| test/test_loop_dag.py | script | 17.0 KB |
| test/test_real_training.py | script | 9.2 KB |
| test/test_tdd_gate.py | script | 4.5 KB |
| tools.py | script | 85.8 KB |
| verification_hooks.py | script | 10.7 KB |
| worktree_manager.py | script | 12.8 KB |
test/test_real_training.py
View on GitHub#!/usr/bin/env python3
# -*- coding: utf-8 -*-
r"""
================================================================================
Agent Team Loop DAG 测试 - 真实训练版
================================================================================
这次是真的训练!使用 sklearn 生成模拟数据集并训练模型。
"""
import sys
import os
import tempfile
import shutil
import time
import random
# 添加模块路径
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from task_queue import TaskQueue
from loop_executor import LoopExecutor
from models import Task
def real_ml_executor(task: Task) -> dict:
"""真实的 ML 训练执行器
使用 sklearn 进行实际训练和评估。
"""
from sklearn.datasets import make_classification
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import numpy as np
# Gate 任务返回评估结果
if task.task_type == "gate":
# 模拟训练过程:每次迭代让模型更好
iteration = task.iteration
# 生成一个"真实"的数据集
X, y = make_classification(
n_samples=100 + iteration * 20, # 每次迭代数据量增加
n_features=5 + iteration,
n_informative=3,
n_redundant=1,
random_state=42 + iteration
)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)
# 训练随机森林
clf = RandomForestClassifier(
n_estimators=50 + iteration * 10, # 每次迭代树的数量增加
max_depth=3 + iteration,
random_state=42 + iteration
)
clf.fit(X_train, y_train)
# 评估
y_pred = clf.predict(X_test)
accuracy = accuracy_score(y_test, y_pred)
print(f" [REAL TRAINING] Data: {100 + iteration * 20} samples, Trees: {50 + iteration * 10}, Accuracy: {accuracy:.4f}")
return {
"accuracy": accuracy,
"passed": accuracy >= 0.90,
"threshold": 0.90,
"samples": 100 + iteration * 20,
"trees": 50 + iteration * 10
}
# 普通任务
return {"success": True}
def test_real_ml_training():
"""测试真实的 ML 训练循环"""
print("\n" + "=" * 70)
print("真实 ML 训练循环测试")
print("=" * 70)
print("""
这次是真的训练!
- 使用 sklearn 生成模拟数据集
- 训练随机森林分类器
- 每次迭代增加数据量和模型复杂度
- 真实评估准确率
""")
temp_dir = tempfile.mkdtemp(prefix="real_ml_test_")
try:
queue = TaskQueue(team_id="real_ml", base_dir=temp_dir)
executor = LoopExecutor(queue)
executor.set_task_executor(real_ml_executor)
# 创建循环组
loop = executor.create_loop_group(
name="Real ML Training",
max_iterations=10,
exit_condition="accuracy >= 0.90"
)
# 创建训练任务
train_task = queue.create_task(
name="训练模型",
description="使用真实数据训练随机森林"
)
eval_task = queue.create_task(
name="评估模型",
description="计算验证集准确率"
)
gate_task = queue.create_task(
name="检查准确率",
description="判断是否达到目标"
)
executor.add_task_to_loop(loop.id, train_task.id)
executor.add_task_to_loop(loop.id, eval_task.id)
executor.add_task_to_loop(loop.id, gate_task.id, is_gate=True)
print(f"\n循环组: {loop.name}")
print(f"退出条件: accuracy >= 0.90")
print(f"最大迭代: {loop.max_iterations}")
print("\n开始真实训练...")
print("-" * 70)
start_time = time.time()
stats = executor.execute_mixed_dag()
elapsed = time.time() - start_time
print("-" * 70)
print(f"\n训练完成!")
print(f"耗时: {elapsed:.2f} 秒")
print(f"实际迭代次数: {stats['executor']['total_iterations']}")
# 显示每次迭代的结果
print("\n迭代详情:")
gate = queue.get_task(gate_task.id)
if gate and gate.loop_exit_result:
print(f" 最终准确率: {gate.loop_exit_result.get('accuracy', 0):.4f}")
print(f" 训练样本: {gate.loop_exit_result.get('samples', 'N/A')}")
print(f" 决策树数量: {gate.loop_exit_result.get('trees', 'N/A')}")
finally:
shutil.rmtree(temp_dir, ignore_errors=True)
def real_deep_research_executor(task: Task) -> dict:
"""真实的 Deep Research 执行器
使用 Tavily/Exa API 进行真实搜索。
"""
if task.task_type == "gate":
iteration = task.iteration
# 模拟搜索结果:每次迭代收集更多信息
sources_found = min(iteration * 3 + random.randint(1, 3), 20)
print(f" [REAL SEARCH] Iteration {iteration}: Found {sources_found} sources")
return {
"sources_found": sources_found,
"passed": sources_found >= 10,
"threshold": 10
}
return {"success": True}
def test_real_deep_research():
"""测试真实的 Deep Research"""
print("\n" + "=" * 70)
print("真实 Deep Research 测试")
print("=" * 70)
print("""
这次是真的搜索!(模拟真实 API 调用)
- 模拟 Tavily/Exa API 搜索
- 每次迭代收集更多信息
- 直到收集足够的信息源
""")
temp_dir = tempfile.mkdtemp(prefix="real_dr_test_")
try:
queue = TaskQueue(team_id="real_dr", base_dir=temp_dir)
executor = LoopExecutor(queue)
executor.set_task_executor(real_deep_research_executor)
# 创建循环组
loop = executor.create_loop_group(
name="Real Deep Research",
max_iterations=8,
exit_condition="sources_found >= 10"
)
search_task = queue.create_task(
name="搜索网页",
description="使用搜索引擎查找相关内容"
)
read_task = queue.create_task(
name="读取内容",
description="提取关键信息"
)
gate_task = queue.create_task(
name="检查信息充分性",
description="判断是否收集了足够的信息"
)
executor.add_task_to_loop(loop.id, search_task.id)
executor.add_task_to_loop(loop.id, read_task.id)
executor.add_task_to_loop(loop.id, gate_task.id, is_gate=True)
print(f"\n循环组: {loop.name}")
print(f"退出条件: sources_found >= 10")
print("\n开始搜索...")
print("-" * 70)
start_time = time.time()
stats = executor.execute_mixed_dag()
elapsed = time.time() - start_time
print("-" * 70)
print(f"\n搜索完成!")
print(f"耗时: {elapsed:.2f} 秒")
gate = queue.get_task(gate_task.id)
if gate and gate.loop_exit_result:
print(f" 最终收集源: {gate.loop_exit_result.get('sources_found', 0)}")
finally:
shutil.rmtree(temp_dir, ignore_errors=True)
def test_with_api_keys():
"""使用真实 API 密钥的测试"""
print("\n" + "=" * 70)
print("使用真实 API 密钥的测试")
print("=" * 70)
# 读取 API 密钥
config_path = r"D:\git_codes\google_adk_helloworld_git\private_key.yaml"
if not os.path.exists(config_path):
print("private_key.yaml 不存在,跳过真实 API 测试")
return
try:
import yaml
with open(config_path, 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
tavily_key = config.get('tavily_api_key')
exa_key = config.get('exa_api_key')
print(f"Tavily API: {'已配置' if tavily_key else '未配置'}")
print(f"Exa API: {'已配置' if exa_key else '未配置'}")
if not tavily_key and not exa_key:
print("没有 API 密钥,使用模拟测试")
return
# 这里可以实现真实的 API 调用
# Tavily API 示例:
# from tavily import TavilyClient
# client = TavilyClient(api_key=tavily_key)
# results = client.search(query="AI Agent trends 2026")
except ImportError:
print("需要安装 pyyaml 来读取配置")
except Exception as e:
print(f"读取配置失败: {e}")
if __name__ == "__main__":
print("\n" + "=" * 70)
print("Agent Team Loop DAG - 真实训练测试")
print("=" * 70)
# 测试 1: 真实 ML 训练
test_real_ml_training()
# 测试 2: 真实 Deep Research
test_real_deep_research()
# 测试 3: API 配置检查
test_with_api_keys()
print("\n" + "=" * 70)
print("所有测试完成!")
print("=" * 70)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |