CoolFace
Apppublic

polojuan/agentic-workflows

sourceHugging Facemitupdated 11mo agoView on Hugging Face
0likes
App README

πŸ€– Agentic Workflow Platform

An intelligent multi-agent platform providing specialized AI assistants for different workflowsβ€”from academic research to medical evidence gathering to database analysis. Choose your assistant and let AI agents handle the complexity while you focus on insights.

Python Streamlit License

🌟 Features

πŸ€– Fully Autonomous

  • β€”Zero manual intervention required
  • β€”Intelligent task planning and decomposition
  • β€”Self-organizing multi-agent coordination

🎯 Evidence-Based

  • β€”Searches only credible, peer-reviewed sources
  • β€”Medical databases (PubMed, Cochrane Library)
  • β€”Academic databases (arXiv, Wikipedia, Tavily)
  • β€”APA format citations

πŸ“ Complete Reports

  • β€”Structured markdown output
  • β€”Introduction, findings, and conclusions
  • β€”Comprehensive reference sections
  • β€”Publication-ready format

πŸ—οΈ Architecture

Research Workflows (5-Agent System)

The research assistants use a 5-agent workflow that works collaboratively:

  1. 1.Planner Agent - Breaks down research topics into actionable steps
  2. 2.Research/Medical Agent - Searches credible databases and sources
  3. 3.Writer Agent - Drafts well-structured summaries and reports
  4. 4.Editor Agent - Reviews, critiques, and refines content
  5. 5.Execution Agent - Orchestrates the entire workflow

Database Workflow (Text-to-SQL)

The OpenRCA assistant uses an iterative refinement workflow:

  1. 1.Database Agent - Converts natural language questions to SQL queries
  2. 2.Query Executor - Runs SQL against the database
  3. 3.Result Evaluator - Reviews query results for accuracy
  4. 4.Query Refiner - Iteratively improves SQL based on feedback
  5. 5.Result Interpreter - Translates data into natural language answers

πŸ“± Applications

The application includes four pages accessible via the Streamlit sidebar:

🏠 Landing Page

  • β€”Overview of the agentic workflow platform
  • β€”Choose between Research Assistant, Clinical Evidence, or OpenRCA
  • β€”Key features and capabilities
  • β€”Navigation to specialized assistants

✍️ Research Assistant (General Academic & Scientific)

Ideal for:

  • β€”Academic research papers
  • β€”Technical documentation
  • β€”Scientific literature reviews
  • β€”General knowledge gathering

Data Sources:

  • β€”πŸ“š arXiv - Academic papers and preprints
  • β€”πŸŒ Tavily - General web search
  • β€”πŸ“– Wikipedia - Encyclopedic knowledge

Typical Use Cases:

  • β€”Computer Science & AI research
  • β€”Physics & Mathematics
  • β€”Engineering topics
  • β€”General academic inquiries

Workflow Time: 5-10 minutes

πŸ” Dr. ResearchRx (Evidence-Based Medical Research)

Ideal for:

  • β€”Clinical research
  • β€”Medical literature reviews
  • β€”Evidence-based medicine
  • β€”Healthcare decision support

Data Sources:

  • β€”πŸ©Ί PubMed - Medical research papers & clinical studies
  • β€”πŸ“Š Cochrane Library - Systematic reviews & meta-analyses

Typical Use Cases:

  • β€”Disease research & treatment options
  • β€”Drug efficacy & safety studies
  • β€”Clinical guidelines & protocols
  • β€”Medical condition analysis

Workflow Time: 2-3 minutes

πŸ”§ OpenRCA (Root Cause Analysis Database Assistant)

Ideal for:

  • β€”Equipment failure analysis
  • β€”Root cause investigation
  • β€”Corrective action tracking
  • β€”Maintenance data exploration

Features:

  • β€”πŸ—£οΈ Natural Language Queries - Ask questions in plain English
  • β€”πŸ”„ Smart SQL Generation - AI converts questions to accurate SQL
  • β€”βœ… Iterative Refinement - Automatically improves query accuracy
  • β€”πŸ“Š Database Browser - Interactive table exploration with filtering
  • β€”πŸ“₯ Export Data - Download filtered results as CSV

Typical Use Cases:

  • β€”Finding most expensive failures by equipment/area
  • β€”Identifying common root causes and failure patterns
  • β€”Analyzing downtime and maintenance costs
  • β€”Reviewing corrective actions and their effectiveness

