Streamlit Agent

Learn how to create web interfaces for your AI agents using Streamlit

Diagram

User Input

Streamlit UI

AI Agent

Results Display

Quick Start

  1. Install Dependencies

    First, install the required packages:

    bash
    pip install praisonaiagents streamlit
  2. Create Script

    Create a new file app.py:

    python
    import streamlit as st
    from praisonaiagents import Agent, Tools
    from praisonaiagents 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:

    bash
    streamlit run app.py

Features

Understanding the Code

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

  1. UI Setup:
  2. Title and description using st.title() and st.write()
  3. Input field with st.text_input()
  4. Search button with st.button()
  1. Agent Integration:
  2. Initialize the AI agent with specific instructions
  3. Connect the agent to the UI components
  4. Handle user input and display results
  1. User Experience:
  2. Loading spinner during processing
  3. Input validation and error messages
  4. Clean result display

Customization

You can enhance the UI with additional Streamlit components:

python
# 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