kuchi
kuchi

Reputation: 1

What would be a good design to inculcate the use of multiple agents using streamlit and langchain

The outputs of each of the agents must be reviewed before it is used as input for the next agent. All of the outputs are in the form of text.

# This is to upload the PDF File
uploaded_file = st.file_uploader("Upload your file")
if uploaded_file is not None:
    save_folder = PATH
    save_path = Path(save_folder, uploaded_file.name)
    with open(save_path, mode='wb') as w:
        w.write(uploaded_file.getvalue())

    if save_path.exists():
        st.success(f'File {uploaded_file.name} is successfully saved!')

        with st.expander("Agent 1"):
            st.spinner("Running Agent 1...")
            INPUT_FILE = "./Resources/extracted_text.txt"
            content = Agent1(pdf_path=f"./Resources/{uploaded_file.name}", INPUT_FILE=INPUT_FILE)
            agent1_output = st.text_area(label="Output of Agent1", value=content, height=200)
            st.button("Proceed to Agent 2", on_click=Agent1Complete(agent1_output), key="Agent1 Button")
        
        if "Agent1" in st.session_state and st.button("Run Agent 2", key="Agent2 Buttonx"):
            with st.expander("Agent 2"):
                st.spinner("Running Agent 2...")
                INPUT_FILE = "./Resources/Agent1.txt"
                content = Agent2(input_file=INPUT_FILE)
                agent2_output = st.text_area(label="Output of Agent2", value=content, height=200)
                st.button("Proceed to Agent 2", on_click=Agent2Complete(agent2_output), key="Agent2 Button")

        if "Agent2" in st.session_state and st.button("Run Agent 3", key="Agent3 Buttonx"):
            with st.expander("Agent 3"):
                st.spinner("Running Agent 3...")
                content = Agent3(input_file=INPUT_FILE)
                agent3_output = st.text_area(label="Output of Agent3", value=content, height=200)
                st.button("Proceed to Agent 2", on_click=Agent3Complete(agent3_output), key="Agent3 Button")

        if "Agent3" in st.session_state and st.button("Run Agent 4", key="Agent4 Buttonx"):
            with st.expander("Agent4"):
                st.spinner("Running Agent 4...")
                Agent4(False, input_file=INPUT_FILE, output_file=OUTPUT_FILE)

I have tried the following solution along with also trying out a multipage solution where each page would be a separate agent, but I was not able to save the changes to the txt file before I moved ahead to the next agent. I thought by using session state I could keep track of which agent had completed its process.

Upvotes: 0

Views: 15

Answers (0)

Related Questions