The standalone prototype should be the root-level project shape for fengqun while preserving the existing planning documents already at the root. This keeps README, examples, tests, and the Python package directly discoverable without deleting the prior docs. Constraint: User clarified that swarm-minimal is the repository root, but other existing root files must remain. Rejected: Deleting existing root docs | They are part of the fengqun repository context and were explicitly protected. Confidence: high Scope-risk: narrow Directive: Keep secrets in ignored .env only; do not commit live credentials. Tested: python3 -B -m unittest discover -s tests; git diff --check; secret-pattern scan showed only placeholders/test values/task-id false positives. Not-tested: Remote web UI rendering after push.
64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
from pathlib import Path
|
|
import json
|
|
import sys
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from swarm_minimal.azure_store import PostgresRedisBlobSwarmStore
|
|
from swarm_minimal.config import SwarmConfig
|
|
from swarm_minimal.core import SwarmCoordinator, Task
|
|
from swarm_minimal.local_env import load_env_file
|
|
from swarm_minimal.newapi_agnet import (
|
|
NewApiChannelConfig,
|
|
build_model_test_agnets,
|
|
discover_newapi_models,
|
|
select_distinct_models,
|
|
)
|
|
|
|
|
|
def main() -> None:
|
|
load_env_file(ROOT / ".env")
|
|
azure_config = SwarmConfig.from_env()
|
|
newapi_config = NewApiChannelConfig.from_env()
|
|
print("azure_config:")
|
|
print(json.dumps(azure_config.redacted_summary(), ensure_ascii=False, indent=2))
|
|
print("newapi_config:")
|
|
print(json.dumps(newapi_config.redacted_summary(), ensure_ascii=False, indent=2))
|
|
|
|
store = PostgresRedisBlobSwarmStore(azure_config)
|
|
try:
|
|
store.ensure_schema()
|
|
models = select_distinct_models(discover_newapi_models(newapi_config), count=3)
|
|
print("selected_models:")
|
|
for model in models:
|
|
print(f"- {model}")
|
|
|
|
agents = build_model_test_agnets(newapi_config, models=models)
|
|
coordinator = SwarmCoordinator(store=store, agents=agents)
|
|
goal = "full live test: Azure-backed swarm with three NewAPI model Agnets"
|
|
run_id = coordinator.submit_goal(goal)
|
|
|
|
for index, model in enumerate(models):
|
|
store.add_task(
|
|
Task(
|
|
kind=f"model_test_{index + 1}",
|
|
input=f"{goal}; model={model}",
|
|
)
|
|
)
|
|
|
|
result = coordinator.run_until_converged(run_id)
|
|
print("run_id:", result.run_id)
|
|
print("accepted_score:", result.accepted_score)
|
|
print("completed_tasks:", result.completed_tasks)
|
|
print("accepted_task_id:", result.accepted_task_id)
|
|
print("accepted_output:", result.accepted_output)
|
|
print("artifact_path:", f"swarm-runs/{result.run_id}/result.json")
|
|
finally:
|
|
store.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|