Back to .md Directory

PolaperBotV2 - Project Planning

Documents the architecture, tech stack, tools, endpoints, and configuration for a.NET 10 AI assistant bot with Google integration.

May 2, 2026
0 downloads
0 views
ai agent prompt
View source

What this file does

Documents the architecture, tech stack, tools, endpoints, and configuration for a.NET 10 AI assistant bot with Google integration.

When to use it

  • Planning a.NET AI assistant with session persistence and tool integration
  • Setting up a project that uses Microsoft Agent Framework with Ollama
  • Adding Gmail and Calendar capabilities to an AI agent
  • Designing a layered.NET solution with DI separation and background services

Assumes this stack

.NET 10Microsoft Agent FrameworkOllamaSQLiteGoogle APIsOllamaSharp

PolaperBotV2 - Project Planning

Project Overview

Recreation of PolaperBot.Core.AI using the latest Microsoft Agent Framework tools and patterns.

Tech Stack

  • .NET 10 Class Library
  • .NET 10 Minimal API
  • SQLite (Session persistence)
  • Microsoft.Agent.Framework 1.0.0-rc1
  • OllamaSharp 5.4.16
  • Google.Apis.Gmail.v1
  • Google.Apis.Calendar.v3
  • Ollama (gpt-oss:20b-cloud)

Project Structure

PolaperBotV2/
├── PolaperBot.Core.AI/           # Core AI Library (.NET 10)
│   ├── Configuration/
│   │   ├── AgentInstructions.cs  # Agent system prompts
│   │   └── AgentOptions.cs       # Configuration POCOs (Ollama, Google, Database)
│   ├── Extensions/
│   │   ├── ServiceCollectionExtensions.cs  # Main DI entry point
│   │   ├── AgentBuilderExtensions.cs       # Agent-specific DI
│   │   ├── ToolsExtensions.cs              # Tools DI
│   │   └── InstructionsExtensions.cs       # Instructions DI
│   ├── Services/
│   │   ├── AgentService.cs       # Agent orchestration
│   │   └── GoogleServicesFactory.cs  # Google OAuth factory
│   ├── Sessions/
│   │   └── ISessionStore.cs      # Session store interface
│   └── Tools/
│       ├── MemoryTool.cs         # MEMORY.MD tool
│       ├── GmailTool.cs          # Gmail integration
│       ├── GoogleCalendarTool.cs # Calendar integration
│       ├── BashTool.cs           # Shell commands
│       └── FileSystemTool.cs     # File operations
├── PolaperBot.Infra/            # Infrastructure Layer (.NET 10)
│   ├── Extensions/
│   │   └── InfraExtensions.cs   # DI extensions
│   └── Sessions/
│       └── SqliteSessionStore.cs # SQLite session persistence
├── PolaperBot.Api/              # Minimal API (.NET 10)
│   ├── credentials/             # Google credentials folder
│   ├── Program.cs
│   ├── appsettings.json
│   └── Endpoints/
│       └── ChatEndpoints.cs     # Chat endpoints
├── MEMORY.MD                    # This file
└── PolaperBot.slnx

NuGet Packages

ProjectPackageVersion
Core.AIMicrosoft.Agents.AI1.0.0-rc1
Core.AIMicrosoft.Extensions.AI10.3.0
Core.AIMicrosoft.Extensions.Configuration.Abstractions10.0.3
Core.AIMicrosoft.Extensions.DependencyInjection.Abstractions10.0.3
Core.AIOllamaSharp5.4.16
Core.AIGoogle.Apis.Calendar.v31.69.0.3667
Core.AIGoogle.Apis.Gmail.v11.69.0.3742
InfraMicrosoft.Agents.AI1.0.0-rc1
InfraMicrosoft.Data.Sqlite10.0.2
ApiMicrosoft.AspNetCore.OpenApi10.0.2

AI Tools Available

MemoryTool

  • SaveToMemory(data) - Save important data to MEMORY.MD
  • ReadMemory() - Read stored memory

GmailTool

  • SendEmail(destinatario, asunto, contenido) - Send email
  • SummarizeEmailsByDate(fecha) - Get email summary by date

GoogleCalendarTool

  • GetCurrentDateTime() - Get current date/time context
  • CreateEvent(titulo, descripcion, fechaInicio, fechaFin, ubicacion) - Create event
  • GetUpcomingEvents(maxResultados) - List upcoming events
  • GetEventsByDate(fecha) - Get events by date
  • DeleteEvent(eventoId) - Delete event

BashTool (Shell Access)

  • ExecuteCommand(command) - Execute shell/bash commands
  • GetSystemInfo() - Get OS, user, hostname, drives info

