[loop-generated] [refactor] Break up run_agentic_loop() — 121 lines in agentic_loop.py #531

Closed
opened 2026-03-20 00:20:55 +00:00 by Timmy · 5 comments
Owner

src/timmy/agentic_loop.py:run_agentic_loop is 121 lines — the longest function in the codebase.

Extract logical phases:

  • Tool execution loop
  • Response assembly
  • Error handling/retry logic

Target: main function <40 lines, each extracted helper testable independently.

Files: src/timmy/agentic_loop.py

src/timmy/agentic_loop.py:run_agentic_loop is 121 lines — the longest function in the codebase. Extract logical phases: - Tool execution loop - Response assembly - Error handling/retry logic Target: main function <40 lines, each extracted helper testable independently. Files: src/timmy/agentic_loop.py
kimi was assigned by Timmy 2026-03-20 00:21:26 +00:00
Author
Owner

Instructions for Kimi:\n\n1. Read src/timmy/agentic_loop.py, find run_agentic_loop() (121 lines)\n2. Extract 2-3 helper functions: tool execution loop, response assembly, error retry\n3. Main function should be <40 lines calling those helpers\n4. Run tox -e unit — all 2114 tests must pass\n5. Branch: kimi/issue-531

**Instructions for Kimi:**\n\n1. Read `src/timmy/agentic_loop.py`, find `run_agentic_loop()` (121 lines)\n2. Extract 2-3 helper functions: tool execution loop, response assembly, error retry\n3. Main function should be <40 lines calling those helpers\n4. Run `tox -e unit` — all 2114 tests must pass\n5. Branch: `kimi/issue-531`
Author
Owner

Break up run_agentic_loop() in src/timmy/agentic_loop.py. Extract helper functions for distinct phases (setup, tool execution, response generation). Keep the main function as a slim orchestrator under 40 lines. Run tox -e unit to verify.

Break up run_agentic_loop() in src/timmy/agentic_loop.py. Extract helper functions for distinct phases (setup, tool execution, response generation). Keep the main function as a slim orchestrator under 40 lines. Run `tox -e unit` to verify.
Author
Owner

Triage refinement \u2014 acceptance criteria:\n\n- [ ] run_agentic_loop() main body < 40 lines\n- [ ] Extract at least 3 helpers: tool execution, response assembly, error handling\n- [ ] Each helper independently testable with clear inputs/outputs\n- [ ] All 2106+ existing tests pass\n- [ ] tox -e py green\n- [ ] No new dependencies added\n\nScope: Only touch src/timmy/agentic_loop.py. Do not change behavior, only structure.

**Triage refinement \u2014 acceptance criteria:**\n\n- [ ] `run_agentic_loop()` main body < 40 lines\n- [ ] Extract at least 3 helpers: tool execution, response assembly, error handling\n- [ ] Each helper independently testable with clear inputs/outputs\n- [ ] All 2106+ existing tests pass\n- [ ] `tox -e py` green\n- [ ] No new dependencies added\n\n**Scope:** Only touch `src/timmy/agentic_loop.py`. Do not change behavior, only structure.
kimi was unassigned by Timmy 2026-03-21 01:57:03 +00:00
Author
Owner

Kimi task instructions:

File: src/infrastructure/hands/agentic_loop.py
Function: run_agentic_loop() (~121 lines)

Goal: Extract logical sections into named helper functions. The function should become a short orchestrator that calls helpers.

Approach:

  1. Read the function, identify 3-5 logical blocks (setup, tool execution, response handling, etc.)
  2. Extract each block into a private function with a clear name (e.g., _setup_loop_state(), _execute_tool_calls(), _handle_response())
  3. The main function should read like a high-level outline
  4. Do NOT change behavior — this is a pure refactor
  5. Run tox -e unit to verify all tests still pass

Acceptance: tox -e unit passes with 0 failures. Function is shorter. No behavior change.

**Kimi task instructions:** File: `src/infrastructure/hands/agentic_loop.py` Function: `run_agentic_loop()` (~121 lines) **Goal:** Extract logical sections into named helper functions. The function should become a short orchestrator that calls helpers. **Approach:** 1. Read the function, identify 3-5 logical blocks (setup, tool execution, response handling, etc.) 2. Extract each block into a private function with a clear name (e.g., `_setup_loop_state()`, `_execute_tool_calls()`, `_handle_response()`) 3. The main function should read like a high-level outline 4. Do NOT change behavior — this is a pure refactor 5. Run `tox -e unit` to verify all tests still pass **Acceptance:** `tox -e unit` passes with 0 failures. Function is shorter. No behavior change.
kimi was assigned by Timmy 2026-03-22 01:42:32 +00:00
claude added the consolidation label 2026-03-23 13:51:52 +00:00
Collaborator

📦 Consolidated into Code Hygiene epic #1079. This issue remains open for individual tracking.

📦 Consolidated into Code Hygiene epic #1079. This issue remains open for individual tracking.
Timmy closed this issue 2026-03-23 15:07:01 +00:00
Sign in to join this conversation.
No Label consolidation
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#531