Skip to content

refactor: decouple sessions and delegation - #3

Merged
lsongdev merged 1 commit into
masterfrom
refactor/session-delegation
Sep 16, 2026
Merged

lsongdev merged 1 commit into
masterfrom
refactor/session-delegation

Conversation

@lsongdev

@lsongdev lsongdev commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

This refactor makes agent/subagent the same runtime concept: delegation is just a tool that invokes another normal profile-backed Agent with an isolated ephemeral session.

Session boundary

  • add Agent.Run, which only advances the in-memory session and never writes it to disk
  • move successful user-session persistence to NewRecordingSink, the boundary that already records session events
  • keep an explicit save before user turns, and save failed ACP turns best-effort so partial state is not silently discarded
  • delegated calls use the same session.Session type but never attach a recording/persistence sink
  • keep RunAgentLoop as a one-line compatibility alias to Run

Delegation

  • replace AgentRunner / SubagentTool with a plain DelegateFunc
  • expose a single delegate(agent, task) tool
  • delegate schema enumerates configured profiles and includes their optional descriptions
  • return the delegated agent's final assistant response as the tool result
  • propagate the caller context naturally and cap nested delegation depth at 4 to prevent accidental cycles

Tool composition

  • remove built-in tool construction from Agent
  • Manager assembles tools when it instantiates a profile-backed Agent
  • add ProfileConfig.Tools; an empty list keeps the current default tool set, while a non-empty list selects exact tool names
  • explicit built-in-only profiles do not initialize unrelated MCP servers
  • MCP tools remain selectable by their existing mcp_<server>_<tool> names

Validation

A temporary PR-only CI step ran:

go test ./agent
go test ./tools -run '^TestDelegateToolCallsFunction$'
go test ./config -run '^$'

All passed, followed by the normal multi-platform make build. The temporary workflow change was then removed. After squashing the branch to one commit, the normal Release workflow ran again and passed (run #31).

The final branch is one commit over master; no workflow changes are included.

@lsongdev
lsongdev force-pushed the refactor/session-delegation branch from 78f91b8 to 4ac7947 Compare September 16, 2026 07:43
@lsongdev
lsongdev marked this pull request as ready for review September 16, 2026 07:44
@lsongdev
lsongdev merged commit a885c1f into master Sep 16, 2026
1 check passed
@lsongdev
lsongdev deleted the refactor/session-delegation branch September 16, 2026 08:03
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.

1 participant