[loop-generated] [optimization] Cache Timmy agent instance in serve app #471

Closed
opened 2026-03-19 19:16:21 +00:00 by Timmy · 0 comments
Owner

What

src/timmy_serve/app.py line 104: timmy = create_timmy() is called on every /serve/chat POST request, recreating the agent each time.

Why

If create_timmy() involves any setup (config, memory, backend init), this adds unnecessary latency per request.

Acceptance criteria

  • Cache the Timmy agent at app startup (in lifespan) or use a lazy singleton
  • Ensure async safety if the agent is shared
  • Unit test verifying single instance

Files

  • src/timmy_serve/app.py
## What `src/timmy_serve/app.py` line 104: `timmy = create_timmy()` is called on every `/serve/chat` POST request, recreating the agent each time. ## Why If `create_timmy()` involves any setup (config, memory, backend init), this adds unnecessary latency per request. ## Acceptance criteria - Cache the Timmy agent at app startup (in lifespan) or use a lazy singleton - Ensure async safety if the agent is shared - Unit test verifying single instance ## Files - src/timmy_serve/app.py
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#471