Skip to content

nashtech-garage/ntg-python-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

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

Repository files navigation

Python Agentic AI Chatbot

A starter template for building agentic AI applications with multi-step reasoning, tool calling, and RAG capabilities.


πŸ“‹ Table of Contents

  1. Overview
  2. Architecture
  3. Key Features
  4. Project Structure
  5. Technology Stack
  6. Getting Started
  7. Configuration
  8. Architecture Decisions
  9. Extending the Project
  10. License

Overview

This project is a modular, extensible framework for building agentic AI applications in Python. It follows industry best practices inspired by frameworks like Microsoft Semantic Kernel, LangChain, and LlamaIndex.

Core Capabilities

  • Agentic Reasoning: Multi-step task planning and execution
  • Tool Calling: Automatic tool invocation based on agent decisions
  • RAG (Retrieval-Augmented Generation): Semantic search over documents
  • Flexible LLM Integration: Support for OpenAI, GitHub Models, Gemini
  • Streaming API: Real-time responses via FastAPI
  • Chat UI: React frontend with WebSocket support

Architecture

System Architecture Diagram

User (React Frontend)
  ↓
API Gateway (FastAPI)
  ↓
Orchestrator (Task Router)
  ↓
Agent (Reasoning Engine)
  ↓
Tool Manager (Search, Math, FileReader, MCP)
  ↓
Memory Layer (Vector DB, RAG)
  ↓
LLM Provider (OpenAI / GitHub / Gemini)
  ↓
Response Stream β†’ React UI

Component Overview

Component Purpose Technologies
Frontend User interaction & chat UI React, TypeScript
API HTTP/WebSocket server FastAPI, Uvicorn
Agent Decision making & planning Python async, reasoning logic
Tools Extensible capabilities Search, Math, File I/O, MCP
Memory Context & semantic search ChromaDB, Vector embeddings
LLM Language model calls OpenAI, GitHub Models, Gemini

Key Features

βœ… Ask anything - Natural language queries with full context
βœ… Multi-step reasoning - Agent plans and executes complex tasks
βœ… Tool calling - Automatic tool selection and invocation
βœ… Search capabilities - Web search, document search, code search
βœ… RAG integration - Semantic search over your documents
βœ… Streaming responses - Real-time output via WebSocket
βœ… Modular design - Easy to add new tools, providers, memory backends
βœ… Production-ready - Docker support, structured logging, error handling


Project Structure

ntg-python-agent/
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ agent/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ runner.py          # Agent loop
β”‚   β”‚   β”œβ”€β”€ planner.py         # Reasoning / planning
β”‚   β”‚   └── context.py         # Agent state
β”‚   β”‚
β”‚   β”œβ”€β”€ llm/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ provider.py        # OpenAI / GitHub / Gemini wrapper
β”‚   β”‚   └── models.py
β”‚   β”‚
β”‚   β”œβ”€β”€ tools/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ search.py
β”‚   β”‚   β”œβ”€β”€ math.py
β”‚   β”‚   └── tool_registry.py
β”‚   β”‚
β”‚   β”œβ”€β”€ memory/
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ vector_store.py
β”‚   β”‚   └── embedder.py
|   |
β”‚   └── server/
β”‚      β”œβ”€β”€ main.py            # FastAPI application
β”‚      └── routers/           # API endpoints (future)
β”‚
β”œβ”€β”€ tests/                      # Unit & integration tests
β”œβ”€β”€ pyproject.toml             # Python project configuration
β”œβ”€β”€ .env                       # Environment variables
β”œβ”€β”€ .gitignore
β”œβ”€β”€ LICENSE
└── README.md


Technology Stack

Layer Technology Version
Runtime Python 3.12+
API Framework FastAPI Latest
Async asyncio Built-in
LLM Integration OpenAI SDK Latest
Environment python-dotenv Latest
Frontend React 18+
Containerization Docker Latest

Getting Started

Prerequisites

  • Python 3.12 or higher (required by project configuration)
  • pip, uv package manager
  • API keys for LLM providers (OpenAI, etc.)
  • Optional: Docker for containerized deployment

Installation

