File size: 20,531 Bytes
3e31e00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
"""

Streamlit UI for Multi-Agent Research Assistant (Tavily Version)

=================================================================



Features:

- Clean, professional interface

- Real-time agent execution visualization

- Interactive tool selection

- Source citations with links

- Export reports

- Session history



Run: streamlit run app.py

"""

import streamlit as st
from datetime import datetime
import json
import time

# Import your multi-agent system
from multi_agent_assistant import (
    MultiAgentSystem,
    Config,
    TAVILY_AVAILABLE
)

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# PAGE CONFIG
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

st.set_page_config(
    page_title="Multi-Agent Research Assistant",
    page_icon="๐Ÿค–",
    layout="wide",
    initial_sidebar_state="expanded"
)

# Custom CSS
st.markdown("""

<style>

    .main-header {

        font-size: 2.5rem;

        font-weight: bold;

        color: #1f77b4;

        text-align: center;

        margin-bottom: 1rem;

    }

    .sub-header {

        font-size: 1.2rem;

        color: #666;

        text-align: center;

        margin-bottom: 2rem;

    }

    .agent-box {

        padding: 1rem;

        border-radius: 0.5rem;

        border-left: 4px solid;

        margin: 1rem 0;

    }

    .researcher { border-color: #1f77b4; background-color: #e3f2fd; }

    .analyst { border-color: #ff7f0e; background-color: #fff3e0; }

    .writer { border-color: #2ca02c; background-color: #e8f5e9; }

    .critic { border-color: #d62728; background-color: #ffebee; }

    .source-card {

        padding: 1rem;

        border-radius: 0.5rem;

        background-color: #f5f5f5;

        margin: 0.5rem 0;

    }

    .metric-card {

        padding: 1rem;

        border-radius: 0.5rem;

        background-color: #ffffff;

        border: 1px solid #e0e0e0;

        text-align: center;

    }

</style>

""", unsafe_allow_html=True)

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# SESSION STATE INITIALIZATION
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

if 'system' not in st.session_state:
    st.session_state.system = None
if 'history' not in st.session_state:
    st.session_state.history = []
if 'current_research' not in st.session_state:
    st.session_state.current_research = None
if 'agent_logs' not in st.session_state:
    st.session_state.agent_logs = []


# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# HELPER FUNCTIONS
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

def initialize_system(hf_token: str, tavily_key: str):
    """Initialize the multi-agent system"""
    try:
        with st.spinner("๐Ÿš€ Initializing Multi-Agent System..."):
            system = MultiAgentSystem(
                hf_token=hf_token,
                tavily_key=tavily_key,
                max_iterations=2
            )
            st.session_state.system = system
            return True
    except Exception as e:
        st.error(f"Initialization failed: {str(e)}")
        return False


def display_agent_activity(step: str, agent_name: str, content: str):
    """Display agent activity in real-time"""
    
    agent_colors = {
        "Researcher": "researcher",
        "Analyst": "analyst",
        "Writer": "writer",
        "Critic": "critic"
    }
    
    color_class = agent_colors.get(agent_name, "researcher")
    
    st.markdown(f"""

    <div class="agent-box {color_class}">

        <strong>๐Ÿค– {agent_name} Agent</strong><br/>

        <small>{content}</small>

    </div>

    """, unsafe_allow_html=True)


