AgentsKit Chat Alpha
Architecture/Adrs

ADR-0002: Upstream-first and no reimplementation

View canonical Markdown

ADR-0002: Upstream-first and no reimplementation

Status: Accepted

Date: 2026-07-10

Context

AgentsKit Chat is an application framework built on AgentsKit. AgentsKit already owns the chat controller, lifecycle, framework bindings, generative UI primitives, tools, confirmation, memory, RAG, runtime, replay, eval, and observability contracts.

Without an explicit dependency rule, AgentsKit Chat could accidentally create parallel implementations with slightly different types and behavior. That would weaken interoperability, split fixes between repositories, and make the dogfood claim false.

Decision

AgentsKit Chat follows an upstream-first rule:

  1. Search the current AgentsKit source and public API before designing or implementing a primitive.
  2. Reuse an existing AgentsKit contract directly when it satisfies the requirement.
  3. Adapt or compose the contract inside AgentsKit Chat when only application-level policy or developer experience is missing.
  4. If a framework-neutral primitive is missing or defective, change it in AgentsKit-io/agentskit first, with its own issue, ADR when required, tests, release, and compatibility path.
  5. Consume the released upstream API from AgentsKit Chat. Do not copy source, fork behavior, vendor private files, or depend on unpublished workspace paths.

AgentsKit Chat may own a new contract only when it is specific to the application-framework layer and cannot be useful independently of that layer. The issue or ADR introducing it must document why composition of existing AgentsKit APIs is insufficient.

Ownership matrix

ConcernOwnerAgentsKit Chat rule
Model adapters and model invocationAgentsKitConfigure and consume; never wrap provider protocols independently.
Chat state and lifecycleAgentsKit ChatControllerdefineChat compiles to or derives ChatConfig; never create a parallel controller.
Streaming, stop, retry, edit, regenerateAgentsKitTransport existing lifecycle semantics; do not redefine them.
Tools and execution loopAgentsKit ToolDefinition and runtimeApplication actions compile to tools plus trusted policy metadata; no second executor.
Tool argument validationAgentsKit validation seamSupply validators and schemas; fix generic validation gaps upstream.
Human confirmationAgentsKit tool confirmation and HITL primitivesAdd product policy, identity, expiry, and audit by composition.
Generative UI primitivesAgentsKit UIMessage and UIElementReuse for the standard portable element set; extend only through an application component registry.
Chat message memoryAgentsKit ChatMemoryReuse for messages; session envelopes store only application metadata not represented upstream.
RAG and retrievalAgentsKitConfigure retrievers and render retrieved-source metadata.
Replay and eval primitivesAgentsKitCompose application traces and renderer conformance around upstream fixtures.
Framework hooks and storesAgentsKit renderer packagesEach native renderer consumes its corresponding package directly.
Deterministic application routesAgentsKit ChatOwn because they coordinate application behavior before model dispatch.
Conversation statechartsAgentsKit Chat unless generalized upstreamOwn application transitions; promote a generally useful primitive upstream before reuse.
Application authorization and policyHost application + AgentsKit Chat seamKeep authority outside the model and outside low-level AgentsKit primitives.
Custom component registryAgentsKit ChatOwn semantic component identity, runtime props validation, native implementations, and fallback.
Client-server application protocolAgentsKit ChatTransport upstream lifecycle plus application events; do not rename or alter upstream semantics.
CLI and project scaffoldingAgentsKit ChatGenerate composition around published AgentsKit packages.

Required issue evidence

Every implementation issue must include an Upstream adoption section containing:

  • AgentsKit source and exports inspected;
  • existing primitives reused;
  • application-layer behavior added;
  • upstream gap, if any, with a linked AgentsKit issue or PR;
  • explicit confirmation that no upstream source is copied or reimplemented.

Code review must reject a change when equivalent behavior already exists upstream or when a generally useful primitive is added locally without an upstream decision.

Source-change protocol

When an upstream change is required:

  1. Open or link an issue in AgentsKit-io/agentskit describing the primitive-level gap.
  2. Implement and test the fix in AgentsKit under its compatibility and ADR rules.
  3. Publish or otherwise make the supported upstream version available.
  4. Update AgentsKit Chat's declared compatibility range.
  5. Implement only the application-layer composition in this repository.

Temporary copied implementations and private cross-repository imports are forbidden, even behind feature flags. Work remains blocked until the supported upstream contract exists.

Consequences

  • AgentsKit remains the single source of truth for reusable agent and chat primitives.
  • AgentsKit Chat dogfoods published APIs rather than a privileged internal path.
  • Some AgentsKit Chat issues may block on upstream releases.
  • Cross-repository work is more explicit, but fixes benefit every AgentsKit consumer.
  • The application framework stays smaller and focuses on composition, policy, protocol, and developer experience.