Database Schema:

  • β€”Equipment failures with timestamps and costs
  • β€”Root cause analysis records
  • β€”Corrective actions and prevention measures
  • β€”Asset hierarchy (Asset β†’ Area β†’ Equipment)

Workflow Time: 1-2 minutes

πŸš€ Getting Started

Prerequisites

  • β€”Python 3.8 or higher
  • β€”OpenAI API key
  • β€”Tavily API key

Installation

  1. 1.Clone the repository:
bash
git clone https://github.com/palscruz23/agentic-workflow.git
cd agentic-workflow
  1. 1.Install dependencies:
bash
pip install -r requirements.txt
  1. 1.Set up environment variables:

Create a .env file in the root directory:

bash
OPENAI_API_KEY=your_openai_api_key_here
TAVILY_API_KEY=your_tavily_api_key_here
  1. 1.Run the application:
bash
streamlit run app.py

The application will open in your default browser at http://localhost:8501

🐳 Docker Deployment

You can also run the application using Docker for a containerized deployment:

Option 1: Using Docker Compose (Recommended)

  1. 1.Create `.env` file with your API keys:
bash
OPENAI_API_KEY=your_openai_api_key_here
TAVILY_API_KEY=your_tavily_api_key_here
  1. 1.Build and run with Docker Compose:
bash
docker-compose up -d
  1. 1.Access the application: Open your browser at http://localhost:8501
  1. 1.Stop the container:
bash
docker-compose down

Option 2: Using Docker directly

  1. 1.Build the Docker image:
bash
docker build -t agentic-workflow .
  1. 1.Run the container:
bash
docker run -d \
  -p 8501:8501 \
  -e OPENAI_API_KEY=your_openai_api_key_here \
  -e TAVILY_API_KEY=your_tavily_api_key_here \
  --name agentic-research \
  agentic-workflow
  1. 1.View logs:
bash
docker logs -f agentic-research
  1. 1.Stop the container:
bash
docker stop agentic-research
docker rm agentic-research

πŸ“‚ Project Structure

agentic-workflow/
β”œβ”€β”€ app.py                      # Landing page (main entry point)
β”œβ”€β”€ About.py                    # About page with workflow details
β”œβ”€β”€ pages/
β”‚   β”œβ”€β”€ 1_Research Assistant.py # General academic research
β”‚   β”œβ”€β”€ 2_Clinical Evidence.py  # Medical research
β”‚   └── 3_OpenRCA.py            # Database assistant for RCA
β”œβ”€β”€ agents/
β”‚   β”œβ”€β”€ planner_agent.py        # Task planning and decomposition
β”‚   β”œβ”€β”€ research_agent.py       # General research (arXiv, Tavily, Wikipedia)
β”‚   β”œβ”€β”€ medical_agent.py        # Medical research (PubMed, Cochrane)
β”‚   β”œβ”€β”€ writer_agent.py         # Content generation
β”‚   β”œβ”€β”€ editor_agent.py         # Content review and refinement
β”‚   β”œβ”€β”€ execution_agent.py      # Workflow orchestration
β”‚   └── database_agent.py       # Text-to-SQL with iterative refinement
β”œβ”€β”€ tools/
β”‚   β”œβ”€β”€ research_tools.py       # arXiv, Tavily, Wikipedia search tools
β”‚   └── medical_tools.py        # PubMed, Cochrane search tools
β”œβ”€β”€ utils/
β”‚   └── database.py             # Database utilities and schema
β”œβ”€β”€ data/
β”‚   └── rca_data.db             # SQLite database for RCA
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ Dockerfile                  # Docker image configuration
β”œβ”€β”€ docker-compose.yml          # Docker Compose configuration
β”œβ”€β”€ .dockerignore              # Docker build ignore file
β”œβ”€β”€ .env                        # Environment variables (create this)
└── README.md                   # This file

πŸ”§ Configuration

Environment Variables

  • β€”OPENAI_API_KEY - Your OpenAI API key (required)
  • β€”TAVILY_API_KEY - Your Tavily API key (required)
  • β€”DLAI_TAVILY_BASE_URL - Optional custom Tavily base URL

Model Configuration

By default, the application uses gpt-4o-mini. You can modify this in app.py:

