init: minimal submit agent

This commit is contained in:
z3st
2026-07-21 18:45:22 +08:00
commit fefc5688e1
5 changed files with 109 additions and 0 deletions

4
.dockerignore Normal file
View File

@@ -0,0 +1,4 @@
__pycache__
*.pyc
.git
.dockerignore

14
Dockerfile Normal file
View File

@@ -0,0 +1,14 @@
FROM modelhubxc-4pd.tencentcloudcr.com/xc_agent_platform/python:3.11-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8080
CMD ["python", "main.py"]

16
README.md Normal file
View File

@@ -0,0 +1,16 @@
# ModelHub 提交智能体
用于获取 `strategyId` 的最小化智能体。
## 功能
- `GET /health` → 健康检查
- `GET /` → 显示 strategyId
## 平台要求
- ✅ 根目录 Dockerfile
- ✅ 暴露 8080 端口
-`/health` 端点返回 200
- ✅ 处理 SIGTERM 信号
- ✅ 读取 `STRATEGY_ID` 环境变量

74
main.py Normal file
View File

@@ -0,0 +1,74 @@
"""
ModelHub 提交智能体(代理模式)
用途:获取 strategyId本地脚本直接调用 ModelHub API
"""
import json
import os
import signal
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
HOST = "0.0.0.0"
PORT = 8080
shutdown_requested = False
def _config() -> dict:
strategy_id = os.getenv("STRATEGY_ID", "")
return {
"strategy_id": strategy_id,
"status": "running",
}
class Handler(BaseHTTPRequestHandler):
def do_GET(self) -> None:
if self.path == "/health":
self._send_json({"status": "ok"})
return
if self.path == "/":
self._send_json({
"name": "modelhub-submit-agent",
"config": _config(),
})
return
self._send_json({"error": "not found"}, status=404)
def log_message(self, fmt: str, *args: object) -> None:
print(f"{self.address_string()} - {fmt % args}", flush=True)
def _send_json(self, body: dict, status: int = 200) -> None:
payload = json.dumps(body).encode()
self.send_response(status)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(payload)))
self.end_headers()
self.wfile.write(payload)
def _handle_signal(signum: int, _frame: object) -> None:
global shutdown_requested
shutdown_requested = True
print(f"received signal {signum}, shutting down", flush=True)
def main() -> None:
signal.signal(signal.SIGTERM, _handle_signal)
signal.signal(signal.SIGINT, _handle_signal)
server = ThreadingHTTPServer((HOST, PORT), Handler)
server.timeout = 1
strategy_id = os.getenv("STRATEGY_ID", "NOT_SET")
print(f"modelhub-submit-agent listening on {HOST}:{PORT}", flush=True)
print(f"STRATEGY_ID: {strategy_id}", flush=True)
while not shutdown_requested:
server.handle_request()
server.server_close()
if __name__ == "__main__":
main()

1
requirements.txt Normal file
View File

@@ -0,0 +1 @@
# No external dependencies needed