Option 1: Standard pip installation

  1. Clone the repository

    git clone https://github.com/nashtech-garage/ntg-python-agent.git
    cd ntg-python-agent
  2. Create virtual environment

    python -m venv .venv
    source .venv/bin/activate  # on Linux/macOS
    .venv\Scripts\activate # On Windows
  3. Install pre-commit in venv

    python -m pip install pre-commit
    pre-commit --version # Check version
  4. Install base dependencies

    pip install -e .

    This installs:

    • openai>=1.60.0 - OpenAI API client
    • fastapi>=0.115.0 - Web framework
    • uvicorn>=0.30.0 - ASGI server
    • httpx>=0.27.0 - HTTP client
    • python-dotenv>=1.0.1 - Environment variables
    • pydantic>=2.7.0 - Data validation
  5. Install optional dependencies (as needed)

    For RAG/Memory features:

    pip install -e ".[rag]"

    Includes: faiss-cpu, sentence-transformers, chromadb

    For development:

    pip install -e ".[dev]"

    Includes: pre-commit, ruff, pytest

  6. Configure environment variables: Copy and paste all from .env.example to .env file

  7. Run the server

    uvicorn src.server.main:app --reload

    Server runs at: http://localhost:8000

Option 2: Using uv (faster, recommended)

# Install uv (one-time)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Clone and setup
git clone https://github.com/nashtech-garage/ntg-python-agent.git
cd ntg-python-agent

# Sync dependencies
uv sync --all-groups

# Run
uv run uvicorn src.server.main:app --reload

Configuration

Environment Variables

Create a .env file in the project root with the following variables:

# Required: your OpenAI API key
OPENAI_API_KEY=sk-proj-xxx

How to obtain an OpenAI API key

Follow these steps to create and obtain an OpenAI API key (secret):

  1. Create an account or sign in at the OpenAI platform:
  2. Verify your email address and finish any required account setup.
  3. Open the API keys page:
  4. Click Create new secret key (or similar). Copy the generated key immediately β€” you won't be able to see it again in full.
  5. Paste the copied key into your project's .env file as the value of OPENAI_API_KEY.

Dependency Groups

The project defines dependencies in pyproject.toml:

Core Dependencies (always installed):

  • openai>=1.60.0 - OpenAI API client for LLM calls
  • fastapi>=0.115.0 - Modern web framework with async support
  • uvicorn>=0.30.0 - ASGI web server
  • httpx>=0.27.0 - Async HTTP client
  • python-dotenv>=1.0.1 - Load environment variables from .env
  • pydantic>=2.7.0 - Data validation and settings management

Optional: RAG Group - For retrieval-augmented generation:

pip install -e ".[rag]"
  • faiss-cpu>=1.8.0 - Vector search library
  • sentence-transformers>=3.0.0 - Embedding models
  • chromadb>=0.5.0 - Vector database

Optional: Dev Group - For development and testing:

pip install -e ".[dev]"
  • pre-commit>=4.5.0 - Git hooks framework
  • ruff>=0.14.8 - Python linter and formatter
  • pytest>=8.3.0 - Testing framework

Project Metadata

  • Name: ntg-python-agent
  • Version: 0.1.0
  • Python Version: >=3.12 (required)
  • License: MIT
  • Repository: github.com/nashtech-garage/ntg-python-agent

Architecture Decisions

This section documents key architectural decisions made in this project.

ADR-001: Modular LLM Provider System

Status: Accepted

Context: Supporting multiple LLM providers (OpenAI, GitHub Models, Gemini) requires flexibility.

Decision: Implement provider abstraction layer with pluggable implementations.

Rationale:

  • Reduces vendor lock-in
  • Allows easy switching between providers
  • Supports cost optimization (choose cheapest provider per task)
  • Enables A/B testing different models

Consequences:

  • βœ… Easy to add new providers
  • βœ… Consistent interface across providers
  • ⚠️ Need to handle provider-specific features gracefully

Implementation: /src/agent/llm.py - Base class for all LLM providers


ADR-002: Async-First Architecture

Status: Accepted

Context: Agent operations are I/O bound (API calls, DB queries, tool invocations).

Decision: Use Python asyncio throughout the codebase.

Rationale:

  • Better resource utilization (non-blocking I/O)
  • Natural fit for FastAPI
  • Handles concurrent requests efficiently
  • Enables real-time streaming responses

Consequences:

  • βœ… High concurrency support
  • βœ… Responsive APIs
  • ⚠️ Requires careful handling of blocking operations

Implementation: All agent methods are async def, FastAPI handles async endpoints


ADR-003: Vector DB for Memory & RAG

Status: Planned

Context: Need efficient semantic search over documents for context retrieval.

Decision: Use ChromaDB as primary vector database with embedding service.

Rationale:

  • Lightweight, in-process option for development
  • Production options available (Pinecone, Weaviate, Milvus)
  • Fast approximate nearest neighbor search
  • Supports metadata filtering

Consequences:

  • βœ… Fast semantic search
  • βœ… Flexible storage options
  • ⚠️ Requires embedding model selection

πŸ“„ License

MIT License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages