@@ -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 } ' }}
0 commit comments