Skip to main content

Service Layer

All business logic is encapsulated in the services/ directory, with clear responsibilities per module, collaborating through function calls.

Service Call Relationships


agent.py -- Chat Agent

Core chat service implementing LLM tool call loop and memory injection.

Available Tools

ToolFunctionParameters
search_knowledgeSingle keyword search in screenshot knowledge basequery: string
search_multiMulti-keyword simultaneous search, merge and dedupqueries: string[]
get_recentGet recent N screenshot analyseslimit: integer
web_searchSearch the internetquery: string

Key Design

  • Memory injection: First round of each conversation injects user memories into system prompt
  • Async memory extraction: After conversation ends, asynchronously extracts memories using independent DB session and semaphore (max 2 concurrent)
  • History limit: Default loads last 20 messages

llm.py -- LLM Service

Shared LLM HTTP client, all LLM calls go through this module.


memory.py -- Memory Service

Manages Agent memory extraction, retrieval, and decay.

Memory Types

TypeExpiryDescription
short_termAuto-expires after 48 hoursTemporary info, e.g., to-do items from instant chat
long_termNever expires (but decays)Names, companies, preferences, etc.

Memory Categories

CategoryDescriptionExample
factGeneral facts"User works in Beijing"
peoplePeople info"Zhang San is a project manager"
projectProject info"Working on XX bidding project"
financeFinancial info"Salary 15000 yuan"
scheduleSchedule"Project deadline Dec 20"
preferencePreferences"Prefers high-speed rail"
interestInterests"Follows AI technology"
habitHabits"Checks stocks every morning"

pipeline.py -- Analysis Pipeline

Async LLM analysis flow after screenshot upload.

Task Scheduling and Retry

  • 3 retries with exponential backoff (2s, 4s)
  • Unrecoverable errors (FileNotFoundError, ValueError) skip directly
  • Every 3 analyses completed, automatically triggers reasoning cycle

Screenshot knowledge base search service, supporting FTS5 full-text search and keyword LIKE fallback.


reasoner.py -- Intent Reasoning

Background "thinking" module analyzing recent user activity and generating articles/notes.


push.py -- Push Notifications

Sends push notifications via Webhook.


Supports Tavily and Brave Search APIs. Tavily takes priority, Brave as fallback.


storage.py -- File Storage

Saves original images and thumbnails. Files organized by date directory.


encryption.py -- Encryption Service

Fernet symmetric encryption for protecting sensitive fields (chat content, memories).


retention.py -- Data Cleanup

Cleans up expired data by retention_days configuration.


scheduler.py -- Scheduled Tasks

Background scheduler running in main.py lifespan.

TaskIntervalDescription
Reasoning1 hourAnalyze recent screenshots and chats, generate dynamic articles
Memory Decay24 hoursDelete expired short-term memories, reduce long-term importance
Data Cleanup24 hoursClean old data per retention_days config