Streamlit Agent
Learn how to create web interfaces for your AI agents using Streamlit
Quick Start
- Install Dependencies
First, install the required packages:
bash pip install praisonaiagents streamlit - 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") - Run Application
Run your Streamlit app:
bash streamlit run app.py
Features
Easy Integration
Seamlessly integrate AI agents with Streamlit’s UI components.
Interactive UICreate responsive interfaces with real-time updates.
Progress IndicatorsBuilt-in loading states and progress indicators.
Rich OutputDisplay formatted text, markdown, and other rich content.
Understanding the Code
The example demonstrates a simple research assistant with these key components:
- UI Setup:
- Title and description using
st.title()andst.write() - Input field with
st.text_input() - Search button with
st.button()
- Agent Integration:
- Initialize the AI agent with specific instructions
- Connect the agent to the UI components
- Handle user input and display results
- 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
- Learn about Prompt Chaining for complex UI workflows
- Explore Evaluator Optimizer for improving responses
- Check out Gradio Integration for an alternative UI framework