python
if "model" not in st.session_state:
    st.session_state.model = "gpt-4o-mini"  # Change this

πŸ’‘ Usage Examples

Example 1: General Academic Research

Topic: "Transformer architecture in neural networks"

Agent Workflow:

  1. 1.Planner: Breaks down into 5 steps (search arXiv, search Wikipedia, draft report, edit, finalize)
  2. 2.Research Agent: Searches arXiv for papers on transformers, queries Wikipedia for background
  3. 3.Writer Agent: Drafts comprehensive report with findings
  4. 4.Editor Agent: Reviews and improves clarity, structure
  5. 5.Execution Agent: Delivers final markdown report with references

Output: Complete research report with introduction, key findings, and APA citations

Example 2: Medical Research

Topic: "Latest treatments for Type 2 Diabetes"

Agent Workflow:

  1. 1.Planner: Creates medical research plan
  2. 2.Medical Agent: Searches PubMed for clinical studies, Cochrane for systematic reviews
  3. 3.Writer Agent: Compiles evidence-based summary
  4. 4.Editor Agent: Refines medical terminology and accuracy
  5. 5.Execution Agent: Produces clinical evidence report

Output: Evidence-based medical report with peer-reviewed sources

Example 3: Database Analysis (OpenRCA)

Question: "What are the top 3 most expensive failures?"

Agent Workflow:

  1. 1.Database Agent: Converts question to SQL query
  2. 2.Query Executor: Runs initial SQL query against RCA database
  3. 3.Result Evaluator: Reviews if results correctly answer the question
  4. 4.Query Refiner: Improves SQL to include relevant columns and fix aggregations
  5. 5.Result Interpreter: Translates data into natural language answer

Output: "The top 3 most expensive failures are: 1) Mine B Concentrate Storage area with an impact of 3,492,427 AUD due to improper tensioning; 2) Mine A Haul Road area with an impact of 3,344,968 AUD due to software malfunction; and 3) Mine A Water Treatment area with an impact of 3,135,004 AUD due to thermal stress."

πŸ› οΈ Development

Adding New Tools

To add a new research tool:

  1. 1.Create the tool function in tools/research_tools.py or tools/medical_tools.py:
python
def new_search_tool(query: str, max_results: int = 5) -> list[dict]:
    # Implementation
    return results
  1. 1.Define the tool specification:
python
new_tool_def = {
    "type": "function",
    "function": {
        "name": "new_search_tool",
        "description": "Description of what this tool does",
        "parameters": {...}
    }
}
  1. 1.Add to the appropriate agent's tool mapping

Customizing Agents

Each agent can be customized by modifying the system prompts in the respective agent files:

  • β€”agents/planner_agent.py - Planning strategy
  • β€”agents/research_agent.py - Research approach
  • β€”agents/writer_agent.py - Writing style
  • β€”agents/editor_agent.py - Review criteria

πŸ§ͺ Testing

Run the application locally to test:

bash
streamlit run app.py

Navigate to each page to ensure:

  • β€”βœ… Landing page displays correctly with all three assistants
  • β€”βœ… Research Assistant can search arXiv, Tavily, Wikipedia
  • β€”βœ… Clinical Evidence can search PubMed, Cochrane
  • β€”βœ… OpenRCA can query database and refine SQL queries
  • β€”βœ… OpenRCA database browser can filter and export data
  • β€”βœ… Reports are generated with proper formatting

πŸ› Troubleshooting

Common Issues

Issue: Import Error for agents

ImportError: cannot import name 'planner_agent' from 'agents.planner_agent'

Solution: Ensure all agent files have proper OpenAI client initialization inside functions, not at module level.

Issue: API Key Errors

ValueError: TAVILY_API_KEY not found in environment variables

Solution: Create .env file with required API keys.

Issue: Session State Errors

AttributeError: st.session_state has no attribute 'client'

Solution: The app initializes session state in init_chatbot(). Ensure it's called before using agents.

🀝 Contributing

Contributions are welcome! Here's how:

  1. 1.Fork the repository
  2. 2.Create a feature branch (git checkout -b feature/amazing-feature)
  3. 3.Commit your changes (git commit -m 'Add amazing feature')
  4. 4.Push to the branch (git push origin feature/amazing-feature)
  5. 5.Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support


Built with Claude, OpenAI, Streamlit | Powered by Multi-Agent AI πŸ€–