Repository navigation
models: add model source registry - #627
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Client-declared BYOK endpoints and cross-client credential retention warrant human architecture review because endpoint-policy enforcement, credential isolation, and erasure depend on host/agent implementations outside this PR.
No open issues 🎉
What changed in this PR
Implements #622’s model source customizations proposal on top of #543’s model catalogs. Clients can contribute bring-your-own-key model sources through plugins, deliver credentials through authenticate, and select their models within a session.
Changes:
- Adds model source lifecycle types, sharing and retention policies, and a scoped authentication target.
- Updates native generators, client models, reducers, and schemas, with shared round-trip and reducer fixtures.
- Documents credential handling, model selection, and migration requirements without adding commands or bumping the protocol version.
| File | Description |
|---|---|
types/test-cases/round-trips/105-model-source-sharing-retention.json |
Covers published policies and an empty model catalog. |
types/test-cases/round-trips/104-active-client-child-model-sources.json |
Covers client policy options and defaults. |
types/test-cases/round-trips/103-authenticate-model-source-target.json |
Covers targeted credential delivery. |
types/test-cases/round-trips/102-model-source-customization-states.json |
Covers all four lifecycle states. |
types/test-cases/reducers/332-session-customizationremoved-model-source-child.json |
Covers removal while preserving siblings. |
types/test-cases/reducers/331-session-customizationtoggled-model-source-clears-enablement.json |
Covers clearing explicit enablement. |
types/test-cases/reducers/330-session-customizationtoggled-plugin-model-source.json |
Covers setting explicit enablement. |
types/common/state.ts |
Documents model source endpoint scheme exceptions. |
types/common/commands.ts |
Adds the model source authentication target and credential contract. |
types/channels-session/state.ts |
Defines model source customizations, lifecycle, and policies. |
types/channels-session/reducer.ts |
Applies scoped enablement to model sources. |
types/channels-session/actions.ts |
Clarifies model source toggle documentation. |
types/channels-root/state.ts |
Documents session model identity and source references. |
scripts/read-stability.test.ts |
Updates the expected generated stability marker count. |
scripts/generate-swift.ts |
Registers Swift model source types and unions. |
scripts/generate-rust.ts |
Registers Rust types, unions, and the auth reason import. |
scripts/generate-kotlin.ts |
Registers Kotlin model source types and unions. |
scripts/generate-go.ts |
Registers Go model source types and unions. |
scripts/generate-csharp.ts |
Registers C# model source types and unions. |
schema/state.schema.json |
Adds model source state definitions. |
schema/notifications.schema.json |
Includes model sources in notification state schemas. |
schema/actions.schema.json |
Includes model sources in action payload schemas. |
docs/specification/root-channel.md |
Defines session model selection and reserved IDs. |
docs/specification/authentication.md |
Specifies credential isolation, revocation, and recovery. |
docs/guide/customizations.md |
Explains lifecycle, enablement, sharing, and retention. |
docs/.changes/20261123-model-source-customizations.json |
Records the new protocol feature. |
docs/.changes/20261123-model-source-customizations-migration.json |
Records exhaustive-match and Rust literal migrations. |
clients/swift/AgentHostProtocol/Sources/AgentHostProtocol/NativeReducer.swift |
Handles model source IDs and enablement. |
clients/swift/AgentHostProtocol/Sources/AgentHostProtocol/Generated/Commands.generated.swift |
Adds generated authentication target support. |
clients/rust/crates/ahp/src/reducers.rs |
Handles model source IDs and enablement. |
clients/rust/crates/ahp-types/src/state.rs |
Adds generated lifecycle, customization, and policy models. |
clients/rust/crates/ahp-types/src/commands.rs |
Adds generated authentication target support. |
clients/rust/crates/ahp-types/src/actions.rs |
Mirrors updated toggle documentation. |
clients/kotlin/src/main/kotlin/com/microsoft/agenthostprotocol/Reducers.kt |
Handles model source IDs and enablement. |
clients/kotlin/src/main/kotlin/com/microsoft/agenthostprotocol/generated/State.generated.kt |
Adds generated models and lifecycle serialization. |
clients/kotlin/src/main/kotlin/com/microsoft/agenthostprotocol/generated/Commands.generated.kt |
Adds authentication target models and serialization. |
clients/go/ahptypes/state.generated.go |
Adds generated models and lifecycle serialization. |
clients/go/ahptypes/commands.generated.go |
Adds authentication target models and serialization. |
clients/go/ahptypes/actions.generated.go |
Mirrors updated toggle documentation. |
clients/go/ahp/reducers.go |
Handles model source IDs and enablement. |
clients/dotnet/src/AgentHostProtocol/Reducers.cs |
Handles model source IDs and enablement. |
clients/dotnet/src/AgentHostProtocol.Abstractions/Generated/JsonSerializerContext.generated.cs |
Registers new models for source-generated serialization. |
clients/dotnet/src/AgentHostProtocol.Abstractions/Generated/Commands.generated.cs |
Adds authentication target records and converter registration. |
clients/dotnet/src/AgentHostProtocol.Abstractions/Generated/Actions.generated.cs |
Mirrors updated toggle documentation. |
.github/instructions/protocol-naming.instructions.md |
Defines model source and contributing client terminology. |
Review effort: Balanced
…ations' into lramos15/model-source-customizations-impl
Implements the host-wide model source registry from the model source registry proposal (#622): - `RootState.modelSourceRegistrations` with `ModelSourceRegistration`, its sharing and retention policies, and the `starting`, `ready`, `authRequired`, and `error` states. - Client-dispatchable `root/modelSourceRegistrationSet` and `root/modelSourceRegistrationRemoved` actions (introduced in 1.2.0) with root reducers in TypeScript and every client. - `AgentCapabilities.modelSourceRegistration` listing the definition formats an agent reads. - A `modelSource` `authenticate` target for delivering a registered source's credential. - Generator registration, reducer and round-trip fixtures, spec and naming docs, and changelog fragments. Refs #619 Co-authored-by: Copilot <[email protected]>
29c5961 to
0ae73ce
Compare
Co-authored-by: Copilot <[email protected]>
…20261022' into lramos15/model-source-customizations-impl
…ations' into lramos15/model-source-customizations-impl
- `ModelSourceRegistration.credentialNonce` and the required `ModelSourceAuthenticateTarget.credentialNonce`, so a delayed `authenticate` can't reach a changed definition. The host rejects a stale nonce with `Conflict`. - Specs follow #622: `Removed` is checked only against the stored registration, status updates are built from the current registration, revocation reports `reason: expired`, moving the endpoint mints new model IDs, clients send a stored secret only when the definition matches their copy, and the host writes status text and errors itself. - Untargeted model source credentials are rejected with `InvalidParams`, and `ProtectedResourceMetadata.resource` notes the model source scheme exception. - Renumber the registry round-trip fixtures after main's new fixture, align the Azure fixture's resource with its endpoint, and note the TypeScript `AuthenticateTarget` narrowing in the migration fragment. Refs #619 Co-authored-by: Copilot <[email protected]>
…ations' into lramos15/model-source-customizations-impl
- Remove `ModelSourceSharingPolicy`, the `sharing` field, takeover, and
the ownership checks on `Set`, `Removed`, and credential delivery.
Any client may change or remove any registration and deliver or
revoke its credential. `clientId` records who last wrote it.
- Add the host-only `root/modelSourceStateChanged { id, state,
credentialNonce }` action, modeled on `session/mcpServerStateChanged`,
with reducers in TypeScript and every client. It is a no-op for an
unknown `id` and changes only `state` and `credentialNonce`.
- Only a change to `provider`, `format`, or `definition` drops the
credential. The host issues a new nonce on every credential install
or drop and ignores failures from requests made with an older key.
- Automations may use registrations with `host` retention, or ones the
host registered.
- Update the specs, naming dictionary, fixtures, and changelog.
Refs #619
Co-authored-by: Copilot <[email protected]>
…ations' into lramos15/model-source-customizations-impl
…ations' into lramos15/model-source-customizations-impl
Once a registration has been ready, the host keeps its models in the catalog through `starting` and `authRequired`, and withdraws them on removal, when the contributing client leaves under `contributingClient` retention, on `error`, or when a change mints new model IDs. A turn that starts without a usable credential ends with a resumable error. The snapshot fixture now lists the models of a source whose key expired. Refs #619 Co-authored-by: Copilot <[email protected]>
…ations' into lramos15/model-source-customizations-impl
- `ModelSourceRegistration.credentialResource` is host-reported RFC 9728 metadata for the endpoint the credential is for, kept in every state while the source takes a credential. `ModelSourceAuthRequirement` keeps only `reason` and `description`. - `root/modelSourceStateChanged` gains an optional `credentialResource` and sets it with `state` and `credentialNonce`. Absent clears it. Reducers in TypeScript and every client follow. - A client-dispatched `Set` must not include `credentialResource`, and `authenticate` matches `resource` against it. - `credentialNonce` is the registration's generation: the host issues a new one when a registration is added or its provider, format, or definition changes, and discards any agent result tagged with an older one. - Box the Rust `RootModelSourceRegistrationSet` variant, since the larger registration trips `large_enum_variant`. Refs #619 Co-authored-by: Copilot <[email protected]>
Address review feedback on #627: - Rename `ModelSourceRegistration.name` to `displayName`. The naming dictionary reserves `name` for stable or machine-oriented names, and the field is published as `ModelSourceInfo.displayName`. - Point the authentication spec's Token Delivery paragraph at `ModelSourceRegistration.credentialResource.resource`, since `ModelSourceAuthRequiredState` no longer carries a resource. Refs #619 Co-authored-by: Copilot <[email protected]>
…/model-source-customizations-impl
…istry Implement the reworked registry from #622: - `ModelSourceRegistration.contributingClientIds` replaces `clientId`. `root/modelSourceRegistrationSet` gains `clientId` and adds, joins an unchanged routing (keeping every host-reported field), or replaces a changed one. Definitions compare as JSON values, ignoring key order and comparing numbers by value. The new client-dispatchable `root/modelSourceContributorRemoved` withdraws one contribution. - Host-reported `credentialOrigins` and `credentialId` on the registration and on `root/modelSourceStateChanged`, and an optional `credentialId` on the `modelSource` authenticate target. - `ModelSourceAuthRequiredReason` (required, expired, rejected, revoked) replaces the shared `AuthRequiredReason` for model sources. - `ModelSourceRegistrationCapability` gains `gracePeriod` and `principalPolicy` (`ModelSourcePrincipalPolicy`: shared, isolated). - `ErrorInfo.errorType` documents the well-known `modelSourceUnavailable` value. - Reducers in TypeScript and every client, regenerated fixtures for every branch, and the root channel, authentication, naming, and guide docs. Refs #619 Co-authored-by: Copilot <[email protected]>
…ations' into lramos15/model-source-customizations-impl
Replace the private direct-routing path (a credential call on the local BYOK channel plus agent/runtime model id translation) with the Agent Host Protocol model source registry, so local and remote agent hosts share one path. - Sync the protocol types to the pre-release microsoft/agent-host-protocol#627 (on #543), and narrow `authenticate` targets that are not MCP servers. - Host: a model source registry validates `root/modelSourceRegistrationSet` and `Removed`, reports status with `root/modelSourceStateChanged`, holds credentials delivered with a `modelSource` target in memory, fences them with a nonce, and removes a departed client's `contributingClient` sources. - Copilot agent: reads the `code.visualstudio.com/custom-endpoint@1` format, publishes each source's models with `modelSourceId`, and registers them on live sessions as host-owned providers that replace earlier ones on sync. Model ids are the runtime selection ids, bound to the registration, endpoint, and upstream model. - Window: registers eligible Custom Endpoint groups with every connected host that reads the format, and answers key requests; the bridge stops listing those models. Co-authored-by: Copilot <[email protected]>
Implement #622's response to review: - Rename `RootState.modelSourceRegistrations` to `modelSources`, `ModelSourceRegistration` to `ModelSource`, and the actions to `root/modelSourceSet` and `root/modelSourceRemoved`. - Drop client IDs from the registry: no `contributingClientIds`, no `clientId` on `Set`, and no `root/modelSourceContributorRemoved`. The host tracks contributing clients from `ActionEnvelope.origin`. - `root/modelSourceSet` carries `{ modelSource, definition }`, and the reducer stores the source without the definition. `ModelSource` gains a required `nonce`. Reducers compare provider, format, and nonce to tell a re-registration from an update, replacing the JSON comparison of definitions in TypeScript and every client. - Replace `credentialId` with `authenticate`'s existing `accountId`, published as `ModelSource.accountId`. - Document recognized `format` values (`openaiCompatible`, `anthropic`, `azureOpenai`, `gemini`) and built-in sources. - Regenerate clients, replace the reducer fixtures with one per branch, and update the round-trip fixtures, specs, naming dictionary, guide, and changelog fragments. Refs #619 Co-authored-by: Copilot <[email protected]>
Replace the private direct-routing path (a credential call on the local BYOK channel plus agent/runtime model id translation) with the Agent Host Protocol model source registry, so local and remote agent hosts share one path. - Sync the protocol types to the pre-release microsoft/agent-host-protocol#627 (on #543), and narrow `authenticate` targets that are not MCP servers. - Host: a model source registry validates `root/modelSourceRegistrationSet` and `Removed`, reports status with `root/modelSourceStateChanged`, holds credentials delivered with a `modelSource` target in memory, fences them with a nonce, and removes a departed client's `contributingClient` sources. - Copilot agent: reads the `code.visualstudio.com/custom-endpoint@1` format, publishes each source's models with `modelSourceId`, and registers them on live sessions as host-owned providers that replace earlier ones on sync. Model ids are the runtime selection ids, bound to the registration, endpoint, and upstream model. - Window: registers eligible Custom Endpoint groups with every connected host that reads the format, and answers key requests; the bridge stops listing those models. Co-authored-by: Copilot <[email protected]>
…ations' into lramos15/model-source-customizations-impl
|
Heads-up: #543 gained 6199969a from Connor's review. It adds a general rule that model IDs are stable: a host SHOULD keep a model's ID across catalog updates and MUST NOT reuse an ID for a different source or upstream model, even after the model leaves Merging #543's branch into this one conflicts in one handwritten spot, the * Model identifier, unique within the agent's {@link AgentInfo.models}.
* When several model sources serve the same upstream model, the host gives
* each entry its own ID. A host SHOULD keep a model's ID across catalog
* updates and MUST NOT reuse an ID for a different source or upstream model.
* An ID the host publishes for a registered model source stays bound to that
* registration and upstream model.
*
* @see {@link /specification/root-channel#reserved-model-ids | Reserved model IDs}The registered-source sentence is now mostly covered by the general rule and the linked section, so it could also be dropped. |
Implements #622 at f30b11a: - `ModelSource.definition` is back in state, with suggested shapes for the recognized formats documented on it. `root/modelSourceSet` carries only `modelSource`. Reducers still compare `provider`, `format`, and `nonce`. - Remove `credentialNonce` and `credentialOrigins` from `ModelSource`, `root/modelSourceStateChanged`, and the `modelSource` authenticate target. - `ModelSourceRegistrationCapability.formats` lists `ModelSourceFormatInfo` objects. Remove `gracePeriod`, `principalPolicy`, and `ModelSourcePrincipalPolicy`, which are now host policy. Updates the generators, client reducers, fixtures, specs, naming dictionary, and changelog fragment to match. Co-authored-by: Copilot <[email protected]>
…20261022' into lramos15/model-source-customizations-impl # Conflicts: # clients/dotnet/src/AgentHostProtocol.Abstractions/Generated/State.generated.cs # clients/go/ahptypes/state.generated.go # clients/kotlin/src/main/kotlin/com/microsoft/agenthostprotocol/generated/State.generated.kt # clients/rust/crates/ahp-types/src/state.rs # clients/swift/AgentHostProtocol/Sources/AgentHostProtocol/Generated/State.generated.swift # schema/actions.schema.json # schema/commands.schema.json # schema/errors.schema.json # schema/notifications.schema.json # schema/state.schema.json # types/channels-root/state.ts
…27 at a4a01c06 Sync the protocol from microsoft/agent-host-protocol#627 at a4a01c06, which implements #622 after its second review round: - The definition is part of the model source: root/modelSourceSet carries only the source, and the reducer keeps the definition in root state. - Credential nonces, credentialOrigins, the capability's gracePeriod and principalPolicy are gone, and formats are { format } objects. The host no longer issues nonces: a later delivery replaces the key it holds, and a lease only lapses for the key it was delivered with. The window checks the host's copy of the definition before sending a key: every endpoint the key reaches must be one its own copy sends it to, whatever the nonce. It checks again after reading the key, since the source may have changed meanwhile. Co-authored-by: Copilot <[email protected]>
…-customizations-impl
- `RootState.modelSources` now lists every model source, including an agent's built-in ones. Remove `ModelSourceInfo` and `AgentInfo.modelSources`; `SessionModelInfo.modelSourceId` names a root source whose `provider` is the model's agent. `format`, `definition`, and `nonce` are optional, present on registered sources. - Add `AhpErrorCodes.ModelSourceUnavailable` (-32013) for requests that select a model whose registered source can't serve it. - Revert model-source wording in the shared `authenticate`, `ProtectedResourceMetadata`, and authentication docs, and drop the new empty-token revocation rules. - Describe format names as conventions some agents may read, not values AHP recognizes. - Keep `@preserveUnknownMembers` only on `ModelSource`, the one new root type clients send. - Cut the root channel and authentication spec sections to their normative rules. Co-authored-by: Copilot <[email protected]>
Fold the reducer branches, rejection rules, status values, and retention values into short sentences. The type docs and reference pages already list them. Co-authored-by: Copilot <[email protected]>
…27 at 6a80f578 Sync the protocol from microsoft/agent-host-protocol#627 at 6a80f578, which targets main now that #543 and #622 are merged: - ModelSourceInfo and AgentInfo.modelSources are gone: root state lists every model source, so the host stops publishing a catalog per agent. - format, definition and nonce are optional on ModelSource. The host rejects a client registration without any of them, and a model counts as the user's own when its root source has a definition. - A request that selects a model whose registered source can't serve it fails with AhpErrorCodes.ModelSourceUnavailable (-32013). Co-authored-by: Copilot <[email protected]>
Follow the MCP split between specification and guide: - Add `guide/model-sources.md`, with registration, status, credentials, retention, and unavailable sources, and list it in the guide sidebar. - Keep the model source rules in the root channel spec, and move the rejection rules into a "Server Validation of Client Actions" table like the session and chat channels have. - Keep the `modelSource` target and credential handling rules in the authentication spec, and move the reasons and client delivery guidance to the guide. - Point the type docs at the guide. Co-authored-by: Copilot <[email protected]>
…-customizations-impl # Conflicts: # clients/rust/crates/ahp-types/src/actions.rs # clients/rust/crates/ahp/src/reducers.rs # scripts/generate-rust.ts # scripts/read-stability.test.ts
…-customizations-impl # Conflicts: # docs/.changes/20261022-model-source-selection.json
- Add optional `ErrorInfo.errorCode?: AhpErrorCode`. A turn whose model source can't serve it carries `ModelSourceUnavailable` (-32013) there. Generators map `AhpErrorCode` to their integer type, and the JSON Schema types it as an integer. - Rename `id` to `modelSourceId` on `root/modelSourceRemoved` and `root/modelSourceStateChanged`. - Drop `@preserveUnknownMembers` from `ModelSource`, which clients don't round-trip, and apply the doc suggestions. Co-authored-by: Copilot <[email protected]>
Follow the automation pattern, per review: - Clients dispatch `root/modelSourceRegisterRequested`, whose reducer leaves state unchanged. The host publishes every source and status change with `root/modelSourceSet`, now host-only and a plain replace, and `root/modelSourceStateChanged` is removed. - Group `format`, `definition`, and `retention` in `ModelSource.registration`, drop `nonce`, and make `state` required. Hosts compare definitions themselves. - Update the generators, client reducers, fixtures, guide, specs, naming dictionary, changelog, and the proposal's status. Co-authored-by: Copilot <[email protected]>
`retention` tells the host what to do when contributing clients leave, and no consumer acts on it, so move it from `ModelSourceRegistration` to `root/modelSourceRegisterRequested`. The host keeps it privately. Co-authored-by: Copilot <[email protected]>
…source registration Registration now follows the automation pattern. The window dispatches root/modelSourceRegisterRequested, and only the host publishes a source, with root/modelSourceSet, for every change including its status. ModelSource moves format, definition and retention into `registration`, has no nonce, and always has a state. root/modelSourceRemoved takes modelSourceId, and root/modelSourceStateChanged is gone. - Host: the registry keeps each registered source and publishes it whole. It compares the format and definition itself, so an unchanged registration keeps its status and key, and publishes before confirming the request. - Window: compares the host's registration with its own copy through a local definition key, and waits for a host that confirms a request before publishing the source. - Turns on an unavailable source end with errorCode ModelSourceUnavailable. The protocol is synced from #627's own changes applied to the AHP base this branch already used (745899da), without AHP main's deferred turns (#620) and search channel (#629), which VS Code main hasn't adopted. Co-authored-by: Copilot <[email protected]>
A host may publish `root/modelSourceSet` before or after it confirms `root/modelSourceRegisterRequested`, so clients wait for the source rather than reading a confirmed request as the source being in state. Co-authored-by: Copilot <[email protected]>
…source retention Retention is now only on root/modelSourceRegisterRequested, beside `registration`, and no longer in state. The window sends it there. The host keeps each source's retention privately from the latest request, uses it when the last contributor leaves, and still declines a retention it won't honor. Synced as before: #627's own change (git diff 2b520a36 cddbc7e7 -- types/) on top of the previous local tree based on AHP 745899da. Co-authored-by: Copilot <[email protected]>


Refs #619
Implements the model source registry proposed in #622 (proposal), on top of #543's model sources. Both have merged.
What it adds, all introduced in protocol 1.2.0, with no version bump:
RootState.modelSourceslists everyModelSource, including an agent's built-in ones, replacing models: add model sources to agent catalogs #543'sModelSourceInfoandAgentInfo.modelSources. Each has a requiredstate. A registered source also has aregistrationwith itsformatanddefinition, plus credential fields. Its retention policy is sent on the registration request and kept by the host.root/modelSourceRegisterRequestedandroot/modelSourceRemoved, from clients. The request doesn't change state.root/modelSourceSet, from the host only, publishes every source and status change.AgentCapabilities.modelSourceRegistrationlists the formats the agent reads, asModelSourceFormatInfoobjects.modelSourcetarget forauthenticate, andAhpErrorCodes.ModelSourceUnavailable(-32013) for requests and turns, carried on turns by the newErrorInfo.errorCode.The canonical types and reducer are in
types/. Every client gets a reducer, tested with shared fixtures, and all five generators register the new types. A new Model Sources guide covers the details, and the root channel and authentication specs, the naming dictionary, and the changelog fragments are updated. Most of the diff is generated code.Review changed some shapes from the proposal; its Status section lists the differences. The proposal's open questions (§9) stay open.
Validation
npm run generate(run twice)npm testcd clients/typescript && npm ci && npm test && npm run buildcd clients/rust && cargo fmt --all -- --check && cargo clippy --workspace --all-targets -- -D warnings && cargo test --workspacecd clients/go && gofmt -l . && go vet ./... && go test ./..../gradlew build(Kotlin, ineclipse-temurin:17-jdk)dotnet format whitespace --verify-no-changes && dotnet build -c Release && dotnet test -c Release(indotnet/sdk:10.0)swift build && swift testnpm run generate:docs && npm run docs:versions && npx vitepress build docs