Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

15 Commits

Folders and files

Repository files navigation

PolaperBot V2 πŸ€–

A modern AI Agent framework implementation using Microsoft Agent Framework, Ollama, and .NET 10

Overview

PolaperBot V2 is a conversational AI assistant built with clean architecture principles and modern .NET patterns. It demonstrates professional-grade implementation of AI agents with persistent sessions, dependency injection, and layered architecture.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      PolaperBot.Api                         β”‚
β”‚              (Minimal API - Presentation Layer)              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   PolaperBot.Core.AI                        β”‚
β”‚            (Domain Layer - Abstractions & Logic)            β”‚
β”‚                                                             β”‚
β”‚  β€’ ISessionStore      β€’ IAgentService                       β”‚
β”‚  β€’ MemoryTool         β€’ GmailTool                           β”‚
β”‚  β€’ GoogleCalendarTool β€’ BashTool                            β”‚
β”‚  β€’ FileSystemTool     β€’ AgentInstructions                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    PolaperBot.Infra                         β”‚
β”‚           (Infrastructure Layer - Implementations)          β”‚
β”‚                                                             β”‚
β”‚  β€’ SqliteSessionStore                                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Tech Stack

Category Technology
Framework .NET 10
AI Framework Microsoft Agent Framework 1.0.0-rc1
LLM Provider Ollama (via OllamaSharp)
Database SQLite
API Style Minimal API
Architecture Clean Architecture / Onion Architecture
DI Pattern Extension Methods per Layer
Integrations Gmail API, Google Calendar API, Shell, FileSystem

Key Features

🧠 AI Agent with Tools

  • MemoryTool - Persistent memory storage in MEMORY.MD
  • GmailTool - Send emails, summarize emails by date
  • GoogleCalendarTool - Create, update, delete, and list calendar events
  • BashTool - Execute shell commands with full system access
  • FileSystemTool - Full file system operations (read, write, delete, etc.)
  • Extensible tool system via AITool[] registration
  • Natural language processing in Spanish

πŸ’» Shell Access (BashTool)

  • ExecuteCommand - Execute any shell/bash command
  • GetSystemInfo - Get OS, user, hostname, drives info
  • Full system permissions (Linux/Mac bash, Windows PowerShell)

πŸ“ File System (FileSystemTool)

  • ReadFile - Read file contents
  • WriteFile - Create/overwrite files
  • AppendToFile - Append content to files
  • ListDirectory - List files and directories
  • CreateDirectory - Create new directories
  • DeleteFile / DeleteDirectory - Remove files/folders
  • CopyFile / Move - Copy or move files
  • Exists - Check if file/directory exists
  • SearchFiles - Search files by pattern

πŸ“§ Gmail Integration

  • SendEmail - Send emails through Gmail
  • SummarizeEmailsByDate - Get email summaries for a specific date

πŸ“… Google Calendar Integration

  • GetCurrentDateTime - Get current date/time context
  • CreateEvent - Create new calendar events
  • GetUpcomingEvents - List upcoming events
  • GetEventsByDate - Get events for a specific date
  • DeleteEvent - Delete calendar events by ID

πŸ’Ύ Session Persistence

  • SQLite-backed session storage
  • JSON serialization of conversation state
  • Automatic table creation on startup
  • Session recovery across server restarts

πŸ“‰ Context Management

  • MessageCountingChatReducer limits context to 20 messages
  • Prevents token overflow in long conversations
  • Managed via InMemoryChatHistoryProvider

πŸ”Œ Clean DI Setup

// Program.cs - Clean and declarative
builder.Services.AddCoreAiAgent(
    ollama => 
    {
        ollama.Endpoint = "http://localhost:11434";
        ollama.Model = "gpt-oss:20b-cloud";
    },
    google => 
    {
        google.CredentialsPath = "./credentials/google_credentials.json";
        google.TokenFolder = "./credentials/google_token";
        google.EnableGmail = true;
        google.EnableCalendar = true;
    });

builder.Services.AddSqliteSessionStore("sessions.db");

API Endpoints

Method Endpoint Description
POST /api/chat Send message with custom userId
POST /api/chat/human Test endpoint (fixed session)
GET /api/chat/health Health check

Example Request

curl -X POST http://localhost:5057/api/chat/human \
  -H "Content-Type: application/json" \
  -d '{"message": "Hola, ΒΏquiΓ©n eres?"}'

Example Response

{
  "response": "Β‘Hola! Soy HANNI, tu asistente personal."
}

Project Structure

