Skip to content

feat(appkit): fromPlugin() DX, runAgent plugins arg, shared toolkit-resolver#305

Open
MarioCadenas wants to merge 1 commit intoagent/v2/4-agents-pluginfrom
agent/v2/5-fromplugin-runagent
Open

feat(appkit): fromPlugin() DX, runAgent plugins arg, shared toolkit-resolver#305
MarioCadenas wants to merge 1 commit intoagent/v2/4-agents-pluginfrom
agent/v2/5-fromplugin-runagent

Conversation

@MarioCadenas
Copy link
Copy Markdown
Collaborator

@MarioCadenas MarioCadenas commented Apr 21, 2026

DX centerpiece. Introduces the symbol-marker pattern that collapses
plugin tool references in code-defined agents from a three-touch dance
to a single line, and extracts the shared resolver that the agents
plugin, auto-inherit, and standalone runAgent all now go through.

fromPlugin(factory, opts?) — the marker

packages/appkit/src/plugins/agents/from-plugin.ts. Returns a spread-
friendly { [Symbol()]: FromPluginMarker } record. The symbol key is
freshly generated per call, so multiple spreads of the same plugin
coexist safely. The marker's brand is a globally-interned
Symbol.for("@databricks/appkit.fromPluginMarker") — stable across
module boundaries.

resolveToolkitFromProvider(pluginName, provider, opts?)

packages/appkit/src/plugins/agents/toolkit-resolver.ts. Single source
of truth for "turn a ToolProvider into a keyed record of ToolkitEntry
markers". Prefers provider.toolkit(opts) when available (core plugins
implement it), falls back to walking getAgentTools() and synthesizing
namespaced keys (${pluginName}.${localName}) for third-party
providers, honoring only / except / rename / prefix the same
way.

Used by three call sites, previously all copy-pasted:

  1. AgentsPlugin.buildToolIndex — fromPlugin marker resolution pass
  2. AgentsPlugin.applyAutoInherit — markdown auto-inherit path
  3. runAgent — standalone-mode plugin tool dispatch

AgentsPlugin.buildToolIndex — symbol-key resolution pass

Before the existing string-key iteration, buildToolIndex now walks
Object.getOwnPropertySymbols(def.tools). For each FromPluginMarker,
it looks up the plugin by name in PluginContext.getToolProviders(),
calls resolveToolkitFromProvider, and merges the resulting entries
into the per-agent index. Missing plugins throw at setup time with a
clear Available: ... listing — wiring errors surface on boot, not
mid-request.

hasExplicitTools now counts symbol keys too, so a
tools: { ...fromPlugin(x) } record correctly disables auto-inherit
on code-defined agents.

Type plumbing

  • AgentTools type: { [key: string]: AgentTool } & { [key: symbol]: FromPluginMarker }. Preserves string-key autocomplete while
    accepting marker spreads under strict TS.
  • AgentDefinition.tools switched to AgentTools.

runAgent gains plugins?: PluginData[]

packages/appkit/src/core/run-agent.ts. When an agent def contains
fromPlugin markers, the caller passes plugins via
RunAgentInput.plugins. A local provider cache constructs each plugin
and dispatches tool calls via provider.executeAgentTool(). Runs as
service principal (no OBO — there's no HTTP request). If a def
contains markers but plugins is absent, throws with guidance.

Exports

fromPlugin, FromPluginMarker, isFromPluginMarker, AgentTools
added to the main barrel.

Test plan

  • 14 new tests: marker shape, symbol uniqueness, type guard,
    factory-without-pluginName error, fromPlugin marker resolution in
    AgentsPlugin, fallback to getAgentTools for providers without
    .toolkit(), symbol-only tools disables auto-inherit, runAgent
    standalone marker resolution via plugins arg, guidance error when
    missing.
  • Full appkit vitest suite: 1311 tests passing.
  • Typecheck clean.

Signed-off-by: MarioCadenas MarioCadenas@users.noreply.github.com

PR Stack

  1. Shared agent types + LLM adapters — feat(appkit): shared agent types and LLM adapter implementations #301
  2. Tool primitives + ToolProvider surfaces — feat(appkit): tool primitives and ToolProvider surfaces on core plugins #302
  3. Plugin infrastructure (attachContext + PluginContext) — feat(appkit): plugin infrastructure — attachContext + PluginContext mediator #303
  4. agents() plugin + createAgent(def) + markdown-driven agents — feat(appkit): agents() plugin, createAgent(def), and markdown-driven agents #304
  5. fromPlugin() DX + runAgent plugins arg + toolkit-resolver (this PR)
  6. Reference app + dev-playground + docs — feat(appkit): reference agent-app, dev-playground chat UI, docs, and template #306

This 6-PR stack is a redesign of the earlier 13-PR stack (#282-#286, #293-#300), reorganized to eliminate mid-stack API churn. Reviewers never see code in this stack that later PRs delete. The old 13 PRs have been closed with references back here.

This was referenced Apr 21, 2026
@MarioCadenas MarioCadenas force-pushed the agent/v2/4-agents-plugin branch from 3c7c35e to cb7fe2b Compare April 21, 2026 20:41
@MarioCadenas MarioCadenas force-pushed the agent/v2/5-fromplugin-runagent branch from 162e970 to 29e3534 Compare April 21, 2026 20:41
@MarioCadenas MarioCadenas force-pushed the agent/v2/4-agents-plugin branch from cb7fe2b to 0afea5e Compare April 22, 2026 08:45
@MarioCadenas MarioCadenas force-pushed the agent/v2/5-fromplugin-runagent branch from 29e3534 to b462716 Compare April 22, 2026 08:45
@MarioCadenas MarioCadenas force-pushed the agent/v2/4-agents-plugin branch from 0afea5e to 983461c Compare April 22, 2026 09:24
@MarioCadenas MarioCadenas force-pushed the agent/v2/5-fromplugin-runagent branch 2 times, most recently from 539487e to dac73b5 Compare April 22, 2026 09:46
@MarioCadenas MarioCadenas force-pushed the agent/v2/4-agents-plugin branch 2 times, most recently from a7b0444 to 623792d Compare April 22, 2026 09:59
@MarioCadenas MarioCadenas force-pushed the agent/v2/5-fromplugin-runagent branch 2 times, most recently from 624f2a0 to 0dd07a4 Compare April 22, 2026 10:21
@MarioCadenas MarioCadenas force-pushed the agent/v2/4-agents-plugin branch from 623792d to 2f752a0 Compare April 22, 2026 10:21
@MarioCadenas MarioCadenas force-pushed the agent/v2/4-agents-plugin branch from 2f752a0 to dd583ad Compare April 22, 2026 10:49
@MarioCadenas MarioCadenas force-pushed the agent/v2/5-fromplugin-runagent branch 2 times, most recently from becc889 to f290fe5 Compare April 22, 2026 12:20
@MarioCadenas MarioCadenas force-pushed the agent/v2/4-agents-plugin branch 2 times, most recently from 11981f7 to acb9094 Compare April 22, 2026 15:49
@MarioCadenas MarioCadenas force-pushed the agent/v2/5-fromplugin-runagent branch from f290fe5 to a02bacf Compare April 22, 2026 15:49
…esolver

DX centerpiece. Introduces the symbol-marker pattern that collapses
plugin tool references in code-defined agents from a three-touch dance
to a single line, and extracts the shared resolver that the agents
plugin, auto-inherit, and standalone runAgent all now go through.

`packages/appkit/src/plugins/agents/from-plugin.ts`. Returns a spread-
friendly `{ [Symbol()]: FromPluginMarker }` record. The symbol key is
freshly generated per call, so multiple spreads of the same plugin
coexist safely. The marker's brand is a globally-interned
`Symbol.for("@databricks/appkit.fromPluginMarker")` — stable across
module boundaries.

`packages/appkit/src/plugins/agents/toolkit-resolver.ts`. Single source
of truth for "turn a ToolProvider into a keyed record of `ToolkitEntry`
markers". Prefers `provider.toolkit(opts)` when available (core plugins
implement it), falls back to walking `getAgentTools()` and synthesizing
namespaced keys (`${pluginName}.${localName}`) for third-party
providers, honoring `only` / `except` / `rename` / `prefix` the same
way.

Used by three call sites, previously all copy-pasted:
1. `AgentsPlugin.buildToolIndex` — fromPlugin marker resolution pass
2. `AgentsPlugin.applyAutoInherit` — markdown auto-inherit path
3. `runAgent` — standalone-mode plugin tool dispatch

Before the existing string-key iteration, `buildToolIndex` now walks
`Object.getOwnPropertySymbols(def.tools)`. For each `FromPluginMarker`,
it looks up the plugin by name in `PluginContext.getToolProviders()`,
calls `resolveToolkitFromProvider`, and merges the resulting entries
into the per-agent index. Missing plugins throw at setup time with a
clear `Available: ...` listing — wiring errors surface on boot, not
mid-request.

`hasExplicitTools` now counts symbol keys too, so a
`tools: { ...fromPlugin(x) }` record correctly disables auto-inherit
on code-defined agents.

- `AgentTools` type: `{ [key: string]: AgentTool } & { [key: symbol]:
  FromPluginMarker }`. Preserves string-key autocomplete while
  accepting marker spreads under strict TS.
- `AgentDefinition.tools` switched to `AgentTools`.

`packages/appkit/src/core/run-agent.ts`. When an agent def contains
`fromPlugin` markers, the caller passes plugins via
`RunAgentInput.plugins`. A local provider cache constructs each plugin
and dispatches tool calls via `provider.executeAgentTool()`. Runs as
service principal (no OBO — there's no HTTP request). If a def
contains markers but `plugins` is absent, throws with guidance.

`fromPlugin`, `FromPluginMarker`, `isFromPluginMarker`, `AgentTools`
added to the main barrel.

- 14 new tests: marker shape, symbol uniqueness, type guard,
  factory-without-pluginName error, fromPlugin marker resolution in
  AgentsPlugin, fallback to getAgentTools for providers without
  .toolkit(), symbol-only tools disables auto-inherit, runAgent
  standalone marker resolution via `plugins` arg, guidance error when
  missing.
- Full appkit vitest suite: 1311 tests passing.
- Typecheck clean.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
@MarioCadenas MarioCadenas force-pushed the agent/v2/4-agents-plugin branch from acb9094 to 807142c Compare April 22, 2026 16:19
@MarioCadenas MarioCadenas force-pushed the agent/v2/5-fromplugin-runagent branch from a02bacf to a15aa42 Compare April 22, 2026 16:19
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