CHORE(app): limit token size

- Add token size constraints
- Optimize API usage
This commit is contained in:
2025-12-24 17:19:51 +09:00
parent a4e758e3b2
commit a382985c79
2 changed files with 23 additions and 55 deletions

View File

@@ -14,5 +14,5 @@ commonLabels:
# 이미지 태그 설정 (ArgoCD Image Updater가 자동으로 업데이트)
images:
- name: gitea0213.kro.kr/bluemayne/mas
newTag: main-sha-d714e56d99b40d4c14e0c120d062237bb1e659c6
newTag: main-sha-422bf3e092c3f7c1228fad9fba7f8d615b8bcdba

View File

@@ -20,64 +20,27 @@ groq_research = ChatOpenAI(
)
RESEARCH_PROMPT = """You are the Research Agent in a Multi-Agent System.
RESEARCH_PROMPT = """Research Agent: Collect system info via commands.
## Role
Collect and analyze information from the host system by requesting command executions.
Request commands in JSON:
{"commands": [{"tool": "execute_host", "command": "kubectl get nodes", "use_sudo": true}]}
## Environment
- Container: /app/
- Host: Kubernetes cluster with kubectl access
- Projects folder: /home/ubuntu/Projects/
Rules:
- Request 1-2 commands at a time
- Use execute_host for kubectl/git, execute_bash for container
- Output ONLY JSON when requesting commands
## Your Task
1. Analyze what information you need to gather
2. Request commands to be executed
3. Analyze the results
4. Provide comprehensive findings
## Command Request Format
When you need to execute commands, output them in this EXACT JSON format:
```json
Final report format:
{
"commands": [
{"tool": "execute_host", "command": "kubectl get nodes", "use_sudo": true},
{"tool": "execute_bash", "command": "ls -la /app"}
]
}
```
**IMPORTANT**:
- Request 1-3 commands at a time (not too many!)
- Use "execute_host" for host system commands (kubectl, git, etc.)
- Use "execute_bash" for container commands
- Set "use_sudo": true for kubectl commands
- Output ONLY the JSON, nothing else when requesting commands
## Final Report Format
When you have enough information, provide a final report in JSON:
```json
{
"summary": "Brief summary of findings",
"findings": [
{"category": "Infrastructure", "data": "K8s cluster with 3 nodes..."},
{"category": "CI/CD", "data": "Current tools: ArgoCD..."}
],
"recommendations": ["Consider X because Y", "..."],
"summary": "Brief findings",
"findings": [{"category": "...", "data": "..."}],
"recommendations": ["..."],
"tekton_recommendation": {
"should_use": true/false,
"reasons": ["reason 1", "reason 2"],
"alternatives": ["alternative 1", "alternative 2"]
"reasons": ["..."],
"alternatives": ["..."]
}
}
```
## Instructions
- Start by requesting basic system info commands
- Analyze results carefully
- Request more specific commands based on findings
- Provide actionable recommendations
- Be concise and focused
"""
@@ -111,7 +74,7 @@ def research_node(state: AgentState) -> AgentState:
]
tool_outputs = []
max_iterations = 5
max_iterations = 2
iteration = 0
while iteration < max_iterations:
@@ -144,7 +107,7 @@ def research_node(state: AgentState) -> AgentState:
commands_executed = True
results = []
for cmd_spec in commands_data["commands"][:5]: # 최대 5개까지만
for cmd_spec in commands_data["commands"][:2]: # 최대 2개까지만 (토큰 절약)
tool_name = cmd_spec.get("tool", "execute_bash")
command = cmd_spec.get("command", "")
use_sudo = cmd_spec.get("use_sudo", False)
@@ -171,10 +134,15 @@ def research_node(state: AgentState) -> AgentState:
results.append(f"Command: {command}\nResult: {error_msg}")
print(error_msg)
# 결과를 대화에 추가
# 결과를 대화에 추가 (최신 것만 유지)
results_text = "\n\n".join(results)
tool_outputs.append(results_text)
conversation.append(HumanMessage(content=f"명령어 실행 결과:\n\n{results_text}\n\n계속 정보가 필요하면 추가 명령어를 요청하고, 충분한 정보를 수집했으면 최종 리포트를 JSON으로 제공해주세요."))
# 전체 히스토리 대신 시스템 프롬프트 + 초기 요청 + 최신 결과만 유지
conversation = [
SystemMessage(content=RESEARCH_PROMPT),
HumanMessage(content=research_request),
HumanMessage(content=f"명령어 실행 결과:\n\n{results_text}\n\n계속 정보가 필요하면 추가 명령어를 요청하고, 충분한 정보를 수집했으면 최종 리포트를 JSON으로 제공해주세요.")
]
continue # 다음 반복으로