in components/frontend_streamlit/src/pages/4_Agent.py [0:0]
def chat_content():
init_messages()
# Create a placeholder for all chat history.
chat_placeholder = st.empty()
with chat_placeholder.container():
index = 1
for item in st.session_state.messages:
logging.info(item)
if "HumanInput" in item:
with st.chat_message("user"):
st.write(item["HumanInput"], is_user=True, key=f"human_{index}")
if "AIOutput" in item:
with st.chat_message("ai"):
ai_output = item["AIOutput"]
ai_output = format_ai_output(ai_output)
st.write(
ai_output,
key=f"ai_{index}",
unsafe_allow_html=False,
is_table=False, # TODO: Detect whether an output content type.
)
if "plan" in item:
with st.chat_message("ai"):
index = 1
plan = get_plan(item["plan"]["id"])
logging.info(plan)
for step in plan["plan_steps"]:
st.text_area(f"step-{index}", step["description"],
height=30, disabled=True,
label_visibility="hidden")
index = index + 1
plan_id = plan["id"]
if st.button("Execute this plan", key=f"plan-{plan_id}"):
with st.spinner("Executing the plan..."):
output = run_agent_execute_plan(
plan_id=plan_id,
chat_id=st.session_state.chat_id,
auth_token=st.session_state.auth_token)
st.session_state.messages.append({
"AIOutput": f"Plan executed successfully. (plan_id={plan_id})",
})
agent_process_output = output.get("agent_process_output", "")
agent_process_output = ansi_escape.sub("", agent_process_output)
st.session_state.messages.append({
"AIOutput": agent_process_output,
})
index = index + 1
st.text_input("User Input:", on_change=on_input_change, key="user_input")