Skip to content

docs: ADR 0350 — use AgentDef for sessions - #1783

Merged
kantord merged 7 commits into
mainfrom
separate-agent-config-system
Sep 23, 2026
Merged

kantord merged 7 commits into
mainfrom
separate-agent-config-system

Conversation

@kantord

@kantord kantord commented Sep 22, 2026

Copy link
Copy Markdown
Member

Summary

Proposed ADR: let a session's main engine run as a named AgentDef specialist — restricted tool allowlist, own system prompt, own model — selected at session-creation time via a new optional agent_id field on CreateSessionRequest. Today an AgentDef is only ever reachable as a child (Subagent(agent=...) or a team member); this reuses the existing buildAgentDefEngine composition step (already shared by 3 call sites) as a fourth call site, rather than a new mechanism.

Motivated by issue #1053 ("Slack bot: multiple @-mentionable identities backed by mecatl agent definitions") — a Slack bot on @stacklok/mecatl-sdk needs sessions bound to specific tool-restricted identities on mecak8s.

Key decisions (see the ADR for full rationale):

  • Strict, non-widenable tool ceiling covering core + MCP tools uniformly; mcp_servers/debug_mcp_servers on the request are rejected when agent_id is set
  • No delegation in v1 (Subagent/Parallel/Team excluded)
  • Mutation allowed only if the def's tools: says so
  • Run limits and PermissionMode are tighten-only against the def's config
  • provider_id/model_id follow the existing empty-means-unset precedence (request > def > default)
  • Ordinary main-session behavior otherwise — guardrails, governance audience, and the normal approval flow are not the child-shaped variant
  • Explicitly deferred: per-caller identity ACLs, delegation, posture-level configurability

Design-doc only — no implementation in this PR.

Test plan

  • task docs:check — 0 broken links, 0 broken anchors, 0 orphans, 0 unreachable

🤖 Generated with Claude Code

kantord and others added 2 commits September 22, 2026 16:43
Lets a session's main engine run as a named AgentDef specialist (strict
tool ceiling, own prompt/model) via a new optional agent_id field on
CreateSessionRequest, reusing buildAgentDefEngine as a fourth call site
instead of only via Subagent/team delegation. Motivated by issue #1053
(Slack bot identities backed by agent definitions).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Lead with the config-reuse story (one AgentDef, usable as a top-level
session or a delegate, no extra wiring) and cut prose length by ~45%
without dropping any decision. Also links issue #1784, the open
question on session-configurable posture raised during review.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@kantord
kantord marked this pull request as ready for review September 22, 2026 15:23
@kantord kantord changed the title docs: ADR 0350 — session-scoped agent identity docs: ADR 0350 — use AgentDef for sessions Sep 22, 2026
@jhrozek

jhrozek commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

I think the core proposal is sound: selecting an AgentDef should create a top-level session using that reusable specialist configuration. I would tighten the ADR in the following areas so the security and lifecycle contract is explicit.

1. Persisted authority attenuation

Please express the tool restriction through the existing authority model, not only catalog construction:

Resolving an AgentDef mints the root session’s persisted authority by attenuating the deployment root authority to the definition’s effective capabilities. Every subsequent engine construction must be a subset of that persisted authority. Fork, clear, restart, and tool enrollment may preserve or further attenuate it, but never widen it.

A smaller catalog controls one engine construction; persisted authority prevents later reconstruction or enrollment from restoring excluded capabilities.

2. Omitted tools: behavior

For named Subagents today, an omitted tools: means “start from this call site’s bounded base set,” not “inherit the parent’s complete catalog.” Root sessions should preserve that model.

Please define a named root-specialist base set and its unconditional exclusions. Omission must not implicitly include the ordinary root’s global MCP, delegation, scheduling, memory-management, or other composition-added tools. The definition’s disallowedTools, session profile, and deployment authority then further attenuate that base.

3. Fixed permission mode

Selecting an agent should fix the session’s permission mode.

If the definition declares permissionMode, the creation request must omit mode or specify the same value; a conflicting value is InvalidArgument. If the definition omits it, resolve the requested or deployment-default mode once at creation.

Persist that effective mode, reject SetMode for agent-bound sessions, and preserve it through fork, clear, and restart. This keeps permission mode part of the selected agent’s fixed security-and-behavior configuration.

4. Restart semantics

On restart, re-resolve the persisted agent selection from the current admitted definition registry while preserving the session’s persisted authority, provider, model, and permission mode. A missing definition fails closed.

Changes to the current definition’s prompt, hooks, skills, and memory may apply to the rebuilt engine, but they cannot widen the persisted authority.

5. Hook composition

For an agent-backed root, definition hooks should form the inner hook runner and ordinary main-session guardrails should decorate that runner.

Definition hooks therefore execute first, and guardrails inspect the effective payload after any definition mutation. A definition hook must never replace or bypass operator guardrails.

6. Other session shapes

Please define these combinations explicitly:

  • agent_id and debug_target_session_id are mutually exclusive and return InvalidArgument.
  • profile: "no-fs" remains valid as further attenuation. Filesystem tools and Shell remain absent even if the definition lists them.
  • Profiles may preserve or restrict the agent’s authority, never restore capabilities removed by either the definition or profile.

7. Provider/model pair resolution

Provider and model should be resolved as a pair:

  1. Resolve a base pair from the definition over the deployment default.
  2. With no request override, use that pair.
  3. With only model_id, apply it to the resolved base provider.
  4. With only provider_id, switch provider and use that provider’s default model; do not carry a model selected for another provider.
  5. With both fields, use the explicit pair.

Persist the resolved pair for the session lifetime. An unavailable definition-pinned provider should fail root-session creation rather than silently instantiate the named agent on another provider.

8. Project memory

For an agent-backed root, memory: project must resolve against the session’s exact bound environment, not the deployment’s default workspace. Fork and clear resolve it from the successor’s placement; memory: user retains its existing operator-level location.

9. Public field name

The requested value is an AgentDef.Name, not an agent instance or security principal. Consider naming the field agent_definition or agent_definition_name, with a corresponding resolved_agent_definition response field, rather than agent_id.

This avoids collision with Mecatl’s separate workload/cryptographic “agent identity” terminology before the name becomes part of the protobuf and SDK compatibility surface.

Addresses PR #1783 review points 1 and 4 (persisted authority,
restart semantics): SetMode/restart-rehydration/MCP-resume don't
currently know about agent_id and would rebuild through the generic
default catalog, silently widening a restricted session. v1 closes
this by failing closed on those paths rather than doing the real
persisted-authority fix, which is tracked in #1796.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@kantord

kantord commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

Thanks for this — the core-proposal agreement plus this level of detail is exactly what
I needed. Working through the points in order; starting with 1 and 4, since they turned
out to be the same underlying gap and the most load-bearing.

On #1 (persisted authority) and #4 (restart semantics): you're right, and it's worse
than "one more thing to add" — I traced every place a per-session engine gets rebuilt
(internal/adapter/server/service.go) and none of them know about agent_id today:
SetMode (plan/default/acceptEdits), restart rehydration (rehydrateSession), and
client-MCP resume (LoadSessionWithMCP) all read only ProviderID/ModelID/Profile
off the persisted session and rebuild through the same generic catalog assembly every
other session uses. Restart in particular isn't a caller action — it happens on every
mecak8s pod restart/redeploy — so an agent_id-bound session would silently regain the
full default catalog on the first restart.

I've landed a v1-scoped fix for this rather than the full persisted-authority mechanism
you described: SetMode is now rejected outright for agent_id-bound sessions, and
restart rehydration / MCP-resume for such a session fails closed (refuses to resume)
instead of rebuilding on the default catalog. It trades session continuity across a
restart for a hard non-widening guarantee — an acceptable v1 cost for the motivating
Slack-bot use case, not a real fix. Opened
#1796 to track the real one (roughly
what you proposed: a persisted attenuation of the deployment's root authority that every
rebuild path can only narrow, never re-derive wider), and linked it from the ADR's
Decision and Consequences sections.

Still working through 2, 3, 5, 6, 7, 8, 9 — will follow up on those separately.


Fully or partially written by an AI agent.

- Rename agent_id -> agent_definition_name (point 9): avoids the
  workload-identity naming collision the ADR already flagged.
- Omitted tools: resolves against the same bounded base set a
  Subagent child gets, never the ordinary root's full catalog
  (point 2).
- PermissionMode conflict is a silent clamp, mirroring Limits, now
  fixed for the session's whole lifetime via the SetMode rejection
  (point 3).
- Definition hooks wire as the inner HookRunner under the existing
  modelhook.Runner guardrail decorator - no new mechanism, guardrails
  always run second and can't be bypassed (point 5).
- Named debug_target_session_id exclusivity and no-fs composition
  rules (point 6).
- provider_id/model_id resolved as a pair, not independently, fixing
  a real mismatch bug; unavailable pinned provider fails closed
  (point 7).
- memory:project binds to the session's own EnvironmentRef, not a
  deployment default; inert under no-fs (point 8).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@kantord

kantord commented Sep 23, 2026

Copy link
Copy Markdown
Member Author

Follow-up on the rest — all landed in the latest revision.

#2 (omitted tools:): reused the existing rule rather than inventing one.
AgentDef.Tools empty already means "the call site's default set"; for the Subagent
path that's baseSubagentTools (core FS tools + Shell), which already excludes global
MCP/delegation/scheduling/memory-management by construction. A session-root call site
now resolves omitted tools: against that same base set via the same
scopedToolNamesMode step, so omission can never pull in anything wider than a child
def already gets.

#3 (fixed permission mode): kept the tighten-only clamp (mirroring Limits) rather
than a hard reject on conflict, but the earlier SetMode-rejection fix (for the
restart/rebuild hole) also closes this — combined, the effective mode is now fixed for
the session's entire lifetime, not just at creation.

#5 (hook composition): turns out this needed zero new mechanism.
internal/adapter/modelhook.Runner already runs an inner HookRunner first and the
guardrail checker second, merging block-dominant
(internal/adapter/modelhook/merge.go) — exactly the decorator you described. An
agent_definition_name session just wires the def's hooks: as that inner instead of
the ordinary no-op. Guardrails always run second and can't be bypassed.

#6 (other shapes): agent_definition_name + debug_target_session_id is now
InvalidArgument; profile:"no-fs" composes as further attenuation (FS/Shell absent
regardless of what the def lists).

#7 (provider/model pair): adopted your resolution algorithm as written — it caught a
real bug in the original draft (independent-field resolution could pair an overridden
provider_id with a model the def pinned for a different provider). An unavailable
pinned provider now fails session creation instead of silently falling back.

#8 (project memory): for an agent_definition_name session, memory: project now
resolves against that session's own EnvironmentRef (ADR 0291), not a deployment
default — there's no parent to inherit a workspace from. Inert (not an error) under
profile:"no-fs".

#9 (naming): renamed agent_id → agent_definition_name, with
resolved_agent_definition_name as the response echo.

#1/#4 already covered in the previous reply — v1 fails closed on restart/SetMode/
MCP-resume rather than doing the full persisted-authority fix, tracked in
#1796. That's everything from this
review addressed in the ADR now.


Fully or partially written by an AI agent.

