Skip to content

Commit 0d1f76a

Browse files
authored
Merge pull request m-cmp#154 from kyuengmanKim/develop/log-analysis
Develop/log analysis
2 parents 1392a58 + 7c70ac6 commit 0d1f76a

3 files changed

Lines changed: 33 additions & 12 deletions

File tree

python/insight/app/core/mcp/mcp_context.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,24 @@ async def get_agent(self, provider: str, model_name: str, provider_credential: s
4747
self.llm_client.setup(model=model_name)
4848
self.agent = self.llm_client.bind_tools(self.tools, self.memory)
4949

50+
async def _build_prompt(self, session_id: str, messages: str):
51+
history = await self.get_chat_history(session_id)
52+
msg_count = 0
53+
if history:
54+
channel_values = history.get('channel_values', {})
55+
msg_count = len(channel_values.get('messages', []))
5056

51-
@staticmethod
52-
def _build_prompt(messages):
5357
current_time = datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%SZ")
5458

55-
system_prompt = f"""
56-
You are an assistant specialized in log retrieval and log exploration.
57-
To respond to user questions, select the appropriate tools and provide thoughtful and sincere answers.
58-
If the question is in English, respond in English; if it's in Korean, respond in Korean.
59-
The current time is {current_time}.
60-
"""
59+
# TODO 기능, 상황별 Prompt 관리 기능 추가
60+
system_prompt_config = self.config.get_system_prompt_config()
61+
62+
if msg_count == 0:
63+
system_prompt_first = system_prompt_config.get("system_prompt_first")
64+
system_prompt = system_prompt_first.format(current_time=current_time)
65+
else:
66+
system_prompt_default = system_prompt_config.get("system_prompt_default")
67+
system_prompt = system_prompt_default.format(current_time=current_time)
6168

6269
return [
6370
{"role": "system", "content": system_prompt},
@@ -66,12 +73,10 @@ def _build_prompt(messages):
6673

6774
async def aquery(self, session_id, messages):
6875
config = self.create_config(session_id)
69-
prompt = self._build_prompt(messages)
76+
prompt = await self._build_prompt(session_id, messages)
7077
response = await self.agent.ainvoke({'messages': prompt}, config=config)
71-
7278
return response
7379

74-
7580
@staticmethod
7681
def create_config(session_id):
7782
return {'configurable': {'thread_id': f'{session_id}'}}

python/insight/config/ConfigManager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,11 @@ def get_mcp_config(self):
8686
mcp = self.config.get('log_analysis', {}).get('mcp', {})
8787
return {
8888
"mcp_grafana_url": mcp.get('mcp_grafana_url', '')
89+
}
90+
91+
def get_system_prompt_config(self):
92+
log_analysis = self.config.get('log_analysis', {})
93+
return {
94+
"system_prompt_first": log_analysis.get('system_prompt_first', ''),
95+
"system_prompt_default": log_analysis.get('system_prompt_default', '')
8996
}

python/insight/config/config.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,13 @@ log_analysis:
116116
- gpt-4o-mini
117117
- gpt-3.5-turbo
118118
mcp:
119-
mcp_grafana_url: http://mc-observability-mcp-grafana:8000/sse
119+
mcp_grafana_url: http://mc-observability-mcp-grafana:8000/sse
120+
system_prompt_first: |
121+
You are an assistant specialized in log retrieval and log exploration.
122+
To respond to user questions, select the appropriate tools and provide thoughtful and sincere answers.
123+
If the question is in English, respond in English; if it's in Korean, respond in Korean.
124+
The current time is {current_time}.
125+
system_prompt_default: |
126+
You are an assistant specialized in log retrieval and log exploration.
127+
respond in Korean.
128+
Continue the conversation. The current time is {current_time}.

0 commit comments

Comments
 (0)