CoolFace
Apppublic

polojuan/agentic-workflows

sourceHugging Facemitupdated 11mo agoView on Hugging Face
0likes
README.md424 linesDownload Raw Back to root
1---2title: Agentic Workflows3emoji: πŸ€–4colorFrom: blue5colorTo: gray6sdk: streamlit7sdk_version: 1.49.18app_file: app.py9pinned: false10license: mit11short_description: 'Multi-Agent Systems for Research and Database Analysis'12---13 14# πŸ€– Agentic Workflow Platform15 16An 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.17 18![Python](https://img.shields.io/badge/python-3.8+-blue.svg)19![Streamlit](https://img.shields.io/badge/streamlit-1.49.1-red.svg)20![License](https://img.shields.io/badge/license-MIT-green.svg)21 22## 🌟 Features23 24### **πŸ€– Fully Autonomous**25- Zero manual intervention required26- Intelligent task planning and decomposition27- Self-organizing multi-agent coordination28 29### **🎯 Evidence-Based**30- Searches only credible, peer-reviewed sources31- Medical databases (PubMed, Cochrane Library)32- Academic databases (arXiv, Wikipedia, Tavily)33- APA format citations34 35### **πŸ“ Complete Reports**36- Structured markdown output37- Introduction, findings, and conclusions38- Comprehensive reference sections39- Publication-ready format40 41## πŸ—οΈ Architecture42 43### Research Workflows (5-Agent System)44 45The research assistants use a **5-agent workflow** that works collaboratively:46 471. **Planner Agent** - Breaks down research topics into actionable steps482. **Research/Medical Agent** - Searches credible databases and sources493. **Writer Agent** - Drafts well-structured summaries and reports504. **Editor Agent** - Reviews, critiques, and refines content515. **Execution Agent** - Orchestrates the entire workflow52 53### Database Workflow (Text-to-SQL)54 55The OpenRCA assistant uses an **iterative refinement workflow**:56 571. **Database Agent** - Converts natural language questions to SQL queries582. **Query Executor** - Runs SQL against the database593. **Result Evaluator** - Reviews query results for accuracy604. **Query Refiner** - Iteratively improves SQL based on feedback615. **Result Interpreter** - Translates data into natural language answers62 63## πŸ“± Applications64 65The application includes four pages accessible via the Streamlit sidebar:66 67### 🏠 **Landing Page**68- Overview of the agentic workflow platform69- Choose between Research Assistant, Clinical Evidence, or OpenRCA70- Key features and capabilities71- Navigation to specialized assistants72 73### ✍️ **Research Assistant** (General Academic & Scientific)74 75**Ideal for:**76- Academic research papers77- Technical documentation78- Scientific literature reviews79- General knowledge gathering80 81**Data Sources:**82- πŸ“š **arXiv** - Academic papers and preprints83- 🌐 **Tavily** - General web search84- πŸ“– **Wikipedia** - Encyclopedic knowledge85 86**Typical Use Cases:**87- Computer Science & AI research88- Physics & Mathematics89- Engineering topics90- General academic inquiries91 92**Workflow Time:** 5-10 minutes93 94### πŸ” **Dr. ResearchRx** (Evidence-Based Medical Research)95 96**Ideal for:**97- Clinical research98- Medical literature reviews99- Evidence-based medicine100- Healthcare decision support101 102**Data Sources:**103- 🩺 **PubMed** - Medical research papers & clinical studies104- πŸ“Š **Cochrane Library** - Systematic reviews & meta-analyses105 106**Typical Use Cases:**107- Disease research & treatment options108- Drug efficacy & safety studies109- Clinical guidelines & protocols110- Medical condition analysis111 112**Workflow Time:** 2-3 minutes113 114### πŸ”§ **OpenRCA** (Root Cause Analysis Database Assistant)115 116**Ideal for:**117- Equipment failure analysis118- Root cause investigation119- Corrective action tracking120- Maintenance data exploration121 122**Features:**123- πŸ—£οΈ **Natural Language Queries** - Ask questions in plain English124- πŸ”„ **Smart SQL Generation** - AI converts questions to accurate SQL125- βœ… **Iterative Refinement** - Automatically improves query accuracy126- πŸ“Š **Database Browser** - Interactive table exploration with filtering127- πŸ“₯ **Export Data** - Download filtered results as CSV128 129**Typical Use Cases:**130- Finding most expensive failures by equipment/area131- Identifying common root causes and failure patterns132- Analyzing downtime and maintenance costs133- Reviewing corrective actions and their effectiveness134 135**Database Schema:**136- Equipment failures with timestamps and costs137- Root cause analysis records138- Corrective actions and prevention measures139- Asset hierarchy (Asset β†’ Area β†’ Equipment)140 141**Workflow Time:** 1-2 minutes142 143## πŸš€ Getting Started144 145### Prerequisites146 147- Python 3.8 or higher148- OpenAI API key149- Tavily API key150 151### Installation152 1531. **Clone the repository:**154```bash155git clone https://github.com/palscruz23/agentic-workflow.git156cd agentic-workflow157```158 1592. **Install dependencies:**160```bash161pip install -r requirements.txt162```163 1643. **Set up environment variables:**165 166Create a `.env` file in the root directory:167```bash168OPENAI_API_KEY=your_openai_api_key_here169TAVILY_API_KEY=your_tavily_api_key_here170```171 1724. **Run the application:**173```bash174streamlit run app.py175```176 177The application will open in your default browser at `http://localhost:8501`178 179### 🐳 Docker Deployment180 181You can also run the application using Docker for a containerized deployment:182 183**Option 1: Using Docker Compose (Recommended)**184 1851. **Create `.env` file** with your API keys:186```bash187OPENAI_API_KEY=your_openai_api_key_here188TAVILY_API_KEY=your_tavily_api_key_here189```190 1912. **Build and run with Docker Compose:**192```bash193docker-compose up -d194```195 1963. **Access the application:**197Open your browser at `http://localhost:8501`198 1994. **Stop the container:**200```bash201docker-compose down202```203 204**Option 2: Using Docker directly**205 2061. **Build the Docker image:**207```bash208docker build -t agentic-workflow .209```210 2112. **Run the container:**212```bash213docker run -d \214  -p 8501:8501 \215  -e OPENAI_API_KEY=your_openai_api_key_here \216  -e TAVILY_API_KEY=your_tavily_api_key_here \217  --name agentic-research \218  agentic-workflow219```220 2213. **View logs:**222```bash223docker logs -f agentic-research224```225 2264. **Stop the container:**227```bash228docker stop agentic-research229docker rm agentic-research230```231 232## πŸ“‚ Project Structure233 234```235agentic-workflow/236β”œβ”€β”€ app.py                      # Landing page (main entry point)237β”œβ”€β”€ About.py                    # About page with workflow details238β”œβ”€β”€ pages/239β”‚   β”œβ”€β”€ 1_Research Assistant.py # General academic research240β”‚   β”œβ”€β”€ 2_Clinical Evidence.py  # Medical research241β”‚   └── 3_OpenRCA.py            # Database assistant for RCA242β”œβ”€β”€ agents/243β”‚   β”œβ”€β”€ planner_agent.py        # Task planning and decomposition244β”‚   β”œβ”€β”€ research_agent.py       # General research (arXiv, Tavily, Wikipedia)245β”‚   β”œβ”€β”€ medical_agent.py        # Medical research (PubMed, Cochrane)246β”‚   β”œβ”€β”€ writer_agent.py         # Content generation247β”‚   β”œβ”€β”€ editor_agent.py         # Content review and refinement248β”‚   β”œβ”€β”€ execution_agent.py      # Workflow orchestration249β”‚   └── database_agent.py       # Text-to-SQL with iterative refinement250β”œβ”€β”€ tools/251β”‚   β”œβ”€β”€ research_tools.py       # arXiv, Tavily, Wikipedia search tools252β”‚   └── medical_tools.py        # PubMed, Cochrane search tools253β”œβ”€β”€ utils/254β”‚   └── database.py             # Database utilities and schema255β”œβ”€β”€ data/256β”‚   └── rca_data.db             # SQLite database for RCA257β”œβ”€β”€ requirements.txt            # Python dependencies258β”œβ”€β”€ Dockerfile                  # Docker image configuration259β”œβ”€β”€ docker-compose.yml          # Docker Compose configuration260β”œβ”€β”€ .dockerignore              # Docker build ignore file261β”œβ”€β”€ .env                        # Environment variables (create this)262└── README.md                   # This file263```264 265## πŸ”§ Configuration266 267### Environment Variables268 269- `OPENAI_API_KEY` - Your OpenAI API key (required)270- `TAVILY_API_KEY` - Your Tavily API key (required)271- `DLAI_TAVILY_BASE_URL` - Optional custom Tavily base URL272 273### Model Configuration274 275By default, the application uses `gpt-4o-mini`. You can modify this in `app.py`:276 277```python278if "model" not in st.session_state:279    st.session_state.model = "gpt-4o-mini"  # Change this280```281 282## πŸ’‘ Usage Examples283 284### Example 1: General Academic Research285 286**Topic:** "Transformer architecture in neural networks"287 288**Agent Workflow:**2891. **Planner:** Breaks down into 5 steps (search arXiv, search Wikipedia, draft report, edit, finalize)2902. **Research Agent:** Searches arXiv for papers on transformers, queries Wikipedia for background2913. **Writer Agent:** Drafts comprehensive report with findings2924. **Editor Agent:** Reviews and improves clarity, structure2935. **Execution Agent:** Delivers final markdown report with references294 295**Output:** Complete research report with introduction, key findings, and APA citations296 297### Example 2: Medical Research298 299**Topic:** "Latest treatments for Type 2 Diabetes"300 301**Agent Workflow:**3021. **Planner:** Creates medical research plan3032. **Medical Agent:** Searches PubMed for clinical studies, Cochrane for systematic reviews3043. **Writer Agent:** Compiles evidence-based summary3054. **Editor Agent:** Refines medical terminology and accuracy3065. **Execution Agent:** Produces clinical evidence report307 308**Output:** Evidence-based medical report with peer-reviewed sources309 310### Example 3: Database Analysis (OpenRCA)311 312**Question:** "What are the top 3 most expensive failures?"313 314**Agent Workflow:**3151. **Database Agent:** Converts question to SQL query3162. **Query Executor:** Runs initial SQL query against RCA database3173. **Result Evaluator:** Reviews if results correctly answer the question3184. **Query Refiner:** Improves SQL to include relevant columns and fix aggregations3195. **Result Interpreter:** Translates data into natural language answer320 321**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."322 323## πŸ› οΈ Development324 325### Adding New Tools326 327To add a new research tool:328 3291. Create the tool function in `tools/research_tools.py` or `tools/medical_tools.py`:330```python331def new_search_tool(query: str, max_results: int = 5) -> list[dict]:332    # Implementation333    return results334```335 3362. Define the tool specification:337```python338new_tool_def = {339    "type": "function",340    "function": {341        "name": "new_search_tool",342        "description": "Description of what this tool does",343        "parameters": {...}344    }345}346```347 3483. Add to the appropriate agent's tool mapping349 350### Customizing Agents351 352Each agent can be customized by modifying the system prompts in the respective agent files:353- `agents/planner_agent.py` - Planning strategy354- `agents/research_agent.py` - Research approach355- `agents/writer_agent.py` - Writing style356- `agents/editor_agent.py` - Review criteria357 358## πŸ§ͺ Testing359 360Run the application locally to test:361```bash362streamlit run app.py363```364 365Navigate to each page to ensure:366- βœ… Landing page displays correctly with all three assistants367- βœ… Research Assistant can search arXiv, Tavily, Wikipedia368- βœ… Clinical Evidence can search PubMed, Cochrane369- βœ… OpenRCA can query database and refine SQL queries370- βœ… OpenRCA database browser can filter and export data371- βœ… Reports are generated with proper formatting372 373## πŸ› Troubleshooting374 375### Common Issues376 377**Issue: Import Error for agents**378```379ImportError: cannot import name 'planner_agent' from 'agents.planner_agent'380```381**Solution:** Ensure all agent files have proper OpenAI client initialization inside functions, not at module level.382 383**Issue: API Key Errors**384```385ValueError: TAVILY_API_KEY not found in environment variables386```387**Solution:** Create `.env` file with required API keys.388 389**Issue: Session State Errors**390```391AttributeError: st.session_state has no attribute 'client'392```393**Solution:** The app initializes session state in `init_chatbot()`. Ensure it's called before using agents.394 395## 🀝 Contributing396 397Contributions are welcome! Here's how:398 3991. Fork the repository4002. Create a feature branch (`git checkout -b feature/amazing-feature`)4013. Commit your changes (`git commit -m 'Add amazing feature'`)4024. Push to the branch (`git push origin feature/amazing-feature`)4035. Open a Pull Request404 405## πŸ“„ License406 407This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.408 409## πŸ™ Acknowledgments410 411- Built with [Streamlit](https://streamlit.io/)412- Powered by [OpenAI GPT-4o-mini](https://openai.com/)413- Research tools: [arXiv](https://arxiv.org/), [PubMed](https://pubmed.ncbi.nlm.nih.gov/), [Cochrane Library](https://www.cochranelibrary.com/)414- Web search: [Tavily](https://tavily.com/)415 416## πŸ“ž Support417 418- **Issues:** [GitHub Issues](https://github.com/palscruz23/agentic-workflow/issues)419- **Repository:** [GitHub Repository](https://github.com/palscruz23/rul-estimation)420 421---422 423**Built with Claude, OpenAI, Streamlit | Powered by Multi-Agent AI** πŸ€–424