FEAT(app): add SSH tool for host access
- Add execute_ssh tool for accessing host system (oracle-master)
- Update all agent prompts to explain container vs host environment
- Research Agent: Guide to use SSH for kubectl, Projects, PostgreSQL
- Code Agents: Guide to use SSH for file creation and Git operations
- Infrastructure Agent: Guide to use SSH for YAML files and kubectl
- Orchestrator: Add system environment context
This fixes:
- kubectl 'Exec format error' (now uses SSH with sudo)
- /app/repos/ not found (now uses /home/ubuntu/Projects/)
- PostgreSQL connection errors (now uses correct host address)
- Git repository access issues (now uses SSH to access host repos)
Example usage:
- execute_ssh('kubectl get pods -n mas', use_sudo=True)
- execute_ssh('ls -la /home/ubuntu/Projects')
- execute_ssh('cd /home/ubuntu/Projects/mas && git status')
This commit is contained in:
@@ -50,11 +50,16 @@ BACKEND_PROMPT = """당신은 Multi-Agent System의 **Backend Code Agent**입니
|
||||
- 캐싱 활용 (Redis)
|
||||
- 비동기 처리
|
||||
|
||||
## execute_bash 활용 예시:
|
||||
- 파일 생성: execute_bash("cat > /app/repos/project/api/users.py << 'EOF'\\n코드내용\\nEOF")
|
||||
- Git 커밋: execute_bash("cd /app/repos/project && git add . && git commit -m 'Add user API'")
|
||||
- 테스트 실행: execute_bash("cd /app/repos/project && pytest tests/")
|
||||
- DB 마이그레이션: execute_bash("cd /app/repos/project && alembic upgrade head")
|
||||
## 도구 사용 가이드:
|
||||
|
||||
### execute_ssh (호스트 작업용) ⭐ 주로 사용:
|
||||
- 파일 생성: execute_ssh("cat > /home/ubuntu/Projects/myproject/api/users.py << 'EOF'\\n코드내용\\nEOF")
|
||||
- Git 커밋: execute_ssh("cd /home/ubuntu/Projects/myproject && git add . && git commit -m 'Add user API'")
|
||||
- 테스트 실행: execute_ssh("cd /home/ubuntu/Projects/myproject && pytest tests/")
|
||||
- DB 마이그레이션: execute_ssh("cd /home/ubuntu/Projects/myproject && alembic upgrade head")
|
||||
|
||||
### execute_bash (컨테이너 내부용):
|
||||
- 간단한 검증이나 테스트에만 사용
|
||||
|
||||
## 출력 형식
|
||||
생성한 파일 목록과 간단한 설명을 제공하세요.
|
||||
|
||||
@@ -50,10 +50,16 @@ FRONTEND_PROMPT = """당신은 Multi-Agent System의 **Frontend Code Agent**입
|
||||
- ARIA 속성
|
||||
- 키보드 네비게이션
|
||||
|
||||
## execute_bash 활용 예시:
|
||||
- 컴포넌트 생성: execute_bash("cat > /app/repos/project/src/components/UserCard.tsx << 'EOF'\\n코드\\nEOF")
|
||||
- 스타일 추가: execute_bash("cat > /app/repos/project/src/styles/UserCard.module.css << 'EOF'\\n스타일\\nEOF")
|
||||
- 빌드 테스트: execute_bash("cd /app/repos/project && npm run build")
|
||||
## 도구 사용 가이드:
|
||||
|
||||
### execute_ssh (호스트 작업용) ⭐ 주로 사용:
|
||||
- 컴포넌트 생성: execute_ssh("cat > /home/ubuntu/Projects/myproject/src/components/UserCard.tsx << 'EOF'\\n코드\\nEOF")
|
||||
- 스타일 추가: execute_ssh("cat > /home/ubuntu/Projects/myproject/src/styles/UserCard.module.css << 'EOF'\\n스타일\\nEOF")
|
||||
- 빌드 테스트: execute_ssh("cd /home/ubuntu/Projects/myproject && npm run build")
|
||||
- Git 커밋: execute_ssh("cd /home/ubuntu/Projects/myproject && git add . && git commit -m 'Add UserCard component'")
|
||||
|
||||
### execute_bash (컨테이너 내부용):
|
||||
- 간단한 검증에만 사용
|
||||
|
||||
## 출력 형식
|
||||
생성한 컴포넌트/파일 목록과 사용 방법을 설명하세요.
|
||||
|
||||
@@ -20,6 +20,11 @@ groq_infrastructure = ChatOpenAI(
|
||||
|
||||
INFRASTRUCTURE_PROMPT = """당신은 Multi-Agent System의 **Infrastructure Code Agent**입니다.
|
||||
|
||||
## ⚠️ 실행 환경
|
||||
- 컨테이너 내부: /app/
|
||||
- 호스트 시스템 접근: execute_ssh 사용
|
||||
- 파일 생성 위치: /home/ubuntu/Projects/ (호스트)
|
||||
|
||||
## 역할
|
||||
- Kubernetes Deployment, Service, Ingress YAML 작성
|
||||
- Docker 컨테이너 설정
|
||||
@@ -50,10 +55,15 @@ INFRASTRUCTURE_PROMPT = """당신은 Multi-Agent System의 **Infrastructure Code
|
||||
- Prometheus ServiceMonitor
|
||||
- Logging 설정
|
||||
|
||||
## execute_bash 활용 예시:
|
||||
- Deployment YAML: execute_bash("cat > /app/repos/cluster-infrastructure/apps/myapp/deployment.yaml << 'EOF'\\nYAML내용\\nEOF")
|
||||
- kubectl apply: execute_bash("kubectl apply -f /app/repos/cluster-infrastructure/apps/myapp/")
|
||||
- ArgoCD sync: execute_bash("kubectl apply -f /app/repos/cluster-infrastructure/argocd/myapp.yaml")
|
||||
## 도구 사용 가이드:
|
||||
|
||||
### execute_ssh (호스트 작업용) ⭐ 주로 사용:
|
||||
- YAML 파일 생성: execute_ssh("cat > /home/ubuntu/Projects/cluster-infrastructure/apps/myapp/deployment.yaml << 'EOF'\\nYAML내용\\nEOF")
|
||||
- kubectl apply: execute_ssh("kubectl apply -f /home/ubuntu/Projects/cluster-infrastructure/apps/myapp/", use_sudo=True)
|
||||
- Git 커밋: execute_ssh("cd /home/ubuntu/Projects/cluster-infrastructure && git add . && git commit -m 'Add myapp'")
|
||||
|
||||
### execute_bash (컨테이너 내부용):
|
||||
- 간단한 테스트나 검증에만 사용
|
||||
|
||||
## 출력 형식
|
||||
생성한 YAML 파일 목록과 배포 방법을 설명하세요.
|
||||
|
||||
@@ -19,18 +19,29 @@ claude_orchestrator = ChatAnthropic(
|
||||
|
||||
ORCHESTRATOR_PROMPT = """당신은 Multi-Agent System의 **총괄 조율자(Orchestrator)**입니다.
|
||||
|
||||
## ⚠️ 시스템 환경
|
||||
- **실행 위치**: Docker 컨테이너 (/app/)
|
||||
- **호스트 접근**: SSH 필요 (ubuntu@172.17.0.1)
|
||||
- **Projects 경로**: /home/ubuntu/Projects/ (호스트)
|
||||
- **Kubernetes**: kubectl은 호스트에서만 작동 (SSH + sudo 필요)
|
||||
|
||||
## 역할
|
||||
- 사용자 요청을 분석하고 적절한 에이전트에게 작업 위임
|
||||
- 각 에이전트의 결과를 검토하고 다음 단계 결정
|
||||
- 최종 출력물의 품질 보증
|
||||
- 에러 발생 시 복구 전략 수립
|
||||
- 필요시 직접 bash 명령어 실행 (간단한 조회/검증)
|
||||
- 필요시 직접 명령어 실행 (간단한 조회/검증)
|
||||
|
||||
## 사용 가능한 도구
|
||||
**execute_bash**: 필요한 경우 직접 bash 명령어를 실행할 수 있습니다.
|
||||
- 간단한 상태 확인: kubectl get pods, git status
|
||||
- 파일 조회: cat, ls
|
||||
- 빠른 검증 작업
|
||||
|
||||
### execute_ssh (호스트 접근용) ⭐ 주로 사용
|
||||
- Kubernetes: execute_ssh("kubectl get pods -n mas", use_sudo=True)
|
||||
- Projects: execute_ssh("ls -la /home/ubuntu/Projects")
|
||||
- Git: execute_ssh("cd /home/ubuntu/Projects/mas && git status")
|
||||
|
||||
### execute_bash (컨테이너 내부용)
|
||||
- 컨테이너 파일 조회: execute_bash("ls -la /app")
|
||||
- 간단한 검증: execute_bash("python --version")
|
||||
|
||||
## 워크플로우
|
||||
1. 사용자 요청 분석
|
||||
|
||||
@@ -21,45 +21,68 @@ groq_research = ChatOpenAI(
|
||||
|
||||
RESEARCH_PROMPT = """당신은 Multi-Agent System의 **Research Agent**입니다.
|
||||
|
||||
## ⚠️ 중요: 실행 환경 이해
|
||||
|
||||
당신은 **Docker 컨테이너 내부(/app/)**에서 실행되고 있습니다.
|
||||
|
||||
### 환경 구분:
|
||||
```
|
||||
[컨테이너 내부] /app/
|
||||
├── agents/
|
||||
├── tools/
|
||||
└── chainlit_app.py
|
||||
|
||||
[호스트 서버] ubuntu@172.17.0.1:/home/ubuntu/
|
||||
├── Projects/
|
||||
│ ├── mas/
|
||||
│ ├── cluster-infrastructure/
|
||||
│ └── ... (기타 레포지토리)
|
||||
└── Kubernetes 클러스터 (kubectl 사용 가능)
|
||||
```
|
||||
|
||||
## 역할
|
||||
- Bash 명령어를 활용하여 필요한 정보 수집
|
||||
- 호스트 시스템 정보 수집 (SSH 사용)
|
||||
- Kubernetes 클러스터 상태 조회
|
||||
- PostgreSQL 데이터베이스 스키마/데이터 탐색
|
||||
- PostgreSQL 데이터베이스 탐색
|
||||
- Git 레포지토리 분석
|
||||
- 파일 시스템 검색
|
||||
- Prometheus 메트릭 수집
|
||||
|
||||
## 사용 가능한 도구
|
||||
**execute_bash**: 모든 bash 명령어를 실행할 수 있습니다.
|
||||
|
||||
### 예시 명령어:
|
||||
### 1. execute_ssh (호스트 접근용) ⭐ 주로 사용
|
||||
호스트 시스템(oracle-master)에 접근할 때 사용합니다.
|
||||
|
||||
**Kubernetes 조회:**
|
||||
- kubectl get pods -n mas
|
||||
- kubectl get deployments -A
|
||||
- kubectl describe pod <pod-name> -n <namespace>
|
||||
- kubectl logs <pod-name> -n <namespace> --tail=50
|
||||
- execute_ssh("kubectl get pods -n mas", use_sudo=True)
|
||||
- execute_ssh("kubectl get deployments -A", use_sudo=True)
|
||||
- execute_ssh("kubectl describe pod mas-xxx -n mas", use_sudo=True)
|
||||
- execute_ssh("kubectl logs mas-xxx -n mas --tail=50", use_sudo=True)
|
||||
|
||||
**PostgreSQL 조회:**
|
||||
- psql -U bluemayne -d postgres -c "\\dt" # 테이블 목록
|
||||
- psql -U bluemayne -d postgres -c "SELECT * FROM users LIMIT 10"
|
||||
- psql -U bluemayne -d postgres -c "\\d users" # 테이블 스키마
|
||||
**Projects 폴더 탐색:**
|
||||
- execute_ssh("ls -la /home/ubuntu/Projects")
|
||||
- execute_ssh("find /home/ubuntu/Projects -name '*.git' -type d")
|
||||
- execute_ssh("cat /home/ubuntu/Projects/mas/README.md")
|
||||
|
||||
**Git 조회:**
|
||||
- git log -10 --oneline
|
||||
- git status
|
||||
- git diff
|
||||
- git branch -a
|
||||
**Git 작업:**
|
||||
- execute_ssh("cd /home/ubuntu/Projects/mas && git log -10 --oneline")
|
||||
- execute_ssh("cd /home/ubuntu/Projects/mas && git status")
|
||||
- execute_ssh("cd /home/ubuntu/Projects/cluster-infrastructure && git branch -a")
|
||||
|
||||
**파일 시스템:**
|
||||
- ls -la /app/repos/
|
||||
- cat /app/repos/cluster-infrastructure/README.md
|
||||
- find /app/repos -name "*.yaml" -type f
|
||||
- grep -r "keyword" /app/repos/
|
||||
**PostgreSQL 조회 (호스트에서):**
|
||||
- execute_ssh("psql -U bluemayne -h postgresql-primary.postgresql.svc.cluster.local -d postgres -c 'SELECT version()'")
|
||||
- execute_ssh("psql -U bluemayne -h postgresql-primary.postgresql.svc.cluster.local -d postgres -c '\\dt'")
|
||||
|
||||
**Prometheus 메트릭:**
|
||||
- curl -s "http://prometheus-kube-prometheus-prometheus.monitoring.svc.cluster.local:9090/api/v1/query?query=up"
|
||||
- curl -s "http://prometheus:9090/api/v1/query?query=node_cpu_seconds_total"
|
||||
### 2. execute_bash (컨테이너 내부용)
|
||||
컨테이너 내부 작업에만 사용합니다.
|
||||
|
||||
**컨테이너 내부 파일 조회:**
|
||||
- execute_bash("ls -la /app")
|
||||
- execute_bash("cat /app/chainlit_app.py")
|
||||
- execute_bash("find /app -name '*.py'")
|
||||
|
||||
**외부 API 호출:**
|
||||
- execute_bash("curl -s http://prometheus:9090/api/v1/query?query=up")
|
||||
|
||||
## 출력 형식 (JSON)
|
||||
수집한 정보를 JSON 형식으로 정리하세요:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""
|
||||
MAS Tools Package
|
||||
"""
|
||||
from .bash_tool import bash_tools, execute_bash
|
||||
from .bash_tool import bash_tools, execute_bash, execute_ssh
|
||||
|
||||
__all__ = ['bash_tools', 'execute_bash']
|
||||
__all__ = ['bash_tools', 'execute_bash', 'execute_ssh']
|
||||
|
||||
@@ -51,5 +51,68 @@ def execute_bash(command: str, timeout: int = 30, cwd: Optional[str] = None) ->
|
||||
return f"❌ Error executing command: {str(e)}"
|
||||
|
||||
|
||||
# Export the tool
|
||||
bash_tools = [execute_bash]
|
||||
@tool
|
||||
def execute_ssh(command: str, host: str = "ubuntu@172.17.0.1", timeout: int = 30, use_sudo: bool = False) -> str:
|
||||
"""
|
||||
Execute command on oracle-master host via SSH.
|
||||
|
||||
USE THIS for accessing the host system:
|
||||
- kubectl commands (Kubernetes cluster management)
|
||||
- Accessing /home/ubuntu/Projects/ (Git repositories)
|
||||
- PostgreSQL queries (via psql)
|
||||
- Git operations on host repositories
|
||||
- File system operations on host
|
||||
|
||||
Args:
|
||||
command: Command to run on the host server
|
||||
host: SSH host (default: ubuntu@172.17.0.1)
|
||||
timeout: Command timeout in seconds (default: 30)
|
||||
use_sudo: Whether to prepend 'sudo' to the command (default: False)
|
||||
|
||||
Returns:
|
||||
Command output or error message
|
||||
|
||||
Examples:
|
||||
- execute_ssh("kubectl get pods -n mas", use_sudo=True)
|
||||
- execute_ssh("ls -la /home/ubuntu/Projects")
|
||||
- execute_ssh("cat /home/ubuntu/Projects/mas/README.md")
|
||||
- execute_ssh("cd /home/ubuntu/Projects/mas && git log -5 --oneline")
|
||||
- execute_ssh("psql -U bluemayne -h postgresql-primary.postgresql.svc.cluster.local -d postgres -c 'SELECT version()'")
|
||||
"""
|
||||
try:
|
||||
# Escape quotes in command for SSH
|
||||
escaped_command = command.replace('"', '\\"')
|
||||
|
||||
# Add sudo if requested
|
||||
if use_sudo:
|
||||
escaped_command = f"sudo {escaped_command}"
|
||||
|
||||
# Build SSH command
|
||||
ssh_command = f'ssh -o StrictHostKeyChecking=no {host} "{escaped_command}"'
|
||||
|
||||
result = subprocess.run(
|
||||
ssh_command,
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=timeout
|
||||
)
|
||||
|
||||
# Combine stdout and stderr
|
||||
output = result.stdout
|
||||
if result.stderr:
|
||||
output += f"\n[STDERR]:\n{result.stderr}"
|
||||
|
||||
if result.returncode != 0:
|
||||
return f"❌ SSH command failed (exit code {result.returncode}):\n{output}"
|
||||
|
||||
return f"✅ SSH command executed successfully:\n{output}"
|
||||
|
||||
except subprocess.TimeoutExpired:
|
||||
return f"❌ SSH command timed out after {timeout} seconds"
|
||||
except Exception as e:
|
||||
return f"❌ Error executing SSH command: {str(e)}"
|
||||
|
||||
|
||||
# Export both tools
|
||||
bash_tools = [execute_bash, execute_ssh]
|
||||
|
||||
Reference in New Issue
Block a user