Skip to content

refactor: extract callModel, unify tool handlers, add sessionCompactor#2761

Closed
dgageot wants to merge 3 commits into
docker:mainfrom
dgageot:runtime/extract-collaborators
Closed

refactor: extract callModel, unify tool handlers, add sessionCompactor#2761
dgageot wants to merge 3 commits into
docker:mainfrom
dgageot:runtime/extract-collaborators

Conversation

@dgageot
Copy link
Copy Markdown
Member

@dgageot dgageot commented May 11, 2026

Three runtime refactors stacked on #2759 and #2760:

  1. Extract callModel method — Pulls the before-hooks → transforms → LLM call → error handling → after-hooks pipeline out of runTurn into a standalone callModel method.

  2. Unify tool handler registration — Removes ToolHandlerFunc type. Built-in handlers now match toolexec.ToolHandler directly, eliminating the per-batch adapter loop in processToolCalls.

  3. sessionCompactor collaborator — Moves compaction logic (previously scattered across 4 files) into a self-contained sessionCompactor struct.

Depends on #2759 and #2760. Pure refactor, no behaviour change.

@dgageot dgageot requested a review from a team as a code owner May 11, 2026 16:46
@docker-agent

This comment was marked as outdated.

@dgageot dgageot force-pushed the runtime/extract-collaborators branch 4 times, most recently from 4365963 to 14d512d Compare May 12, 2026 07:38
@rumpl
Copy link
Copy Markdown
Member

rumpl commented May 12, 2026

waiting on a rebase once the eventsink is merged

dgageot added 3 commits May 12, 2026 10:47
…ndler

Remove ToolHandlerFunc type and the per-batch adapter loop in
processToolCalls. Built-in handlers (transfer_task, handoff,
change_model, revert_model, run_skill) now match toolexec.ToolHandler
directly and access events through r.toolSink, set for the duration of
each processToolCalls call.
Move compactWithReason, compactIfNeeded, preCompactSourceFor, and
joinPrompts into a sessionCompactor struct. The LocalRuntime holds a
*sessionCompactor and delegates all compaction calls to it. This
concentrates compaction reasoning (previously spread across runtime.go,
loop.go, loop_steps.go, and session_compaction.go) in one place.
@dgageot dgageot force-pushed the runtime/extract-collaborators branch from 14d512d to 19ce805 Compare May 12, 2026 08:52
// emits a TokenUsageEvent so the UI immediately reflects the new
// context pressure.
func (c *sessionCompactor) Compact(ctx context.Context, sess *session.Session, additionalPrompt, reason string, events EventSink) {
r := c.runtime
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kinda weird for this to depend on the runtime just to run the pre-compaction hooks

a := r.resolveSessionAgent(sess)

source := preCompactSourceFor(reason)
skip, msg, extraPrompt := r.executePreCompactHooks(ctx, sess, a, source, events)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r.doCompact already calls executeBeforeCompactionHooks, what is the difference between the two?

@dgageot dgageot closed this May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants