Skip to content

techbuzzz/Hercules

Repository files navigation

Hercules

Self-improving AI agent on C# / .NET 10
Creates skills from experience Β· improves them during use Β· remembers context between sessions

.NET C# Astro License Status

English Β· Русский


Hercules is a compact self-improving micro-agent that reproduces the key self-improving characteristics of "hermes-style" agents (Nous Research) in a runnable form factor.

The agent creates skills from experience, improves them during use, retains knowledge across sessions, and builds a deepening model of the user. It supports YandexGPT, Ollama Cloud, and Ollama Local through a single OpenAI-compatible interface (Microsoft.Extensions.AI).

This is the default landing page (English). For the Russian version, see README-RU.md.


✨ Features

Subsystem What it does
Self-Improving Skill System Automatically proposes creating a skill on repeated queries (>2 times), versions skills, and improves them when success rate is low
Long-term Memory Stores user profile, preferences, entities, and session context in Markdown; carries context across restarts
Reflection Engine Self-analysis after a session or every N commands β€” what went well / poorly / what to improve
Skill Router Query routing: skill by triggers or direct LLM response
Hybrid Storage Files (Markdown + JSON) for skills and memory + SQLite for logs and metrics
Multi-provider LLM YandexGPT (primary), Ollama Cloud / Local, LM Studio β€” through a single OpenAI-compatible interface with automatic fallback
Interfaces CLI (REPL, primary) + Telegram bot (secondary)

πŸ—οΈ Architecture

Hercules/
β”œβ”€β”€ Program.cs                 # Entry point, DI and configuration setup
β”œβ”€β”€ appsettings.json           # Provider and agent thresholds configuration
β”œβ”€β”€ Config/
β”‚   └── AppConfig.cs           # Configuration models
β”œβ”€β”€ Agent/                     # Agent core
β”‚   β”œβ”€β”€ AgentCore.cs           # Main request-processing loop
β”‚   β”œβ”€β”€ SkillRouter.cs         # Skill-based routing (triggers)
β”‚   β”œβ”€β”€ SkillManager.cs        # Skill CRUD + versioning (via LLM)
β”‚   β”œβ”€β”€ ReflectionEngine.cs    # Self-analysis, reflection reports
β”‚   └── MemoryManager.cs       # Long-term memory, user model
β”œβ”€β”€ LLM/                       # LLM layer (Microsoft.Extensions.AI)
β”‚   β”œβ”€β”€ ILLMClient.cs          # Unified provider interface
β”‚   β”œβ”€β”€ ChatClientLLMClient.cs # Base over IChatClient
β”‚   β”œβ”€β”€ YandexGPTClient.cs     # YandexGPT (OpenAI-compatible endpoint)
β”‚   β”œβ”€β”€ LocalLLMClient.cs      # Ollama Cloud/Local, LM Studio
β”‚   β”œβ”€β”€ LlmClientFactory.cs    # Client factory by provider name
β”‚   └── ResilientLLMClient.cs  # Resilience + fallback chain
β”œβ”€β”€ Storage/                   # Storage
β”‚   β”œβ”€β”€ FileSkillRepository.cs # Skills/ β€” skill files
β”‚   β”œβ”€β”€ MemoryStore.cs         # Memory/ β€” Markdown memory
β”‚   β”œβ”€β”€ SqliteSessionStore.cs  # SQLite: sessions, logs, metrics, counters
β”‚   └── Models.cs              # Domain models (Skill, SkillMeta, ...)
β”œβ”€β”€ CLI/
β”‚   └── ConsoleUI.cs           # REPL loop (Spectre.Console)
β”œβ”€β”€ Telegram/
β”‚   └── TelegramBot.cs         # Telegram bot (long polling)
└── Agent/WebApiAdapter.cs     # Core adapter for Web API + DTO

Additional "faΓ§ade" projects on top of the core:

Hercules.WebApi/            # ASP.NET Core Minimal API (REST), port :5000
β”œβ”€β”€ Program.cs                 # DI + CORS + middleware, reuses the core
β”œβ”€β”€ Auth/ApiKeyMiddleware.cs   # X-Api-Key header validation
β”œβ”€β”€ Config/WebApiConfig.cs     # API key + allowed CORS origins
└── Controllers/               # Chat / Skills / Memory / Stats (Minimal API)

hercules-web/                    # Astro + TailwindCSS frontend, port :4321
β”œβ”€β”€ src/lib/api.ts             # Web API client
β”œβ”€β”€ src/layouts/Layout.astro   # Base layout (dark theme, navigation)
β”œβ”€β”€ src/components/            # ChatBox, SkillCard, ProfileEditor, StatsDashboard
└── src/pages/                 # index / skills / profile / stats

All runtime data goes into the data/ directory:

