Commit 6fae1d4b authored by Kostas Chartsias's avatar Kostas Chartsias
Browse files

first major commit for AI_agents module

parent 47e140c2
Loading
Loading
Loading
Loading

AI_agent/README.md

0 → 100644
+122 −0
Original line number Diff line number Diff line
# AI Agent 

This repository contains a lightweight **[`Quart`](https://quart.palletsprojects.com/en/latest/) backend server** that exposes API endpoints for interacting with different AI sub-agents. 

---

## 📁 Project Structure

```
AI_agent/
├── sub_agents/            # AI sub-agent implementations
├── routes/                # API route definitions
│   ├── groq.py             # Groq-related endpoints
│   └── debug.py            # Debug / health endpoints
├── .env                   # Environment variables
├── app.py                 # Application entry point
├── requirements.txt       # Python dependencies
```

---

## ⚙️ Configuration

The application is configured using environment variables defined in a `.env` file.

### `.env` Example

```env
# --- Backend Server Configuration ---
APP_HOST=127.0.0.1
APP_PORT=9013

# --- MCP Server ---
MCP_SERVER_URL=http://127.0.0.1:8004/mcp

# --- Groq ---
GROQ_API_KEY=your_groq_api_key_here
GROQ_MODEL_NAME=qwen/qwen3-32b
```

### Environment Variables

| Variable          | Description                             |
| ----------------- |-----------------------------------------|
| `APP_HOST`        | Host interface the server binds to      |
| `APP_PORT`        | Port the backend server listens on      |
| `MCP_SERVER_URL`  | URL of the MCP server used by sub-agent |
| `GROQ_API_KEY`    | API key for Groq LLM access             |
| `GROQ_MODEL_NAME` | Groq model identifier                   |

---

## ⚙️ Installation

### 1. Clone the Repository

```
git clone <your-repo-url>
cd AI_agent
```

### 2. Create a Virtual Environment (Recommended)

```
python3 -m venv venv
source venv/bin/activate  # Linux / macOS
venv\Scripts\activate     # Windows
```

### 3. Install Dependencies

```
pip install -r requirements.txt
```

### 4. Configure Environment Variables

Create a `.env` file in the root of `AI_agent/` and populate it as shown above.

---

## 🚀 Usage

### Option 1 - Local (venv)

Follow these steps to set up and run the app locally.

Start the backend server using:

```
python app.py
```

The server will start at:

```
http://127.0.0.1:9013
```

CORS is enabled for all origins.

---


## 🧩 Extending the Application

To add new functionality:

1. Create a new sub-agent under `sub_agents/`
2. Add corresponding API routes under `routes/`
3. Register the routes in `app.py`

Example:

```
from AI_agent.routes.my_agent import register_my_agent_routes
register_my_agent_routes(app)
```

---

AI_agent/app.py

0 → 100644
+24 −0
Original line number Diff line number Diff line
import os
import logging
from quart import Quart
from quart_cors import cors
from dotenv import load_dotenv

from AI_agent.routes.groq import register_groq_routes
from AI_agent.routes.debug import register_debug_routes

load_dotenv()

logging.basicConfig(level=logging.INFO)

app = Quart(__name__)
app = cors(app, allow_origin="*")

register_groq_routes(app)
register_debug_routes(app)


if __name__ == "__main__":
    host = os.getenv("APP_HOST", "127.0.0.1")
    port = int(os.getenv("APP_PORT", "9013"))
    app.run(host=host, port=port, debug=False, use_reloader=False)
 No newline at end of file
+7 −0
Original line number Diff line number Diff line
langchain_google_genai==3.1.0
langchain_groq==1.0.1
mcp_use==1.4.0
objgraph==3.6.2
python-dotenv==1.2.1
quart==0.20.0
quart_cors==0.8.0
+16 −0
Original line number Diff line number Diff line
import io
import sys
import objgraph
from quart import Response

def register_debug_routes(app):

    @app.route("/debug/objgraph", methods=["GET"])
    async def debug_objgraph():
        buf = io.StringIO()
        sys.stdout = buf

        objgraph.show_growth(limit=10)

        sys.stdout = sys.__stdout__
        return Response(buf.getvalue(), mimetype="text/plain")
+23 −0
Original line number Diff line number Diff line
import logging
from quart import request, jsonify
from AI_agent.sub_agents.groq_agent import create_groq_agent

def register_groq_routes(app):

    @app.route("/groq-mcp", methods=["POST"])
    async def groq_query():
        data = await request.get_json()
        query = data.get("query") if data else None

        if not query:
            return jsonify({"error": "No query provided"}), 400

        agent = await create_groq_agent()
        try:
            result = await agent.run(query)
            return jsonify({"response": result})
        except Exception as e:
            logging.error("Error in groq_query", exc_info=True)
            return jsonify({"error": str(e)}), 500
        finally:
            await agent.close()
Loading