@@ -32,6 +32,7 @@ main.py # Application entry point
3232config/
3333 __init__.py
3434 settings.py # Environment configuration
35+ models.py # Model configuration (LLM_MODEL, IMAGE_MODEL)
3536 schemas.py # JSON schemas for LLM responses
3637 personality/ # Modular character definition
3738 __init__.py # Combines parts into SYSTEM_PROMPT
@@ -41,15 +42,17 @@ config/
4142 prompts/ # LLM prompts
4243 agent_autopost.py # Agent planning prompt
4344 mention_selector.py # Mention handling prompt
45+ utils/
46+ __init__.py
47+ api.py # OpenRouter API configuration
4448services/
4549 __init__.py
46- autopost.py # Autoposting service
50+ autopost.py # Autoposting service (uses LLMClient)
4751 mentions.py # Mention handling service
4852 tier_manager.py # Twitter API tier detection and limits
49- llm.py # LLM client
53+ llm.py # LLM client (generate, generate_structured, chat)
5054 twitter.py # Twitter API client
51- image_gen.py # Image generation service
52- database.py # Database operations
55+ database.py # Database operations + metrics
5356tools/
5457 __init__.py
5558 registry.py # Tool registry for function calling
@@ -67,19 +70,41 @@ requirements.txt # Python dependencies
6770### main.py
6871FastAPI application with lifespan management. On startup:
69721 . Connects to PostgreSQL database
70- 2 . Initializes AutoPostService and MentionHandler
71- 3 . Schedules two recurring jobs via APScheduler:
72- - ` autopost_job ` — runs every POST_INTERVAL_MINUTES
73- - ` mentions_job ` — runs every MENTIONS_INTERVAL_MINUTES
74- 4 . Starts the scheduler
73+ 2 . Initializes TierManager, AutoPostService, and MentionHandler
74+ 3 . Logs connected Twitter account info
75+ 4 . Schedules hourly tier refresh via APScheduler
76+ 5 . Starts the scheduler
7577
7678HTTP endpoints:
77- - ` GET /health ` — health check with scheduler status
79+ - ` GET /health ` — health check with database, scheduler, tier status
80+ - ` GET /metrics ` — bot statistics (posts/mentions counts, timestamps)
7881- ` GET /callback ` — OAuth callback for Twitter authentication
79- - ` POST /trigger-post ` — manually trigger autopost
80- - ` POST /trigger-mentions ` — manually trigger mention processing
82+ - ` POST /trigger-post ` — manually trigger agent-based autopost
83+ - ` GET /check-mentions ` — fetch mentions without processing (dry run)
84+ - ` POST /process-mentions ` — fetch and process mentions
8185- ` GET /tier-status ` — get current tier and usage stats
8286- ` POST /tier-refresh ` — force tier re-detection
87+ - ` POST /webhook/mentions ` — Twitter webhook endpoint
88+ - ` GET /webhook/mentions ` — Twitter CRC challenge verification
89+
90+ ### utils/api.py
91+ Centralized OpenRouter API configuration.
92+
93+ ** Contents:**
94+ - ` OPENROUTER_URL ` — API endpoint constant
95+ - ` get_openrouter_headers() ` — Returns headers with authorization, content-type, referer
96+
97+ ** Used by:** services/llm.py, tools/web_search.py, tools/image_generation.py
98+
99+ ### config/models.py
100+ Centralized model configuration.
101+
102+ ``` python
103+ LLM_MODEL = " anthropic/claude-sonnet-4.5"
104+ IMAGE_MODEL = " google/gemini-3-pro-image-preview"
105+ ```
106+
107+ ** Used by:** services/llm.py, tools/web_search.py, tools/image_generation.py
83108
84109### config/settings.py
85110Pydantic Settings class that loads configuration from environment variables and ` .env ` file. All settings are typed and validated on startup.
@@ -199,9 +224,9 @@ Structured output schema:
199224Methods:
200225- ` generate(system, user) ` — simple text completion
201226- ` generate_structured(system, user, response_format) ` — JSON structured output
202- - ` chat(messages, tools ) ` — chat completion with optional tool calling
227+ - ` chat(messages, response_format ) ` — multi-turn chat with optional structured output
203228
204- Uses ` anthropic/claude-sonnet-4.5 ` model by default (configurable via TEXT_MODEL constant) .
229+ Uses model from ` config/models.py ` ( ` LLM_MODEL ` ). The ` chat() ` method is used by ` AutoPostService ` for agent conversations .
205230
206231### services/twitter.py
207232` TwitterClient ` class — Twitter API integration using tweepy.
@@ -215,16 +240,27 @@ Methods:
215240
216241Note: Media upload uses API v1.1 because v2 doesn't support it yet.
217242
218- ### services/image_gen .py
219- ` ImageGenerator ` class — image generation via OpenRouter .
243+ ### services/database .py
244+ ` Database ` class — async PostgreSQL client using asyncpg .
220245
221- Uses ` google/gemini-3-pro-image-preview ` model. Supports reference images from ` assets/ ` folder for consistent character appearance.
246+ Tables (auto-created on startup):
247+ - ` posts ` — stores all posted tweets
248+ - ` mentions ` — stores mention interactions
249+ - ` bot_state ` — key-value store for state (e.g., last_mention_id)
222250
223- Flow:
224- 1 . Loads reference images from ` assets/ ` folder (up to 2 randomly selected)
225- 2 . Sends reference images + text prompt to model
226- 3 . Receives base64-encoded image in response
227- 4 . Returns raw image bytes
251+ ** Key methods:**
252+ - ` get_recent_posts_formatted(limit) ` — posts as formatted string for LLM context
253+ - ` save_post(text, tweet_id, include_picture) ` — save new post
254+ - ` save_mention(...) ` — save mention interaction
255+ - ` mention_exists(tweet_id) ` — check if mention already processed
256+ - ` get_state(key) ` / ` set_state(key, value) ` — state management
257+ - ` get_user_mention_history(author_handle) ` — conversation history with user
258+
259+ ** Metrics methods (v1.2.2):**
260+ - ` ping() ` — health check (returns bool)
261+ - ` count_posts() ` / ` count_posts_today() ` — post counts
262+ - ` count_mentions() ` / ` count_mentions_today() ` — mention counts
263+ - ` get_last_post_time() ` / ` get_last_mention_time() ` — timestamps
228264
229265### services/tier_manager.py
230266` TierManager ` class — automatic Twitter API tier detection and limit management.
@@ -265,21 +301,6 @@ TIER_FEATURES = {
265301- ` MentionHandler.process_mentions_batch() ` calls ` tier_manager.can_use_mentions() ` before processing
266302- Both services receive ` tier_manager ` instance via constructor
267303
268- ### services/database.py
269- ` Database ` class — async PostgreSQL client using asyncpg.
270-
271- Tables (auto-created on startup):
272- - ` posts ` — stores all posted tweets
273- - ` mentions ` — stores mention interactions
274- - ` bot_state ` — key-value store for state (e.g., last_mention_id)
275-
276- Key methods:
277- - ` get_recent_posts_formatted(limit) ` — posts as formatted string for LLM context
278- - ` save_post(text, tweet_id, include_picture) ` — save new post
279- - ` save_mention(...) ` — save mention interaction
280- - ` mention_exists(tweet_id) ` — check if mention already processed
281- - ` get_state(key) ` / ` set_state(key, value) ` — state management
282-
283304### tools/registry.py
284305Tool registry for agent function calling. Contains:
285306- ` TOOLS ` — dict mapping tool names to async functions
0 commit comments