Web Serch Agent:ソースコード:main.py


import os
import streamlit as st

# custom tools
from tools.command_list import set_work_space
from tools.command_list import load_ai_agent_name_list
from tools.WebSerchAgent import WebSerchAgent
################################################
##########################################################
def init_page():
    st.set_page_config(
        page_title="web serch agent.",
        page_icon=""
    )
    st.header("web serch agent.")
    st.sidebar.title("Options")


def init_messages(ai_agent):
    clear_button = st.sidebar.button("Clear Conversation", key="clear")
    if clear_button or "messages" not in st.session_state:
        st.session_state.messages = [
            {"role": "assistant", "content": "入力してください。"}
        ]
        ai_agent.clear_memory()



def main():
    load_ai_agent_name_list()
    ai_agent=WebSerchAgent()
 
    init_page()
    init_messages(ai_agent)
    set_work_space(os.getcwd())
    print("current folder", os.getcwd())
    for msg in st.session_state['memory'].chat_memory.messages:
        st.chat_message(msg.type).write(msg.content)
    # セッション状態に値がある場合のみテキスト入力欄を表示

    if user_prompt := st.chat_input(placeholder="作業内容を入れてください"):
        st.chat_message("user").write(user_prompt)

        respons = ai_agent.get_respons(user_prompt)
        st.chat_message("Web Serch Agent").write(respons)
    print("end_of_main")
if __name__ == '__main__':
    main()