A modern AI Agent framework implementation using Microsoft Agent Framework, Ollama, and .NET 10
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.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 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 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| 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 |
- 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
ExecuteCommand- Execute any shell/bash commandGetSystemInfo- Get OS, user, hostname, drives info- Full system permissions (Linux/Mac bash, Windows PowerShell)
ReadFile- Read file contentsWriteFile- Create/overwrite filesAppendToFile- Append content to filesListDirectory- List files and directoriesCreateDirectory- Create new directoriesDeleteFile/DeleteDirectory- Remove files/foldersCopyFile/Move- Copy or move filesExists- Check if file/directory existsSearchFiles- Search files by pattern
SendEmail- Send emails through GmailSummarizeEmailsByDate- Get email summaries for a specific date
GetCurrentDateTime- Get current date/time contextCreateEvent- Create new calendar eventsGetUpcomingEvents- List upcoming eventsGetEventsByDate- Get events for a specific dateDeleteEvent- Delete calendar events by ID
- SQLite-backed session storage
- JSON serialization of conversation state
- Automatic table creation on startup
- Session recovery across server restarts
MessageCountingChatReducerlimits context to 20 messages- Prevents token overflow in long conversations
- Managed via
InMemoryChatHistoryProvider
// 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");| 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 |
curl -X POST http://localhost:5057/api/chat/human \
-H "Content-Type: application/json" \
-d '{"message": "Hola, ΒΏquiΓ©n eres?"}'{
"response": "Β‘Hola! Soy HANNI, tu asistente personal."
}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
| 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 |
- .NET 10 SDK
- Ollama running locally with a model
- (Optional) Google Cloud credentials for Gmail/Calendar
# Clone and navigate
cd PolaperBotV2
# Run the API
dotnet run --project PolaperBot.Api- Go to Google Cloud Console
- Create a project and enable Gmail API and Calendar API
- Create OAuth 2.0 credentials (Desktop app)
- Download credentials JSON
- Save to
PolaperBot.Api/credentials/google_credentials.json - First run will open browser for OAuth authorization
{
"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
}
}- β 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
MIT License
Built with β€οΈ using .NET 10 and Microsoft Agent Framework