PolaperBotV2 - Project Planning
Documents the architecture, tech stack, tools, endpoints, and configuration for a.NET 10 AI assistant bot with Google integration.
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
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
| Project | Package | Version |
|---|---|---|
| Core.AI | Microsoft.Agents.AI | 1.0.0-rc1 |
| Core.AI | Microsoft.Extensions.AI | 10.3.0 |
| Core.AI | Microsoft.Extensions.Configuration.Abstractions | 10.0.3 |
| Core.AI | Microsoft.Extensions.DependencyInjection.Abstractions | 10.0.3 |
| Core.AI | OllamaSharp | 5.4.16 |
| Core.AI | Google.Apis.Calendar.v3 | 1.69.0.3667 |
| Core.AI | Google.Apis.Gmail.v1 | 1.69.0.3742 |
| Infra | Microsoft.Agents.AI | 1.0.0-rc1 |
| Infra | Microsoft.Data.Sqlite | 10.0.2 |
| Api | Microsoft.AspNetCore.OpenApi | 10.0.2 |
AI Tools Available
MemoryTool
SaveToMemory(data)- Save important data to MEMORY.MDReadMemory()- Read stored memory
GmailTool
SendEmail(destinatario, asunto, contenido)- Send emailSummarizeEmailsByDate(fecha)- Get email summary by date
GoogleCalendarTool
GetCurrentDateTime()- Get current date/time contextCreateEvent(titulo, descripcion, fechaInicio, fechaFin, ubicacion)- Create eventGetUpcomingEvents(maxResultados)- List upcoming eventsGetEventsByDate(fecha)- Get events by dateDeleteEvent(eventoId)- Delete event
BashTool (Shell Access)
ExecuteCommand(command)- Execute shell/bash commandsGetSystemInfo()- Get OS, user, hostname, drives info
FileSystemTool (Full Permissions)
ReadFile(filePath)- Read file contentsWriteFile(filePath, content)- Create/overwrite filesAppendToFile(filePath, content)- Append to filesListDirectory(directoryPath)- List files and directoriesCreateDirectory(directoryPath)- Create directoriesDeleteFile(filePath)- Delete filesDeleteDirectory(directoryPath)- Delete directoriesCopyFile(sourcePath, destinationPath)- Copy filesMove(sourcePath, destinationPath)- Move/rename filesExists(path)- Check if file/directory existsSearchFiles(pattern, directoryPath)- Search files by pattern
Implementation Tasks
| # | Task | Status |
|---|---|---|
| 1 | Create solution + project structure | ✅ |
| 2 | Implement ISessionStore interface | ✅ |
| 3 | Create MemoryTool for MEMORY.MD operations | ✅ |
| 4 | Build DI extensions | ✅ |
| 5 | Configure Ollama provider using OllamaSharp | ✅ |
| 6 | Create API endpoints | ✅ |
| 7 | Add SQLite session persistence | ✅ |
| 8 | Implement ChatReduction with MessageCountingChatReducer(20) | ✅ |
| 9 | Add Gmail integration | ✅ |
| 10 | Add Google Calendar integration | ✅ |
| 11 | Create GoogleServicesFactory with OAuth | ✅ |
| 12 | Add BashTool for shell commands | ✅ |
| 13 | Add FileSystemTool for file operations | ✅ |
| 14 | Refactor tools to use proper DI | ✅ |
| 15 | Add Usage tracking for observability | ✅ |
| 16 | Add HeartbeatService with configurable triggers | ✅ |
Key Design Decisions
- Layered Architecture: Core.AI (abstractions) → Infra (implementations) → Api
- SQLite Session Persistence: Sessions serialized to JSON and stored in SQLite
- Chat Reduction:
InMemoryChatHistoryProviderwith 20-message limit - DI Separation: Each layer has its own extension methods
- Graceful Degradation: Tools disabled when Google credentials missing
- Factory Pattern:
GoogleServicesFactoryhandles OAuth and service creation - Full System Access: BashTool and FileSystemTool with complete permissions
- Usage Tracking: Processing time stored for observability (not retrieved on load)
- 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 newSaveAsync(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
- Create Google Cloud project
- Enable Gmail API and Calendar API
- Create OAuth 2.0 credentials (Desktop app)
- Download JSON to
credentials/google_credentials.json - 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
Zig 0.16.0 Context Document for LLMs
Documents breaking changes from Zig 0.13/0.14 to 0.16.0, covering syntax, I/O, build system, and standard library updates.
Beads Workflow Context
Guides when to use bd graph-based issue tracker versus TodoWrite for session vs multi-session work, with commands and workflows.
TreeDex — Comprehensive Documentation
Documents the architecture, API, and internals of a tree-based, vectorless RAG framework available in Python and Node.js.
每日安全资讯(2023-08-05)
Aggregates daily security news from multiple RSS feeds into a single Markdown page for quick scanning.