Quick Start

1

Install Dependencies

First, install the required packages:

pip install praisonaiagents streamlit
2

Create Script

Create a new file app.py:

import streamlit as st
from praisonaiagents import Agent, Tools
from praisonaiagents.tools import duckduckgo

st.title("AI Research Assistant")
st.write("Enter your research query below to get started!")

# Initialize the research agent
agent = Agent(instructions="You are a Research Agent", tools=[duckduckgo])

# Create the input field
query = st.text_input("Research Query", placeholder="Enter your research topic...")

# Add a search button
if st.button("Search"):
    if query:
        with st.spinner("Researching..."):
            result = agent.start(query)
            st.write(result)
    else:
        st.warning("Please enter a research query")
3

Run Application

Run your Streamlit app:

streamlit run app.py

Features

Easy Integration

Seamlessly integrate AI agents with Streamlit’s UI components.

Interactive UI

Create responsive interfaces with real-time updates.

Progress Indicators

Built-in loading states and progress indicators.

Rich Output

Display formatted text, markdown, and other rich content.

Understanding the Code

The example demonstrates a simple research assistant with these key components:

  1. UI Setup:

    • Title and description using st.title() and st.write()
    • Input field with st.text_input()
    • Search button with st.button()
  2. Agent Integration:

    • Initialize the AI agent with specific instructions
    • Connect the agent to the UI components
    • Handle user input and display results
  3. User Experience:

    • Loading spinner during processing
    • Input validation and error messages
    • Clean result display

Customization

You can enhance the UI with additional Streamlit components:

# Add sidebar options
st.sidebar.title("Settings")
model = st.sidebar.selectbox("Select Model", ["GPT-3", "GPT-4"])

# Add multiple input types
text_input = st.text_area("Long Query", height=100)
file_input = st.file_uploader("Upload File")

# Display results with formatting
st.markdown("### Results")
st.json(structured_data)
st.dataframe(tabular_data)

Next Steps

Was this page helpful?