Skip to content

feat(agent-core): replace asChild boolean with an explicit session role enum - #451

Merged
WinterYukky merged 2 commits into
aws-samples:mainfrom
WinterYukky:feature/create-session-role-enum-1785861679
Aug 24, 2026
Merged

feat(agent-core): replace asChild boolean with an explicit session role enum#451
WinterYukky merged 2 commits into
aws-samples:mainfrom
WinterYukky:feature/create-session-role-enum-1785861679

Conversation

@WinterYukky

Copy link
Copy Markdown
Contributor

Summary

Replace the boolean asChild parameter of the createNewSession tool with an
explicit role enum (child | successor | independent), and add the
session-reparenting plumbing the successor role needs.

Motivation

A single boolean could not express the three distinct relationships a new session
can have with the current one. An explicit enum makes intent unambiguous in the
tool schema, enables the successor/handover flow (re-parent the current session
and its children under a fresh parent), and keeps independent sessions clearly
separate.

Changes

  • packages/agent-core/src/tools/create-session/index.ts: swap asChild for the
    role enum; expand the tool description and role guidance.
  • packages/agent-core/src/lib/sessions.ts: add reparentSessions to move a set
    of child workers under a new parent.
  • packages/agent-core/src/schema/session.ts, schema/events.ts: schema fields /
    event types for the role + reparenting.
  • create-session/index.test.ts: unit coverage for the role enum + reparenting.

Testing

  • agent-core unit tests: create-session/index.test.ts — 8 tests, all passing
    (tsc + prettier + vitest).

Notes

  • Self-contained. The handover-modal PR (webapp) builds on the successor
    flow introduced here — merge this first.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…Session tool

Replace the binary asChild parameter with a three-value role enum:
- 'child': Sub-task of the current session (replaces asChild=true)
- 'successor': Hand over to a fresh parent session, re-parenting the
  current session and all its children under the new one
- 'independent': Completely separate session (replaces asChild=false)

The successor role enables session handover (引き継ぎ): when an agent's
context grows too large or the user explicitly requests a handover, it
can spin up a fresh coordinator that inherits the full session tree.

Supporting changes:
- Add reparentSessions() to sessions.ts with cycle detection, self-parent
  guard, and DDB TransactWrite (bounded at 100 items)
- Add sessionReparented webapp event for real-time sidebar updates
- Add handedOverTo field to SessionItem schema (idempotency guard for
  concurrent handover attempts)
The tool description and role guidance are user-facing prompt strings in the
public upstream, so remove the stray non-English term and keep the handover
wording consistent in English. No behavioural change (8 tests pass).
@WinterYukky
WinterYukky merged commit 97fd3c4 into aws-samples:main Aug 24, 2026
8 checks passed
@WinterYukky
WinterYukky deleted the feature/create-session-role-enum-1785861679 branch August 24, 2026 06:52
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