FileSystemTool (Full Permissions)

  • ReadFile(filePath) - Read file contents
  • WriteFile(filePath, content) - Create/overwrite files
  • AppendToFile(filePath, content) - Append to files
  • ListDirectory(directoryPath) - List files and directories
  • CreateDirectory(directoryPath) - Create directories
  • DeleteFile(filePath) - Delete files
  • DeleteDirectory(directoryPath) - Delete directories
  • CopyFile(sourcePath, destinationPath) - Copy files
  • Move(sourcePath, destinationPath) - Move/rename files
  • Exists(path) - Check if file/directory exists
  • SearchFiles(pattern, directoryPath) - Search files by pattern

Implementation Tasks

#TaskStatus
1Create solution + project structure
2Implement ISessionStore interface
3Create MemoryTool for MEMORY.MD operations
4Build DI extensions
5Configure Ollama provider using OllamaSharp
6Create API endpoints
7Add SQLite session persistence
8Implement ChatReduction with MessageCountingChatReducer(20)
9Add Gmail integration
10Add Google Calendar integration
11Create GoogleServicesFactory with OAuth
12Add BashTool for shell commands
13Add FileSystemTool for file operations
14Refactor tools to use proper DI
15Add Usage tracking for observability
16Add HeartbeatService with configurable triggers

Key Design Decisions

  1. Layered Architecture: Core.AI (abstractions) → Infra (implementations) → Api
  2. SQLite Session Persistence: Sessions serialized to JSON and stored in SQLite
  3. Chat Reduction: InMemoryChatHistoryProvider with 20-message limit
  4. DI Separation: Each layer has its own extension methods
  5. Graceful Degradation: Tools disabled when Google credentials missing
  6. Factory Pattern: GoogleServicesFactory handles OAuth and service creation
  7. Full System Access: BashTool and FileSystemTool with complete permissions
  8. Usage Tracking: Processing time stored for observability (not retrieved on load)
  9. Heartbeat Service: Background service with configurable triggers (GmailHbs, RemindersHbs)

Heartbeat Service

Configurable background service that executes triggers at specified intervals:

{
  "Heartbeat": {
    "Enabled": true,
    "IntervalMinutes": 5,
    "EnabledTriggers": ["GmailHbs", "RemindersHbs"]
  }
}

Available triggers:

  • GmailHbs - Gmail heartbeat trigger (placeholder)
  • RemindersHbs - Reminders heartbeat trigger (placeholder)

To add new triggers, implement IHeartbeatTrigger interface and register in DI.

API Endpoints

POST /api/chat

{ "userId": 123456789, "message": "Hola" }
→ { "response": "¡Hola!" }

POST /api/chat/human (Local Testing)

{ "message": "Hola" }
→ { "response": "¡Hola!" }
  • Fixed session ID: 999999
  • Persists across server restarts via SQLite

GET /api/chat/health

→ "PolaperBot API is running"

Configuration

{
  "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
  },
  "Agent": { "Name": "HanniAssistant", "MemoryPath": "./MEMORY.MD" }
}

Session Persistence

Sessions are stored in SQLite with this schema:

CREATE TABLE Sessions (
    UserId INTEGER PRIMARY KEY,
    SessionJson TEXT NOT NULL,
    UsageJson TEXT,
    UpdatedAt TEXT NOT NULL
)
  • LoadOrCreateAsync(userId): Loads session from DB or creates new
  • SaveAsync(userId, session, usage): Serializes and saves session with usage metrics

Session Usage Tracking

Usage is stored for observability/metrics (not retrieved when loading sessions):

public class SessionUsage
{
    public int InputTokens { get; set; }
    public int OutputTokens { get; set; }
    public string? Model { get; set; }
    public double ProcessingTimeMs { get; set; }
    public int ToolCalls { get; set; }
    public DateTime Timestamp { get; set; }
}

Usage is captured automatically after each message and stored in UsageJson column.

Google Integration Setup

  1. Create Google Cloud project
  2. Enable Gmail API and Calendar API
  3. Create OAuth 2.0 credentials (Desktop app)
  4. Download JSON to credentials/google_credentials.json
  5. First run triggers OAuth authorization flow

Last updated: 2026-02-25

What's inside

16 sections covering project structure, tech stack, 5 AI tools, 16 implementation tasks, 9 design decisions, API endpoints, and configuration

Change this for your project

  • Replace "Model": "gpt-oss:20b-cloud" with your Ollama model name
  • Replace "CredentialsPath": "./credentials/google_credentials.json" with your Google credentials path
  • Replace "Name": "HanniAssistant" with your agent name
  • Replace "MemoryPath": "./MEMORY.MD" with your memory file path

Where it goes

Keep it in your repository where the agent or team that needs it will read it.

Worth borrowing

  • Layered architecture with Core.AI, Infra, and Api projects for separation of concerns
  • DI extension methods per layer to keep composition root clean
  • Graceful degradation when external services (Google) are unavailable

Related Documents