PTENES
MODULE 1.2

๐Ÿ— Overall Architecture

How the 5 components connect, the complete flow of a message from Telegram to the response, and the workspace system that configures everything.

6
Topics
60
Minutes
Basic
Level
Diagram
Type
1

๐Ÿ”„ The 5 Core Components

INTELECTO has exactly 5 distinct responsibilities. This division isn't arbitraryโ€”each component can be replaced, tested, and evolved independently of the others. That's the secret to keeping the system manageable.

๐Ÿงฉ The 5 Components

๐Ÿค–
Agent

The brain. Receives messages, builds context, decides whether to use tools or respond directly, and orchestrates everything.

๐Ÿ”ฎ
Providers

Access to LLMs. OpenRouter, Ollama, direct API. Any implementation of BaseProvider will work.

๐Ÿ“ก
Channels

How the user communicates. Telegram, WhatsApp, Discord, CLI. Implement BaseChannel.

๐Ÿง 
Memory

Context persistence. SQLite FTS5 with BM25 semantic search and automatic deduplication.

๐Ÿ”ง
Tools

Real-world actions. Google Calendar, GitHub, browser, shell. Implement BaseTool.

2

๐Ÿ“จ Complete Message Flow

Each message follows a precise path. Understanding this flow is essential to knowing where to intervene when something fails and where to add new features.

๐Ÿ“Š Flow Diagram

U
User types a message in Telegram
โ†“
CH
Channel.receive() โ†’ normalizes to internal format
โ†“
S
Safety.check() โ†’ validates against the blocklist and injection
โ†“
AG
Agent.loop() โ†’ builds context with workspace + memory
โ†“
PR
Provider.chat() โ†’ sends to LLM, receives response
โ†“ (if tool_call)
TL
Tool.execute() โ†’ performs an action, returns a result
โ†“ (up to max 5 rounds)
ME
Memory.store() โ†’ persists relevant facts
โ†“
CH
Channel.send() โ†’ sends response to Telegram
โ†“
U
User receives the response

๐Ÿ’ก Practical Tip

To debug, add logs at every step of the flow. Python logging with different levels (DEBUG for Channel, INFO for Agent, WARNING for Safety) lets you pinpoint exactly where the problem occurs.

3

๐Ÿ” The Agent Loop โ€” Max 5 Rounds

O loop.py is the heart of INTELECTO. It implements the ReAct pattern (Reason + Act): the AI thinks, decides to use a tool, receives the result, thinks again, and so onโ€”until it reaches a final answer or hits the 5-round limit.

๐Ÿ”„ The ReAct Cycle

R
Reason

LLM analyzes the message + context and decides what to do

โ†“
A
Act (Take Action)

If you decide to use a tool โ†’ call tool.execute() with the parameters

โ†“
O
Observe (Observe)

Tool result enters context โ†’ back to Reason

โ†“ (loop until response or max 5)
F
Final

LLM generates a natural language response for the user

โš  Why a 5-Round Limit?

Without a limit, a bug in the AI logic can cause an infinite loop โ€” costing hundreds of dollars in tokens. The limit of 5 is the circuit breaker that protects your billing. For complex tasks, adjust the limit carefully and always monitor it.

4

๐Ÿ“ The Workspace โ€” Configuration in Markdown

The directory workspace/ is where you define what your Jarvis is. Three Markdown files that are read and injected into every system prompt. Changing the AIโ€™s behavior doesnโ€™t require changing codeโ€”just editing these files.

๐Ÿงฌ SOUL.md

The AI's personality: name, tone of voice, values, communication style, ethical limitations. Defines who Jarvis is.

You are Atlas, a direct, technical personal assistant. You prefer Python. You aren't afraid to disagree.

๐Ÿ“‹ AGENTS.md

Behavior rules: what to do, what never to do, how to prioritize tasks, when to ask for confirmation.

NEVER run rm -rf without confirmation. ALWAYS check whether files exist before overwriting them.

๐Ÿง  MEMORY.md

Bootstrap facts: information the AI needs to know from the first conversation without having to be taught.

User: Joรฃo Silva. Stack: Python, FastAPI. Company: Acme Corp. Time zone: America/Sao_Paulo.

๐Ÿ’ก Configuration as Code

Workspace files are "code" in the sense that they control system behavior. Version them with git, back them up, and treat changes to them with the same care as code changes.

5

๐Ÿงฉ Interface Contracts

The secret to INTELECTOโ€™s extensibility is the interface contracts. Each component type has an abstract base class with required methods. If you follow the contract, your component works with everything else automatically.

๐Ÿ“‹ The 3 Main Contracts

BaseProviderproviders/base.py
async def chat(messages: list[dict], **kwargs) -> str: ...

The only required method. Any LLM that implements this works with the Agent.

BaseChannelchannels/base.py
async def start() โ†’ None
async def send(user_id, msg) โ†’ None
async def stop() โ†’ None

3 methods. Telegram, WhatsApp, CLI โ€” all implement these 3.

BaseTooltools/base.py
name: str
description: str
parameters: dict # JSON Schema
async def execute(**kwargs) โ†’ str

The description + parameters are sent to the LLM so it knows how to use the tool.

6

๐Ÿ—„ Persistence in ~/.intelecto/

Everything INTELECTO persists is stored in ~/.intelecto/. Three critical files you need to know, back up, and never accidentally delete.

DB

memory.db

SQLite database with FTS5 enabled. Stores facts (category: fact/conversation/solution), conversation history, and results of previous searches. BM25 for relevance ranking.

๐Ÿ”

.secrets

API keys encrypted with Fernet. The encryption key is derived from the hardware UUID using PBKDF2. The file can only be decrypted on the same machine.

๐Ÿ“‹

audit.log

Record of all actions: who requested them, what was executed, when, and with what result. Immutable by design โ€” each line is append-only.

โœ… Module 1.2 Summary

โœ“
5 Components โ€” Agent, Providers, Channels, Memory, Tools with strictly separated responsibilities
โœ“
Complete Workflow โ€” 8 stages from incoming message to sent response, each auditable
โœ“
ReAct Loop โ€” Reason-Act-Observe with a 5-round limit as a cost circuit breaker
โœ“
Workspace โ€” SOUL.md (personality), AGENTS.md (rules), MEMORY.md (bootstrap facts)
โœ“
Contracts โ€” BaseProvider, BaseChannel, BaseTool ensure any implementation is plug-and-play
โœ“
Persistence โ€” memory.db (SQLite FTS5), .secrets (Fernet), audit.log (append-only)

Next Module:

1.3 โ€” Environment Setup: from scratch to Jarvis running on Telegram