Skip to content

Ginkgo-AI/pocketflow-db-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PocketFlow Database Query Agent

A flexible, extensible PocketFlow agent that converts natural language queries into database queries with support for multiple database types, intelligent schema analysis, and seamless integration into other agentic systems.

πŸš€ Features

Core Capabilities

  • Multi-Database Support: PostgreSQL, MySQL, SQLite, SQL Server, and more
  • Intelligent Query Analysis: Understands query intent, complexity, and requirements
  • Smart Schema Management: Context-aware schema extraction and caching
  • Advanced Error Handling: Multi-stage validation and correction
  • Security-First: SQL injection prevention and access control
  • Performance Optimized: Connection pooling and query caching

Integration Ready

  • Plugin Architecture: Extensible components for custom database types
  • API Interface: RESTful API for external system integration
  • Event System: Callbacks and hooks for monitoring and customization
  • Configuration Management: Environment-based and programmatic configuration
  • Multiple Output Formats: JSON, CSV, formatted tables, and custom formats

Advanced Features

  • Query Classification: Automatically categorizes queries (SELECT, INSERT, analytics, etc.)
  • Result Visualization: Built-in charting and data visualization options
  • Query History & Caching: Intelligent caching of similar queries
  • Access Control: Role-based permissions and query restrictions
  • Monitoring & Logging: Comprehensive observability features

πŸ—οΈ Architecture

The agent uses a modular, plugin-based architecture with these core components:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Query Input   β”‚ -> β”‚  Query Analyzer  β”‚ -> β”‚ Schema Manager  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Result Formatterβ”‚ <- β”‚  Query Executor  β”‚ <- β”‚ Query Generator β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚  Error Handler   β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Installation

# Clone or create the project
cd cookbook/pocketflow-db-agent

# Install dependencies
pip install -r requirements.txt

# Set up configuration
cp .env.example .env
# Edit .env with your settings

Basic Usage

from pocketflow_db_agent import DatabaseAgent

# Initialize agent
agent = DatabaseAgent(
    database_url="postgresql://user:pass@localhost/mydb",
    # or use configuration file
    # config_file="config.yaml"
)

# Simple query
result = agent.query("Show me all customers from New York")
print(result.data)  # Formatted results
print(result.sql)   # Generated SQL
print(result.metadata)  # Execution metadata

# Advanced usage with options
result = agent.query(
    "What are the top 5 products by revenue this month?",
    options={
        "format": "json",
        "include_metadata": True,
        "cache": True,
        "validate": True
    }
)

Integration with Other Systems

# As a PocketFlow node
from pocketflow_db_agent.nodes import DatabaseQueryNode

db_node = DatabaseQueryNode(
    database_url="sqlite:///data.db",
    config={"max_retries": 3}
)

# Use in a flow
query_flow = Flow(start=db_node)
result = query_flow.run({"natural_query": "Count all users"})

API Server Mode

# Start the API server
python -m pocketflow_db_agent.server --port 8080

# Use the REST API
curl -X POST http://localhost:8080/query \
  -H "Content-Type: application/json" \
  -d '{"query": "List all active users", "database": "main"}'

πŸ“– Documentation

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“ License

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

About

πŸš€ Advanced Natural Language to SQL Database Query Agent for PocketFlow. Features multi-database support, enterprise security, and seamless workflow integration.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages