from Agents.AIAgent import AIAgent
from tools.program_called_command_list import load_ai_agent_name_list
import flow.flow_controller
import streamlit as st
class PythonProgramerAgent():
def __init__(self, max_check=3):
name = "PythonProgramer"
self.agetn_dict = load_ai_agent_name_list("PythonProgramerAgent")
self.agent = AIAgent(name,
self.__get_agent_prompt(name),
[],
False)
self.serch_result = []
self.max_check = max_check
# AIAgentと関数的互換性確保のために必要
def get_name(self):
return PythonProgramerAgent.__name__
def clear_memory(self):
self.agent.clear_memory()
def update_temperature(self, temperature):
self.agent.update_temperature(temperature)
def update_tools(self, tools):
self.agent.update_tools(tools)
def get_respons(self, command):
error_respons, respons_text = self.program(command)
return respons_text
################################################
def __get_agent_prompt(self, name):
return self.agetn_dict[name][1]
def program(self, command):
self.agent.update_system_prompt(
self.__get_agent_prompt("PythonProgramer"))
# コールバック関数の設定 (エージェントの動作の可視化用)
respons = self.agent.get_respons(command)
return self.respons_programe_check(respons)
def respons_programe_check(self, check_prompt):
# 次の作業者を決定。
count = 0
respons_text = check_prompt
# pythonで エラーが出るようなら自動で作りなおしを依頼。
print("respons_programe_check:", respons_text)
while True:
error_respons =\
flow.flow_controller.python_error_check(respons_text)
if False is flow.flow_controller.get_code_error():
error_respons = ""
return error_respons, respons_text
if self.max_check <= count:
error_respons = "3回以上やり直してもエラーを修正しきれませんでした。"
return error_respons, respons_text
print(error_respons)
respons_text =\
self.think_agent(error_respons+"\r\n原因と対策を確認したうえで、直してください。")
count += 1
def think_agent(self, prompt):
# AIエージェントの思考
with st.chat_message("PythonProgramer"):
# エージェントを実行
response = self.agent.get_respons(prompt)
st.write(response)
return response