Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
waterflier committed Sep 29, 2023
1 parent ef36bc0 commit b6a06c4
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/aios_kernel/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import json
import shlex
import datetime
import copy

from .agent_message import AgentMsg, AgentMsgStatus, AgentMsgType,FunctionItem,LLMResult
from .chatsession import AIChatSession
Expand Down Expand Up @@ -48,7 +49,7 @@ def append(self,prompt):

if prompt.system_message is not None:
if self.system_message is None:
self.system_message = prompt.system_message
self.system_message = copy.deepcopy(prompt.system_message)
else:
self.system_message["content"] += prompt.system_message.get("content")

Expand Down Expand Up @@ -105,7 +106,7 @@ def load_from_config(self,config:dict) -> bool:

class AIAgent:
def __init__(self) -> None:
self.prompt:AgentPrompt = None
self.agent_prompt:AgentPrompt = None
self.llm_model_name:str = None
self.max_token_size:int = 3600
self.agent_id:str = None
Expand Down Expand Up @@ -136,7 +137,7 @@ def create_from_templete(cls,templete:AIAgentTemplete, fullname:str):
result_agent.agent_id = "agent#" + uuid.uuid4().hex
result_agent.fullname = fullname
result_agent.powerby = templete.author
result_agent.prompt = templete.prompt
result_agent.agent_prompt = templete.prompt
return result_agent

def load_from_config(self,config:dict) -> bool:
Expand All @@ -151,8 +152,8 @@ def load_from_config(self,config:dict) -> bool:
self.fullname = config["fullname"]

if config.get("prompt") is not None:
self.prompt = AgentPrompt()
self.prompt.load_from_config(config["prompt"])
self.agent_prompt = AgentPrompt()
self.agent_prompt.load_from_config(config["prompt"])

if config.get("guest_prompt") is not None:
self.guest_prompt_str = config["guest_prompt"]
Expand Down Expand Up @@ -350,7 +351,7 @@ async def _execute_func(self,inenr_func_call_node:dict,prompt:AgentPrompt,org_ms
return task_result.result_str,0

async def _get_agent_prompt(self) -> AgentPrompt:
return self.prompt
return self.agent_prompt

def _format_msg_by_env_value(self,prompt:AgentPrompt):
if self.owner_env is None:
Expand Down Expand Up @@ -403,7 +404,8 @@ async def _process_msg(self,msg:AgentMsg) -> AgentMsg:
inner_func_call_node = result_message.get("function_call")
if inner_func_call_node:
#TODO to save more token ,can i use msg_prompt?
final_result,error_code = await self._execute_func(inner_func_call_node,prompt,msg)
call_prompt : AgentPrompt = copy.deepcopy(prompt)
final_result,error_code = await self._execute_func(inner_func_call_node,call_prompt,msg)
if error_code != 0:
error_resp = msg.create_error_resp(final_result)
return error_resp
Expand Down

0 comments on commit b6a06c4

Please sign in to comment.