- Overview
- Features
- Prerequisites
- Quick Start
- Installation
- Configuration
- Usage
- Security Features
- Architecture
- Project Structure
- Contributing
- Known Issues
- License
This project implements a Local Multi-Agent AI Content Refinement System using IBM's newest state-of-the-art Granite Nano models via Ollama. It leverages a Generator-Critic-Summarizer-Research workflow to iteratively produce high-quality content based on a given task, incorporating external research and rigorous quality evaluation.
The system runs entirely locally, ensuring data privacy and security, and is designed for production environments with built-in cybersecurity features.
Disclaimer: This agentic system is experimental and must undergo additional evaluation before being deployed into a production environment.
- Multi-Agent Workflow: Generator, Critic, Summarizer, and Research agents collaborate to refine content.
- Local Execution: Runs entirely on your local machine using Ollama.
- IBM Granite Models: Leverages
ibm/granite4:350m,ibm/granite4:1b, andibm/granite4:3bmodels. - External Research: Integrates with the Tavily API for up-to-date information retrieval.
- Iterative Refinement: Continuously improves content based on quality scores until a threshold is met.
- Quality Assurance: Built-in critic agent evaluates content and provides specific feedback.
- Security-First Design: Implements secure API key management, input sanitization, audit logging, and more.
- Configurable: Easily configurable via YAML file for models, workflow parameters, and security settings.
- Python 3.8 or higher - Download
- Ollama - Install
- IBM Granite models via Ollama:
ibm/granite4:350m(Generator - fastest)ibm/granite4:1b(Critic - medium)ibm/granite4:3b(Summarizer & Researcher - largest)
- Tavily API Key - Get free key
# 1. Clone the repository
git clone <your-repository-url>
cd granite4-local-agents
# 2. Install dependencies
pip install -r requirements.txt
# 3. Start Ollama
ollama serve
# 4. Pull IBM Granite models
ollama pull ibm/granite4:350m
ollama pull ibm/granite4:1b
ollama pull ibm/granite4:3b
# 5. Set up environment
cp .env.example .env
# Edit .env and add your TAVILY_API_KEY
# 6. Run the application
python granite4-local-main.py --task "Write a blog post about AI"For detailed installation instructions, see SETUP.md.
git clone <your-repository-url>
cd granite4-local-agents# Create virtual environment
python3 -m venv venv
# Activate virtual environment
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtThis installs:
aiohttp- Async HTTP clientpyyaml- YAML configuration supporttenacity- Retry logic with exponential backoffrequests- Synchronous HTTP for validation
Install Ollama from ollama.com, then:
# Start Ollama server (in a separate terminal)
ollama serve
# Pull required IBM Granite models
ollama pull ibm/granite4:350m
ollama pull ibm/granite4:1b
ollama pull ibm/granite4:3bImportant: All model names must include the
ibm/prefix.
# Copy environment template
cp .env.example .env
# Edit .env and add your Tavily API key
# TAVILY_API_KEY=your_actual_api_key_hereGet your free Tavily API key from tavily.com.
Security Note: Never commit your .env file to version control!
The system uses config.yaml for configuration. You can customize:
models:
generator: "ibm/granite4:350m" # Fast model for content generation
critic: "ibm/granite4:1b" # Medium model for evaluation
summarizer: "ibm/granite4:3b" # Large model for summarization
researcher: "ibm/granite4:3b" # Large model for researchworkflow:
max_iterations: 5 # Maximum refinement cycles
quality_threshold: 8.0 # Target quality score (0-10)tavily:
search_depth: "advanced" # "basic" or "advanced"
max_results: 3 # Number of search results
timeout: 30 # Request timeout in secondssecurity:
audit_log_file: "agentic_workflow_audit.log"
enable_pii_redaction: true
enable_audit_logging: trueFor all configuration options, see the config.yaml file.
Run with a specific task:
python granite4-local-main.py --task "Your detailed content creation task here"Run without arguments to be prompted:
python granite4-local-main.py
# You will be asked: "π― Enter your content creation task: "python granite4-local-main.py --task "Write a comprehensive blog post about the benefits of renewable energy for residential use."The system will:
- π Conduct research using Tavily API
- π Generate content using
ibm/granite4:350m - π― Evaluate quality using
ibm/granite4:1b - π Refine iteratively based on feedback
- π Summarize progress using
ibm/granite4:3b - β Deliver final content with quality score
Example output:
π Starting content refinement for: Write a blog post about renewable energy
============================================================
π Conducting initial research...
π Iteration 1/5
π Generating initial content...
π― Evaluating content quality...
Quality Score: 7.5/10
π Summarizing progress...
...
β
Quality threshold reached! Score: 8.2
============================================================
π CONTENT REFINEMENT COMPLETE!
============================================================
π Final Quality Score: 8.2/10
π Iterations Completed: 3
β±οΈ Total Time: 45.3s
π Session ID: a3f5e8d2c1b4a6f9
This system implements enterprise-grade cybersecurity best practices:
- API keys loaded from environment variables
- Never hardcoded in source code
- Excluded from version control via
.gitignore
- Automatic detection of sensitive data
- Regex-based PII redaction for:
- Email addresses
- Social Security Numbers (SSN)
- Credit card numbers
- Phone numbers
- Sanitization before processing and logging
- Comprehensive event logging with timestamps
- Session tracking with unique IDs
- Cryptographic hash chains (SHA-256) for tamper detection
- Audit trail for all content generation and API calls
- Logs saved to
agentic_workflow_audit.log
- All external API calls over HTTPS
- Secure Tavily API integration
- TLS encryption for web requests
- Minimal system resource access
- Environment variable-based configuration
- Controlled file system operations
- Restricted network access
- Cryptographic hashing of context data
- Verification of data integrity between workflow steps
- Chain-of-custody for generated content
Audit logs location: agentic_workflow_audit.log
The system consists of several specialized components:
AIContentRefiner: Main orchestrator managing the workflowGeneratorAgent: Creates/refines content usingibm/granite4:350mCriticAgent: Evaluates quality usingibm/granite4:1bSummarizerAgent: Maintains context usingibm/granite4:3bResearchAgent: Analyzes tasks and coordinates research usingibm/granite4:3b
OllamaClient: Handles local Ollama API communicationTavilyResearcher: Interfaces with Tavily API for web researchSecurityManager: Centralizes security functions (logging, sanitization, hashing)
Task Input
β
Research Phase (TavilyResearcher)
β
Content Generation (GeneratorAgent - ibm/granite4:350m)
β
Quality Evaluation (CriticAgent - ibm/granite4:1b)
β
Progress Summary (SummarizerAgent - ibm/granite4:3b)
β
Quality Check β [Pass] β Final Output
β β
[Fail] |
βββββββββββ
(Iterate with feedback)
granite4-local-agents/
βββ granite4-local-main.py # Main application code
βββ requirements.txt # Python dependencies
βββ config.yaml # Configuration file
βββ .env.example # Environment variable template
βββ .gitignore # Git ignore rules
βββ README.md # This file
βββ SETUP.md # Detailed setup guide
βββ CONTRIBUTING.md # Contribution guidelines
βββ BUGS.md # Known issues tracker
βββ LICENSE # MIT License
βββ Granite.jpg # Project logo
βββ .env # Your environment variables (git-ignored)
βββ agentic_workflow_audit.log # Security audit logs (git-ignored)
βββ context_history.log # Workflow context history (git-ignored)
βββ outputs/ # Generated content (git-ignored)
Contributions are welcome! Please read our Contributing Guidelines before submitting pull requests.
- Always use
ibm/prefix for Granite model references - Follow Python PEP 8 style guidelines
- Add type hints to all functions
- Include docstrings for public methods
- Test changes thoroughly before submitting
- Update documentation as needed
- Never commit sensitive data or API keys
- Bug fixes (see BUGS.md)
- Documentation improvements
- Test coverage
- Performance optimizations
- Security enhancements
- New agent capabilities
- Model integrations
See BUGS.md for a complete list of known issues and their status.
config.yaml.
Please check BUGS.md for details and workarounds.
"TAVILY_API_KEY environment variable not set"
- Solution: Create a
.envfile with your API key - See SETUP.md for details
"Cannot connect to Ollama"
- Solution: Run
ollama servein a separate terminal - Ensure Ollama is installed correctly
"Required model not found"
- Solution: Pull missing models with
ollama pull ibm/granite4:XXX - Verify models with
ollama list
For more troubleshooting help, see SETUP.md.
- SETUP.md - Comprehensive setup guide
- CONTRIBUTING.md - How to contribute
- BUGS.md - Known issues and bugs
- config.yaml - Configuration reference
See requirements.txt for Python dependencies:
- aiohttp >=3.9.0
- pyyaml >=6.0.1
- tenacity >=8.2.3
- requests >=2.31.0
This project is licensed under the MIT License - see the LICENSE file for details.
- IBM for the Granite AI models
- Ollama for local model hosting
- Tavily for research API
- IBM Champions Program
Β© 2025 Julian A. Gonzalez, Thomas Mertens
Star β this repository if you find it useful!
