Skip to content

Architecture

μ•„ν‚€ν…μ²˜

Project Structure / ν”„λ‘œμ νŠΈ ꡬ쑰

SalmAlm is organized into several subpackages, each responsible for a specific domain.

SalmAlm은 μ—¬λŸ¬ μ„œλΈŒνŒ¨ν‚€μ§€λ‘œ κ΅¬μ„±λ˜μ–΄ 있으며, 각각 νŠΉμ • 도메인을 λ‹΄λ‹Ήν•©λ‹ˆλ‹€.

salmalm/
β”œβ”€β”€ __init__.py          # Package init, version
β”œβ”€β”€ __main__.py          # Entry point (python -m salmalm)
β”œβ”€β”€ cli.py               # CLI argument parser
β”œβ”€β”€ constants.py         # Global constants
β”‚
β”œβ”€β”€ core/                # Core engine modules / μ½”μ–΄ μ—”μ§„ λͺ¨λ“ˆ
β”‚   β”œβ”€β”€ core.py          # Central SalmAlm class
β”‚   β”œβ”€β”€ engine.py        # LLM orchestration engine
β”‚   β”œβ”€β”€ llm.py           # LLM provider abstraction
β”‚   β”œβ”€β”€ llm_loop.py      # Conversation loop handler
β”‚   β”œβ”€β”€ llm_task.py      # Async LLM task runner
β”‚   β”œβ”€β”€ prompt.py        # System prompt builder
β”‚   β”œβ”€β”€ session_manager.py # Session lifecycle
β”‚   β”œβ”€β”€ memory.py        # Memory management
β”‚   β”œβ”€β”€ health.py        # Health check endpoints
β”‚   β”œβ”€β”€ shutdown.py      # Graceful shutdown
β”‚   β”œβ”€β”€ export.py        # Session export (JSON/Markdown)
β”‚   β”œβ”€β”€ image_resize.py  # Image preprocessing
β”‚   β”œβ”€β”€ plugin_watcher.py # Plugin hot-reload
β”‚   └── exceptions.py    # Custom exceptions
β”‚
β”œβ”€β”€ tools/               # Tool system / 도ꡬ μ‹œμŠ€ν…œ
β”‚   β”œβ”€β”€ tool_registry.py # Decorator-based tool dispatch
β”‚   β”œβ”€β”€ tools.py         # Tool definitions (58+ schemas)
β”‚   β”œβ”€β”€ tools_file.py    # File operations
β”‚   β”œβ”€β”€ tools_web.py     # Web search & fetch
β”‚   β”œβ”€β”€ tools_exec.py    # Shell execution
β”‚   β”œβ”€β”€ tools_memory.py  # Memory tools
β”‚   β”œβ”€β”€ tools_system.py  # System monitoring
β”‚   β”œβ”€β”€ tools_personal.py # Personal assistant tools
β”‚   β”œβ”€β”€ tools_calendar.py # Calendar tools
β”‚   β”œβ”€β”€ tools_email.py   # Email tools
β”‚   β”œβ”€β”€ tools_google.py  # Google integration
β”‚   β”œβ”€β”€ tools_media.py   # Image/audio tools
β”‚   β”œβ”€β”€ tools_browser.py # Browser automation
β”‚   β”œβ”€β”€ tools_agent.py   # Sub-agent spawning
β”‚   β”œβ”€β”€ tools_misc.py    # Miscellaneous utilities
β”‚   β”œβ”€β”€ tools_patch.py   # Patch/diff tools
β”‚   β”œβ”€β”€ tools_common.py  # Shared tool utilities
β”‚   β”œβ”€β”€ tools_reaction.py # Reaction tools
β”‚   β”œβ”€β”€ tools_reminder.py # Reminder tools
β”‚   └── tools_util.py    # Utility tools
β”‚
β”œβ”€β”€ features/            # Feature modules / κΈ°λŠ₯ λͺ¨λ“ˆ
β”‚   β”œβ”€β”€ commands.py      # Slash command handler (30+)
β”‚   β”œβ”€β”€ rag.py           # RAG vector search
β”‚   β”œβ”€β”€ mcp.py           # MCP server/client
β”‚   β”œβ”€β”€ mcp_marketplace.py # MCP marketplace
β”‚   β”œβ”€β”€ a2a.py           # Agent-to-agent protocol
β”‚   β”œβ”€β”€ agents.py        # Multi-agent management
β”‚   β”œβ”€β”€ briefing.py      # Daily briefing
β”‚   β”œβ”€β”€ bookmarks.py     # Session bookmarks
β”‚   β”œβ”€β”€ compare.py       # Response comparison
β”‚   β”œβ”€β”€ dashboard_life.py # Life dashboard
β”‚   β”œβ”€β”€ deadman.py       # Dead man switch
β”‚   β”œβ”€β”€ doctor.py        # System diagnostics
β”‚   β”œβ”€β”€ heartbeat.py     # Heartbeat monitoring
β”‚   β”œβ”€β”€ hooks.py         # Event hooks
β”‚   β”œβ”€β”€ mood.py          # Mood tracking
β”‚   β”œβ”€β”€ nodes.py         # Node management
β”‚   β”œβ”€β”€ plugin_manager.py # Plugin lifecycle
β”‚   β”œβ”€β”€ presence.py      # Online presence
β”‚   β”œβ”€β”€ self_evolve.py   # Self-evolution
β”‚   β”œβ”€β”€ shadow.py        # Shadow mode
β”‚   β”œβ”€β”€ sla.py           # SLA monitoring
β”‚   β”œβ”€β”€ stt.py           # Speech-to-text
β”‚   β”œβ”€β”€ stability.py     # Stability features
β”‚   β”œβ”€β”€ thoughts.py      # Thought tracking
β”‚   β”œβ”€β”€ timecapsule.py   # Time capsule
β”‚   β”œβ”€β”€ transcript_hygiene.py # Transcript cleanup
β”‚   β”œβ”€β”€ tray.py          # System tray
β”‚   β”œβ”€β”€ users.py         # User management
β”‚   β”œβ”€β”€ vault_chat.py    # Vault chat
β”‚   β”œβ”€β”€ watcher.py       # File watcher
β”‚   └── workflow.py      # Workflow engine
β”‚
β”œβ”€β”€ channels/            # Chat channels / μ±„νŒ… 채널
β”‚   β”œβ”€β”€ channel_router.py # Multi-channel routing
β”‚   β”œβ”€β”€ telegram.py      # Telegram bot
β”‚   β”œβ”€β”€ discord_bot.py   # Discord bot
β”‚   └── slack_bot.py     # Slack bot (experimental)
β”‚
β”œβ”€β”€ security/            # Security layer / λ³΄μ•ˆ λ ˆμ΄μ–΄
β”‚   β”œβ”€β”€ security.py      # OWASP protection
β”‚   β”œβ”€β”€ crypto.py        # AES-256-GCM encryption
β”‚   β”œβ”€β”€ sandbox.py       # Sandboxed execution
β”‚   β”œβ”€β”€ container.py     # Container isolation
β”‚   └── exec_approvals.py # Dangerous command approval
β”‚
β”œβ”€β”€ web/                 # Web server / μ›Ή μ„œλ²„
β”‚   β”œβ”€β”€ web.py           # HTTP request handler
β”‚   β”œβ”€β”€ ws.py            # WebSocket handler
β”‚   β”œβ”€β”€ auth.py          # Web authentication
β”‚   β”œβ”€β”€ oauth.py         # Google OAuth flow
β”‚   └── templates.py     # HTML templates
β”‚
β”œβ”€β”€ utils/               # Utilities / μœ ν‹Έλ¦¬ν‹°
β”‚   β”œβ”€β”€ async_http.py    # Async HTTP client
β”‚   β”œβ”€β”€ browser.py       # Browser utilities
β”‚   β”œβ”€β”€ chunker.py       # Message chunking
β”‚   β”œβ”€β”€ dedup.py         # Deduplication
β”‚   β”œβ”€β”€ file_logger.py   # File-based logging
β”‚   β”œβ”€β”€ logging_ext.py   # Logging extensions
β”‚   β”œβ”€β”€ markdown_ir.py   # Markdown IR processor
β”‚   β”œβ”€β”€ migration.py     # Data migration
β”‚   β”œβ”€β”€ queue.py         # Async queue
β”‚   β”œβ”€β”€ retry.py         # Retry with backoff
β”‚   └── tls.py           # TLS certificate generation
β”‚
β”œβ”€β”€ infra/               # Infrastructure / 인프라
β”œβ”€β”€ integrations/        # External integrations / μ™ΈλΆ€ 톡합
β”œβ”€β”€ plugins/             # Plugin directory / ν”ŒλŸ¬κ·ΈμΈ 디렉토리
β”œβ”€β”€ static/              # Static assets (HTML, CSS, JS)
β”œβ”€β”€ frontend/            # Frontend assets
└── default_skills/      # Built-in skill definitions

Data Flow / 데이터 흐름

User Input β†’ Channel (Web/Telegram/Discord)
    β†’ channel_router β†’ core.engine
    β†’ prompt builder β†’ LLM API
    β†’ tool_registry (if tool call) β†’ tool_handler
    β†’ response β†’ channel β†’ User

Key Design Decisions / μ£Όμš” 섀계 κ²°μ •

  1. Zero dependencies β€” stdlib only for core; cryptography optional for vault / μ½”μ–΄λŠ” ν‘œμ€€ 라이브러리만 μ‚¬μš©
  2. Decorator-based tool registry β€” @register("tool_name") pattern / λ°μ½”λ ˆμ΄ν„° 기반 도ꡬ 등둝
  3. Lazy module loading β€” tools loaded on first use / 첫 μ‚¬μš© μ‹œ λͺ¨λ“ˆ λ‘œλ”©
  4. Multi-channel abstraction β€” single engine, multiple frontends / 단일 μ—”μ§„, 닀쀑 ν”„λ‘ νŠΈμ—”λ“œ
  5. Feature isolation β€” each feature is a standalone module / 각 κΈ°λŠ₯은 독립 λͺ¨λ“ˆ
  6. SSE-first transport β€” SSE is the primary message delivery channel (tab-switch-safe); WebSocket demoted to typing indicators only / SSEκ°€ κΈ°λ³Έ 전솑 채널 (νƒ­ μ „ν™˜ μ•ˆμ „); WebSocket은 타이핑 ν‘œμ‹œλ§Œ
  7. Embedding RAG β€” hybrid vector search with OpenAI/Google embeddings + BM25 fallback for memory recall / ν•˜μ΄λΈŒλ¦¬λ“œ 벑터 검색 (μž„λ² λ”© + BM25 폴백)