def format_report(report_output, research_output, critique_output):
    """Format the final report"""
    
    st.markdown("---")
    st.markdown("## ๐Ÿ“„ Research Report")
    
    # Title
    st.markdown(f"### {report_output.title}")
    
    # Content
    st.markdown(report_output.content)
    
    # Metadata section
    st.markdown("---")
    st.markdown("### ๐Ÿ“Š Research Metadata")
    
    col1, col2, col3 = st.columns(3)
    
    with col1:
        st.markdown(f"""

        <div class="metric-card">

            <h4>Sources</h4>

            <p>{', '.join(research_output.sources_used)}</p>

        </div>

        """, unsafe_allow_html=True)
    
    with col2:
        st.markdown(f"""

        <div class="metric-card">

            <h4>Confidence</h4>

            <p>{research_output.confidence*100:.0f}%</p>

        </div>

        """, unsafe_allow_html=True)
    
    with col3:
        st.markdown(f"""

        <div class="metric-card">

            <h4>Quality Score</h4>

            <p>{critique_output.score:.1f}/10</p>

        </div>

        """, unsafe_allow_html=True)
    
    # Web sources
    if research_output.web_sources:
        st.markdown("### ๐ŸŒ Web References")
        for i, source in enumerate(research_output.web_sources, 1):
            st.markdown(f"""

            <div class="source-card">

                <strong>{i}. {source['title']}</strong><br/>

                <a href="{source['url']}" target="_blank">{source['url']}</a>

            </div>

            """, unsafe_allow_html=True)


def export_report(report_output, research_output):
    """Generate downloadable report"""
    
    content = f"""# {report_output.title}



{report_output.content}



---



## Metadata



- **Sources:** {', '.join(research_output.sources_used)}

- **Confidence:** {research_output.confidence*100:.0f}%

- **Generated:** {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}



"""
    
    if research_output.web_sources:
        content += "\n## Web References\n\n"
        for i, source in enumerate(research_output.web_sources, 1):
            content += f"{i}. [{source['title']}]({source['url']})\n"
    
    return content


# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# SIDEBAR
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

with st.sidebar:
    st.markdown("# โš™๏ธ Configuration")
    
    # API Keys
    st.markdown("## ๐Ÿ”‘ API Keys")
    
    hf_token = st.text_input(
        "Hugging Face Token",
        type="password",
        value=Config.HF_TOKEN if Config.HF_TOKEN else "",
        help="Get from: https://huggingface.co/settings/tokens"
    )
    
    tavily_key = st.text_input(
        "Tavily API Key",
        type="password",
        value=Config.TAVILY_API_KEY if Config.TAVILY_API_KEY else "",
        help="Get FREE key from: https://tavily.com/"
    )
    
    if st.button("๐Ÿš€ Initialize System", type="primary", use_container_width=True):
        if not hf_token or not tavily_key:
            st.error("Both tokens required!")
        else:
            if initialize_system(hf_token, tavily_key):
                st.success("โœ… System Ready!")
    
    st.markdown("---")
    
    # System Status
    st.markdown("## ๐Ÿ“Š System Status")
    
    if st.session_state.system:
        st.success("๐ŸŸข Online")
        st.info(f"๐Ÿ“š Queries: {len(st.session_state.history)}")
    else:
        st.error("๐Ÿ”ด Offline")
    
    if not TAVILY_AVAILABLE:
        st.warning("โš ๏ธ Tavily not installed")
    
    st.markdown("---")
    
    # Example queries
    st.markdown("## ๐Ÿ’ก Example Queries")
    
    examples = {
        "Math": "what is 125*8+47",
        "Knowledge": "explain deep learning",
        "Current Events": "latest AI news December 2025",
        "Web Search": "current Bitcoin price"
    }
    
    for category, query in examples.items():
        if st.button(f"{category}", use_container_width=True):
            st.session_state.example_query = query
    
    st.markdown("---")
    
    # Clear history
    if st.button("๐Ÿ—‘๏ธ Clear History", use_container_width=True):
        st.session_state.history = []
        st.session_state.current_research = None
        st.rerun()
    
    st.markdown("---")
    
    # About
    with st.expander("โ„น๏ธ About"):
        st.markdown("""

        **Multi-Agent Research Assistant**

        

        An Agentic AI system with:

        - ๐Ÿ” Tavily web search

        - ๐Ÿงฎ Calculator tool

        - ๐Ÿ“š Knowledge base

        - ๐Ÿค– 4 specialized agents

        - โ™ป๏ธ Iterative refinement

        

        **Tools:**

        - LangGraph (orchestration)

        - Tavily (AI-optimized search)

        - Llama 3.1 8B (reasoning)

        

        **Version:** 2.0

        """)


# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# MAIN CONTENT
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

# Header
st.markdown('<div class="main-header">๐Ÿค– Multi-Agent Research Assistant</div>', unsafe_allow_html=True)
st.markdown('<div class="sub-header">Powered by Tavily AI-Optimized Search & Agentic AI With LangGraph</div>', unsafe_allow_html=True)

# Check system status
if not st.session_state.system:
    st.warning("โš ๏ธ Please initialize the system using the sidebar")
    
    col1, col2, col3 = st.columns(3)
    
    with col1:
        st.markdown("""

        ### ๐Ÿ”‘ Step 1: Get API Keys

        

        **Hugging Face (FREE)**

        - [Get token](https://huggingface.co/settings/tokens)

        - No credit card needed

        

        **Tavily (FREE)**

        - [Get key](https://tavily.com/)

        - 1,000 searches/month free

        """)
    
    with col2:
        st.markdown("""

        ### โš™๏ธ Step 2: Initialize

        

        1. Enter tokens in sidebar

        2. Click "Initialize System"

        3. Wait ~10 seconds

        4. Start researching!

        """)
    
    with col3:
        st.markdown("""

        ### ๐Ÿ’ก Step 3: Ask Questions

        

        Try:

        - Math calculations

        - General knowledge

        - Current events

        - Web research

        """)
    
    st.stop()

# Main Interface
st.markdown("## ๐Ÿ” Research Query")

# Query input
query_col, button_col = st.columns([4, 1])

with query_col:
    # Check if example query exists
    default_query = st.session_state.get('example_query', '')
    if default_query:
        query = st.text_input(
            "What would you like to research?",
            value=default_query,
            placeholder="e.g., latest AI developments, what is 25*4, explain machine learning"
        )
        # Clear example query after use
        del st.session_state.example_query
    else:
        query = st.text_input(
            "What would you like to research?",
            placeholder="e.g., latest AI developments, what is 25*4, explain machine learning"
        )

with button_col:
    st.markdown("<br/>", unsafe_allow_html=True)
    research_button = st.button("๐Ÿš€ Research", type="primary", use_container_width=True)

# Execute research
if research_button and query:
    
    st.markdown("---")
    st.markdown("## ๐Ÿค– Agent Activity")
    
    # Progress container
    progress_placeholder = st.empty()
    agent_placeholder = st.empty()
    
    try:
        # Show progress
        with progress_placeholder:
            progress_bar = st.progress(0)
            status_text = st.empty()
        
        # Execute research with progress updates
        with st.spinner("๐Ÿ” Research in progress..."):
            
            # Agent 1: Researcher
            status_text.text("๐Ÿ” Researcher Agent: Gathering information...")
            progress_bar.progress(25)
            
            final_state = st.session_state.system.research(query)
            
            # Agent 2: Analyst
            status_text.text("๐Ÿ“Š Analyst Agent: Analyzing findings...")
            progress_bar.progress(50)
            time.sleep(0.5)
            
            # Agent 3: Writer
            status_text.text("โœ๏ธ Writer Agent: Creating report...")
            progress_bar.progress(75)
            time.sleep(0.5)
            
            # Agent 4: Critic
            status_text.text("๐ŸŽฏ Critic Agent: Quality check...")
            progress_bar.progress(100)
            time.sleep(0.5)
        
        # Clear progress
        progress_placeholder.empty()
        
        if final_state and final_state.get("report_output"):
            
            # Display agent summary
            with agent_placeholder:
                st.success("โœ… Research Complete!")
                
                col1, col2, col3, col4 = st.columns(4)
                
                with col1:
                    st.markdown("**๐Ÿ” Researcher**")
                    st.caption("Information gathered")
                
                with col2:
                    st.markdown("**๐Ÿ“Š Analyst**")
                    st.caption("Insights extracted")
                
                with col3:
                    st.markdown("**โœ๏ธ Writer**")
                    st.caption("Report created")
                
                with col4:
                    st.markdown("**๐ŸŽฏ Critic**")
                    st.caption(f"Score: {final_state['critique_output'].score:.1f}/10")
            
            # Store in session
            st.session_state.current_research = final_state
            
            # Add to history
            st.session_state.history.append({
                "timestamp": datetime.now(),
                "query": query,
                "result": final_state
            })
            
            # Display report
            format_report(
                final_state["report_output"],
                final_state["research_output"],
                final_state["critique_output"]
            )
            
            # Export options
            st.markdown("---")
            st.markdown("### ๐Ÿ“ฅ Export")
            
            col1, col2, col3 = st.columns([1, 1, 2])
            
            with col1:
                report_text = export_report(
                    final_state["report_output"],
                    final_state["research_output"]
                )
                
                st.download_button(
                    label="๐Ÿ“„ Download Markdown",
                    data=report_text,
                    file_name=f"research_report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md",
                    mime="text/markdown",
                    use_container_width=True
                )
            
            with col2:
                report_json = json.dumps({
                    "query": query,
                    "report": final_state["report_output"].dict(),
                    "research": final_state["research_output"].dict(),
                    "critique": final_state["critique_output"].dict(),
                    "timestamp": datetime.now().isoformat()
                }, indent=2)
                
                st.download_button(
                    label="๐Ÿ“Š Download JSON",
                    data=report_json,
                    file_name=f"research_data_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json",
                    mime="application/json",
                    use_container_width=True
                )
        
        else:
            st.error("โŒ Research failed. Please try again.")
    
    except Exception as e:
        st.error(f"โŒ Error during research: {str(e)}")
        st.exception(e)

# Display current research if exists
elif st.session_state.current_research:
    st.markdown("---")
    st.info("๐Ÿ’ก Previous research result shown below. Ask a new question above!")
    
    final_state = st.session_state.current_research
    
    format_report(
        final_state["report_output"],
        final_state["research_output"],
        final_state["critique_output"]
    )

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# HISTORY TAB
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

if st.session_state.history:
    st.markdown("---")
    st.markdown("## ๐Ÿ“š Research History")
    
    for i, item in enumerate(reversed(st.session_state.history)):
        with st.expander(
            f"๐Ÿ” {item['query'][:60]}... - {item['timestamp'].strftime('%H:%M:%S')}",
            expanded=(i == 0)
        ):
            if item['result'] and item['result'].get('report_output'):
                
                col1, col2 = st.columns([3, 1])
                
                with col1:
                    st.markdown(f"**Question:** {item['query']}")
                    st.markdown(f"**Answer:** {item['result']['research_output'].answer[:200]}...")
                
                with col2:
                    st.metric("Quality", f"{item['result']['critique_output'].score:.1f}/10")
                    st.metric("Confidence", f"{item['result']['research_output'].confidence*100:.0f}%")
                
                if st.button(f"๐Ÿ“„ View Full Report #{len(st.session_state.history)-i}", key=f"view_{i}"):
                    st.session_state.current_research = item['result']
                    st.rerun()


# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# FOOTER
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

st.markdown("---")

footer_col1, footer_col2, footer_col3 = st.columns(3)

with footer_col1:
    st.markdown("""

    **๐Ÿค– Agentic AI System**

    - Autonomous tool selection

    - Multi-agent collaboration

    - Iterative refinement

    """)

with footer_col2:
    st.markdown("""

    **๐Ÿ› ๏ธ Technologies**

    - LangGraph

    - Tavily Search

    - Llama 3.1 8B

    """)

with footer_col3:
    st.markdown("""

    **๐Ÿ“Š Capabilities**

    - Web search

    - Calculations

    - Knowledge base

    - Real-time info

    """)

st.markdown("""

<div style='text-align: center; color: gray; padding: 2rem;'>

    <small>Multi-Agent Research Assistant  | Powered by Tavily & LangGraph</small>

</div>

""", unsafe_allow_html=True)