PolaperBotV2/
β”œβ”€β”€ PolaperBot.Core.AI/                 # Core domain library
β”‚   β”œβ”€β”€ Configuration/
β”‚   β”‚   β”œβ”€β”€ AgentInstructions.cs        # System prompts
β”‚   β”‚   └── AgentOptions.cs             # Configuration POCOs
β”‚   β”œβ”€β”€ Extensions/
β”‚   β”‚   β”œβ”€β”€ AgentBuilderExtensions.cs   # Agent DI setup
β”‚   β”‚   β”œβ”€β”€ InstructionsExtensions.cs   # Instructions DI
β”‚   β”‚   └── ToolsExtensions.cs          # Tools DI
β”‚   β”œβ”€β”€ Services/
β”‚   β”‚   β”œβ”€β”€ AgentService.cs             # Agent orchestration
β”‚   β”‚   └── GoogleServicesFactory.cs    # Google OAuth factory
β”‚   β”œβ”€β”€ Sessions/
β”‚   β”‚   └── ISessionStore.cs            # Session abstraction
β”‚   └── Tools/
β”‚       β”œβ”€β”€ MemoryTool.cs               # Memory persistence
β”‚       β”œβ”€β”€ GmailTool.cs                # Gmail integration
β”‚       β”œβ”€β”€ GoogleCalendarTool.cs       # Calendar integration
β”‚       β”œβ”€β”€ BashTool.cs                 # Shell commands
β”‚       └── FileSystemTool.cs           # File operations
β”‚
β”œβ”€β”€ PolaperBot.Infra/                   # Infrastructure layer
β”‚   β”œβ”€β”€ Extensions/
β”‚   β”‚   └── InfraExtensions.cs          # Infra DI setup
β”‚   └── Sessions/
β”‚       └── SqliteSessionStore.cs       # SQLite implementation
β”‚
β”œβ”€β”€ PolaperBot.Api/                     # API layer
β”‚   β”œβ”€β”€ credentials/                    # Google credentials folder
β”‚   β”œβ”€β”€ Endpoints/
β”‚   β”‚   └── ChatEndpoints.cs            # Endpoint definitions
β”‚   β”œβ”€β”€ Program.cs                      # App entry point
β”‚   └── appsettings.json                # Configuration
β”‚
└── MEMORY.MD                           # Project documentation

Design Patterns Used

Pattern Application
Dependency Injection All services registered via DI containers
Repository Pattern ISessionStore abstracts data access
Extension Methods Clean service registration per layer
Options Pattern OllamaOptions, GoogleOptions, AgentOptions
Factory Pattern GoogleServicesFactory for OAuth, BuildAgentTools() for tools
Graceful Degradation Tools disabled when credentials missing

Getting Started

Prerequisites

  • .NET 10 SDK
  • Ollama running locally with a model
  • (Optional) Google Cloud credentials for Gmail/Calendar

Run

# Clone and navigate
cd PolaperBotV2

# Run the API
dotnet run --project PolaperBot.Api

Google Integration Setup (Optional)

  1. Go to Google Cloud Console
  2. Create a project and enable Gmail API and Calendar API
  3. Create OAuth 2.0 credentials (Desktop app)
  4. Download credentials JSON
  5. Save to PolaperBot.Api/credentials/google_credentials.json
  6. First run will open browser for OAuth authorization

Configuration (appsettings.json)

{
  "Database": {
    "SqlitePath": "sessions.db"
  },
  "Ollama": {
    "Endpoint": "http://localhost:11434",
    "Model": "gpt-oss:20b-cloud"
  },
  "Google": {
    "CredentialsPath": "./credentials/google_credentials.json",
    "TokenFolder": "./credentials/google_token",
    "EnableGmail": true,
    "EnableCalendar": true
  }
}

Skills Demonstrated

  • βœ… Clean Architecture - Separation of concerns across layers
  • βœ… Modern .NET - .NET 10 with Minimal APIs
  • βœ… AI Integration - Microsoft Agent Framework & Ollama
  • βœ… External APIs - Gmail API & Google Calendar API integration
  • βœ… OAuth 2.0 - Google authentication flow
  • βœ… Shell Access - Execute system commands safely
  • βœ… File System - Full CRUD operations on files/folders
  • βœ… Persistence - SQLite with async operations
  • βœ… DI Best Practices - Extension methods for clean registration
  • βœ… Async/Await - Non-blocking I/O throughout
  • βœ… JSON Serialization - Session state persistence
  • βœ… Error Handling - Graceful fallbacks for missing credentials
  • βœ… Tool System - Extensible AI function calling

License

MIT License


Built with ❀️ using .NET 10 and Microsoft Agent Framework

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages