Skip to content

refactor: extract shared protocol kernel into @agentic-kit/protocol#12

Merged
pyramation merged 3 commits into
mainfrom
refactor/extract-protocol-package
May 26, 2026
Merged

refactor: extract shared protocol kernel into @agentic-kit/protocol#12
pyramation merged 3 commits into
mainfrom
refactor/extract-protocol-package

Conversation

@yyyyaaa
Copy link
Copy Markdown
Contributor

@yyyyaaa yyyyaaa commented May 25, 2026

Summary

Extracts the duplicated protocol kernel — types, EventStream, and the usage/message/JSON/base-url helpers — into a new zero-dependency @agentic-kit/protocol leaf package, and points all four packages (the three provider adapters plus agentic-kit) at it. This replaces ~900 lines of byte-identical (and already drifting) copies with a single source of truth.

Why

The kernel was copy-pasted across agentic-kit and the three providers because of a dependency cycle: agentic-kit depends on the providers and registers them at module load, so the providers couldn't import back from agentic-kit. The copies had started to drift (e.g. ollama's Context had no tools field; no provider copy carried ToolCallContent.decision) — a latent correctness risk. A zero-dep leaf package that everything depends on breaks the cycle without inverting it.

Key properties

  • Public API preserved. agentic-kit still depends on all three providers, auto-registers them on module load, re-exports them, and owns createOpenAIKit / createAnthropicKit / createOllamaKit / createMultiProviderKit. import 'agentic-kit' behaves exactly as before — no consumer changes (apps/ is untouched).
  • Providers stay standalone. Each adapter depends only on the zero-dep kernel, so it remains independently installable.
  • Drift killed. Every provider now shares the canonical Context.tools, ToolCallContent.rawArguments, ToolCallContent.decision, and the full 12-field StreamOptions.

Net effect

~-819 source lines. anthropic 891→557, openai 966→621, ollama 738→501; kernel single-sourced at 600 lines in @agentic-kit/protocol.

Verification

  • Build 7/7 — topo order @agentic-kit/protocol → {openai, anthropic, ollama} → agentic-kit → agent → react
  • Tests 118 pass — protocol 7, agentic-kit 17, anthropic 1, openai 6, ollama 7, agent 45, react 35
  • Per-package tsc --noEmit clean; lint clean on all changed sources

Commits

  1. feat(protocol) — add the zero-dep package
  2. refactor(agentic-kit) — source the kernel from the package, drop local copies
  3. refactor(providers) — point openai/anthropic/ollama at the package

yyyyaaa added 3 commits May 25, 2026 16:31
Extract the shared protocol kernel — types, EventStream, and the
usage/message/JSON/base-url helpers — into a standalone leaf package
with no runtime dependencies, so every provider adapter can depend on it
without pulling in the framework. Establishes a single source of truth
for the contract that was previously copy-pasted across packages.
Drop the local kernel copies (types, event-stream, messages) and import
them from @agentic-kit/protocol, re-exporting the package so the public
surface is unchanged. agentic-kit still depends on all three providers,
auto-registers them on module load, and owns the createXKit helpers —
import 'agentic-kit' behaves exactly as before.
Point the openai, anthropic, and ollama adapters at @agentic-kit/protocol
instead of re-declaring the kernel locally, removing ~900 lines of
byte-identical and drifting copies. Each adapter now depends only on the
zero-dep kernel, so it stays independently installable, and all three
share the canonical Context.tools, ToolCallContent.rawArguments/decision,
and full StreamOptions.
@yyyyaaa yyyyaaa requested a review from pyramation May 25, 2026 09:36
@pyramation pyramation merged commit 070d904 into main May 26, 2026
12 checks passed
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