data/
β”œβ”€β”€ Skills/                    # skill.{id}.md / .prompt.md / .meta.json / .usage.json / .v{N}.md
β”œβ”€β”€ Memory/                    # user_profile.md, preferences.md, entities.md, context_{date}.md
└── sessions.db                # SQLite: sessions, interactions, metrics

πŸš€ Installation and Run

Requirements

Build

cd Hercules
dotnet restore
dotnet build

Run CLI (primary mode)

dotnet run

Run Telegram bot

dotnet run -- --telegram

(set Telegram:BotToken in appsettings.json beforehand)

Run Web API (REST server)

# from repository root
dotnet run --project Hercules.WebApi

The server starts on http://localhost:5000. The agent core (AgentCore) is reused through the WebApiAdapter adapter β€” there is no separate agent logic in the Web API.

Run CLI via the main project

dotnet run --project Hercules -- --cli   # REPL mode
dotnet run --project Hercules            # same thing (CLI by default)

🌐 Web API

ASP.NET Core Minimal API. All responses are JSON (UTF-8, camelCase). Protection is the X-Api-Key header (value from WebApi:ApiKey, default dev-local-key). CORS is open for the local frontend (http://localhost:4321, http://localhost:3000). Every interaction is logged in SQLite (data/sessions.db).

Method Route Description
GET /api/health Liveness check (no key required)
POST /api/chat Send a message to the agent β†’ response + mode/confidence/skill
GET /api/skills List skills
POST /api/skills Create a skill manually; ?ai=true β€” generate via LLM
GET /api/skills/{id} Skill details (metadata + prompt)
PUT /api/skills/{id} Update a skill (triggers/prompt/description) β†’ new version
POST /api/skills/{id}/improve Improve a skill via LLM β†’ new version
GET /api/memory/profile Long-term memory profile (Markdown)
PUT /api/memory/profile Overwrite the memory profile
POST /api/memory/reset Reset long-term memory
GET /api/reflect Run reflection β†’ Markdown report
GET /api/stats Metrics: total, skill/direct, success rate, per-day

Example:

curl -X POST http://localhost:5000/api/chat \
  -H "X-Api-Key: dev-local-key" -H "Content-Type: application/json" \
  -d '{"message":"what is the weather in Moscow?"}'

Web API configuration (Hercules.WebApi/appsettings.json):

"WebApi": {
  "ApiKey": "dev-local-key",                  // empty string β†’ no-key access
  "AllowedCorsOrigins": [ "http://localhost:4321", "http://localhost:3000" ]
}

🎨 Web Interface (Astro)

Minimalist SPA on Astro + TailwindCSS (dark theme, monospaced code blocks). Located in the hercules-web/ directory.

Page Purpose
/ Chat with the agent (mode/confidence/provider badges, typing effect, skill hints)
/skills Skill list, manual creation and AI improvement, editing
/profile Long-term memory profile editor + reset
/stats Metrics dashboard, skill/direct ratio, daily activity, reflection

Components: ChatBox, SkillCard, ProfileEditor, StatsDashboard. API client β€” src/lib/api.ts.

Run the frontend

cd hercules-web
npm install
npm run dev        # dev server on http://localhost:4321

The backend address and key are configured via environment variables (hercules-web/.env file):

PUBLIC_API_BASE=http://localhost:5000
PUBLIC_API_KEY=dev-local-key

Full local run (two terminals)

# Terminal 1 β€” backend
dotnet run --project Hercules.WebApi      # β†’ :5000

# Terminal 2 β€” frontend
cd hercules-web && npm run dev                  # β†’ :4321

Open http://localhost:4321.


βš™οΈ Configuration (appsettings.json)

{
  "Llm": {
    "Provider": "yandexgpt",                 // active provider
    "Fallback": ["ollama-cloud", "ollama-local"], // fallback order
    "YandexGpt": {
      "Endpoint": "https://llm.api.cloud.yandex.net/v1",
      "ApiKey": "<IAM or API key>",
      "FolderId": "<Yandex Cloud folder id>",
      "Model": "yandexgpt",                  // becomes gpt://{folderId}/yandexgpt/latest
      "Temperature": 0.6,
      "MaxTokens": 2000
    },
    "OllamaCloud": {
      "Endpoint": "https://ollama.com/v1",
      "ApiKey": "<Ollama Cloud key>",
      "Model": "gpt-oss:120b"
    },
    "OllamaLocal": {
      "Endpoint": "http://localhost:11434/v1",
      "ApiKey": "",                          // no key required locally
      "Model": "llama3.1"
    }
  },
  "Agent": {
    "SkillCreationThreshold": 3,             // repetitions before proposing a skill
    "SkillImprovementThreshold": 0.6,        // success_rate threshold for improvement
    "SkillEvaluationWindow": 5,              // skill evaluation window
    "ReflectionEveryNCommands": 10           // auto-reflection every N commands
  },
  "Telegram": { "Enabled": false, "BotToken": "" }
}

Any setting can be overridden via environment variables with the HERCULES_ prefix, for example: HERCULES_Llm__Provider=ollama-local.

LLM Providers

All providers work through an OpenAI-compatible interface and the Microsoft.Extensions.AI abstraction (IChatClient). Supported providers:

  • YandexGPT β€” primary (Russia). The model is passed as gpt://{folderId}/{model}/latest.
  • Ollama Cloud β€” cloud fallback (https://ollama.com/v1).
  • Ollama Local / LM Studio β€” local fallback (http://localhost:11434/v1).

If the primary provider is unavailable, ResilientLLMClient automatically switches to the next one in the Fallback list.


πŸ’» CLI Commands

Command Description
> text Direct query to LLM with profile context
/skills Show all skills (table)
/skills create "name" Create a skill manually
/skills improve {id} Improve a skill (new version)
/memory show Show user profile
/memory reset Reset memory
/reflect Run reflection manually
/help Help
/exit Exit with context saving and final reflection

πŸ€– Telegram Commands

  • /start β€” initialization
  • /skills β€” list of skills
  • /profile β€” what the agent knows about the user
  • /reset β€” reset memory
  • plain text β€” agent response

πŸ”„ How the self-improving cycle works

  1. Request β†’ load profile and context from memory
  2. Routing β†’ find a matching skill by triggers (SkillRouter)
  3. LLM response β†’ with the active skill (skill-prompt) or directly (direct)
  4. Logging β†’ input/output/confidence/mode in SQLite
  5. Skill threshold β†’ if the request has been repeated SkillCreationThreshold times β†’ propose creating a skill (with confirmation)
  6. Improvement threshold β†’ if success_rate < SkillImprovementThreshold β†’ propose updating the skill
  7. Memory saving β†’ facts about the user, entities, preferences
  8. Reflection β†’ at the end of a session or every N commands

Principles

  • Never stop learning β€” every session enriches memory or skills
  • Explicit improvement loop β€” the agent itself proposes fixes
  • Transparent β€” the user sees all creations/improvements
  • Human-in-the-loop β€” skills are created only after confirmation
  • Versioned β€” old skill versions are not deleted (skill.{id}.v{N}.md)

πŸ§ͺ Acceptance Criteria Check

Criterion How to verify
A skill is created automatically Repeat the same query 3 times β†’ the agent proposes a skill
A skill is used After creation β€” the query goes through skill: ...
A skill improves After a series of bad responses β†’ a proposal to update
Profile is saved Restart β†’ /memory show remembers facts
Context is carried over Session 1: fact β†’ Session 2: agent remembers
Reflection runs After /exit β€” Reflection Engine output

πŸ“¦ Dependencies (NuGet)

  • Microsoft.Extensions.AI + Microsoft.Extensions.AI.OpenAI β€” AI abstractions
  • OpenAI β€” OpenAI-compatible SDK (YandexGPT, Ollama)
  • Microsoft.Data.Sqlite β€” SQLite
  • YamlDotNet β€” metadata parsing
  • Spectre.Console β€” improved CLI
  • Telegram.Bot β€” Telegram interface
  • Microsoft.Extensions.Hosting / Configuration.Json β€” DI and configuration

πŸ“š Documentation

All documents are available in two languages. The default links point to the English version.

Document Description
docs/QUICKSTART-EN.md Β· RU Quick start in a few minutes
docs/ARCHITECTURE-EN.md Β· RU Core and interface architecture
docs/AGENT-MESH-EN.md Β· RU Micro-agent mesh concept
docs/IOT-SCENARIOS-EN.md Β· RU B2C/B2B IoT deployment scenarios
docs/ROADMAP-EN.md Β· RU Planned features and milestones
docs/CONFIGURATION-EN.md Β· RU Full settings reference
docs/API-EN.md Β· RU REST Web API reference
CONTRIBUTING-EN.md Β· RU How to contribute
CHANGELOG-EN.md Β· RU Change history
SECURITY.md Security policy
CODE_OF_CONDUCT.md Code of conduct

🀝 Contributing

PRs and Issues are welcome! Before starting, please read CONTRIBUTING-EN.md and CODE_OF_CONDUCT.md. Report vulnerabilities via SECURITY.md.


πŸ“ License

MIT Β© 2026 Victor Buzin.

About

Hercules is a compact self-improving micro-agent that reproduces the key self-improving characteristics of "hermes-style" agents (Nous Research) in a runnable form factor.

Topics

Resources

License

Code of conduct

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages