File size: 1,855 Bytes
73e774f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import streamlit as st

from agent_backend import ask_agent

# -----------------------------------
# Page config
# -----------------------------------
st.set_page_config(
    page_title="Day 7 AI Agent",
    page_icon="🤖",
    layout="wide"
)

# -----------------------------------
# Title
# -----------------------------------
st.title("🤖 Day 7 - AI Agent Assistant")

st.markdown("""
This AI Agent can:
- 🧮 Perform calculations
- 🌐 Search the web
- 🧠 Reason using tools
""")

# -----------------------------------
# Sidebar
# -----------------------------------
with st.sidebar:

    st.header("⚙️ Controls")

    if st.button("🗑️ Clear Chat"):

        st.session_state.messages = []

        st.rerun()

# -----------------------------------
# Session State
# -----------------------------------
if "messages" not in st.session_state:

    st.session_state.messages = []

# -----------------------------------
# Display chat history
# -----------------------------------
for msg in st.session_state.messages:

    with st.chat_message(msg["role"]):

        st.write(msg["content"])

# -----------------------------------
# User input
# -----------------------------------
user_input = st.chat_input(
    "Ask anything..."
)

if user_input:

    # save user message
    st.session_state.messages.append(
        {
            "role": "user",
            "content": user_input
        }
    )

    # display user message
    with st.chat_message("user"):

        st.write(user_input)

    # assistant response
    with st.chat_message("assistant"):

        with st.spinner("Thinking..."):

            response = ask_agent(user_input)

            st.write(response)

    # save assistant response
    st.session_state.messages.append(
        {
            "role": "assistant",
            "content": response
        }
    )