kantord and others added 3 commits September 23, 2026 15:29
0350 was taken by "purpose-attributed auxiliary token usage" (#1793),
merged to main after this ADR was drafted. Renumbering to the next
free slot; also drops the now-stale "draft ADR 0351" label for PR
#1730 (0351 itself collided with an unrelated, already-merged Studio
ADR, so PR #1730 will need its own renumber before it merges).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
kantord added a commit that referenced this pull request Sep 23, 2026
…ape wrappers

Slice A of ADR 0350's implementation (docs/adr/0350-session-scoped-agent-identity.md,
still under review in PR #1783 - this branch is exploratory and not yet mergeable).

Extracts buildAgentDefEngine's catalog/MCP/skills/hooks/memory resolution into a
new resolvedAgentDefCatalog core, so it can be shared between the existing
CHILD-shaped construction (buildAgentDefEngine, unchanged behavior) and a new
ROOT-shaped construction (buildAgentDefRootEngine) that bottoms out in
engineDepsForProvider + buildGuardrailsHooks instead of newChildEngineForProvider
- ordinary main-session Deps (real Store/Instructions, AudienceMain policy,
guardrails wrapping the def's own hooks) rather than child-shaped Deps.

buildAgentDefRootEngine is not yet wired to any session-creation path - that
lands in a later slice, alongside the fail-closed rebuild guards it requires.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@kantord
kantord added this pull request to stack #1810 September 23, 2026 15:25
@kantord
kantord merged commit 862bb46 into main Sep 23, 2026
31 checks passed
@kantord
kantord deleted the separate-agent-config-system branch September 23, 2026 15:25
kantord added a commit that referenced this pull request Sep 23, 2026
…ape wrappers

Slice A of ADR 0350's implementation (docs/adr/0350-session-scoped-agent-identity.md,
still under review in PR #1783 - this branch is exploratory and not yet mergeable).

Extracts buildAgentDefEngine's catalog/MCP/skills/hooks/memory resolution into a
new resolvedAgentDefCatalog core, so it can be shared between the existing
CHILD-shaped construction (buildAgentDefEngine, unchanged behavior) and a new
ROOT-shaped construction (buildAgentDefRootEngine) that bottoms out in
engineDepsForProvider + buildGuardrailsHooks instead of newChildEngineForProvider
- ordinary main-session Deps (real Store/Instructions, AudienceMain policy,
guardrails wrapping the def's own hooks) rather than child-shaped Deps.

buildAgentDefRootEngine is not yet wired to any session-creation path - that
lands in a later slice, alongside the fail-closed rebuild guards it requires.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Sep 25, 2026
2 tasks
kantord added a commit that referenced this pull request Sep 28, 2026
Durable behavioral and interface contract for ADR 0353 (Session-scoped
agent identity, merged as #1783). Architectural work classification;
3 scenarios, 25 acceptance criteria, 7 open human decisions (keeps the
plan draft).

Drafted via /to-acceptance-plan, reviewed by one devils-advocate pass
and two specialist spot-checks (secure-code-reviewer, software-architect),
all folded in:
- devils-advocate: fixed a contradiction between AC2.5's original
  claim and the ADR's own text vs. actual code (memory:project
  placement), surfaced a hidden Limits zero-value decision, removed a
  task-shaped AC, added missing no-fs composition coverage.
- software-architect: confirmed the buildAgentDefEngine split and the
  new AgentDefSessionEngineFactory's shape, flagged a 15-argument
  positional-prefix duplication risk and a provider/model resolver
  delegation opportunity for the eventual implementation.
- secure-code-reviewer: found a CRITICAL, code-verified guardrail
  bypass (a definition hook's mutated payload is never re-inspected
  by the guardrail checker today) and a HIGH-severity mistargeted
  fail-closed guard (the real choke point is
  needsRehydration()/engineAndEnvironmentFor, not rehydrateSession,
  and RetryFailedRun/CompactSession/resumeFromAwaiting share the same
  exposure) - both now explicit ACs and human decisions.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
kantord added a commit that referenced this pull request Sep 28, 2026
Durable behavioral and interface contract for ADR 0353 (Session-scoped
agent identity, merged as #1783). Architectural work classification;
3 scenarios, 25 acceptance criteria, 7 open human decisions (keeps the
plan draft).

Drafted via /to-acceptance-plan, reviewed by one devils-advocate pass
and two specialist spot-checks (secure-code-reviewer, software-architect),
all folded in:
- devils-advocate: fixed a contradiction between AC2.5's original
  claim and the ADR's own text vs. actual code (memory:project
  placement), surfaced a hidden Limits zero-value decision, removed a
  task-shaped AC, added missing no-fs composition coverage.
- software-architect: confirmed the buildAgentDefEngine split and the
  new AgentDefSessionEngineFactory's shape, flagged a 15-argument
  positional-prefix duplication risk and a provider/model resolver
  delegation opportunity for the eventual implementation.
- secure-code-reviewer: found a CRITICAL, code-verified guardrail
  bypass (a definition hook's mutated payload is never re-inspected
  by the guardrail checker today) and a HIGH-severity mistargeted
  fail-closed guard (the real choke point is
  needsRehydration()/engineAndEnvironmentFor, not rehydrateSession,
  and RetryFailedRun/CompactSession/resumeFromAwaiting share the same
  exposure) - both now explicit ACs and human decisions.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

This branch was successfully deployed

1 active deployment
Preview — 4e6fa7eb Deployed Sep 23, 2026 by vercel[bot]
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.

2 participants