Skip to content

(WIP) Redesign agentic-kit core around structured streams and add minimal agent runtime#4

Open
yyyyaaa wants to merge 7 commits intomainfrom
feat/features-complete
Open

(WIP) Redesign agentic-kit core around structured streams and add minimal agent runtime#4
yyyyaaa wants to merge 7 commits intomainfrom
feat/features-complete

Conversation

@yyyyaaa
Copy link
Copy Markdown

@yyyyaaa yyyyaaa commented Apr 18, 2026

This PR rewrites agentic-kit from a thin text-generation adapter layer into a structured provider portability layer, and introduces a separate @agentic-kit/agent runtime package for
sequential tool execution.

The new architecture is based on the redesign decisions captured in REDESIGN_DECISIONS.md. It preserves a compatibility path for the existing AgentKit.generate() flow while establishing the
new long-term API around:

  • provider-independent model descriptors
  • structured message/content types
  • event-based streaming
  • model/provider registries
  • cross-provider message normalization
  • a minimal stateful agent loop as a separate package

Why

The repo was previously too thin to serve as a serious provider-agnostic foundation in Constructive.

Before this PR, the library mostly offered:

  • provider switching
  • prompt/messages passthrough
  • plain text streaming via chunk callbacks

It did not have:

  • a normalized message/content model
  • tool call protocol
  • reasoning/thinking content
  • usage/cost metadata
  • abort/stop semantics
  • cross-provider replay/handoff rules
  • a distinct agent runtime layer

This PR addresses those gaps systematically.

What Changed

Core agentic-kit redesign

Added new core modules in packages/agentic-kit/src/:

  • types.ts
  • event-stream.ts
  • messages.ts
  • model-registry.ts
  • provider-registry.ts
  • transform-messages.ts

These introduce:

  • ModelDescriptor
  • Context
  • Message / AssistantMessage / ToolResultMessage
  • content blocks for text, image, thinking, and toolCall
  • Usage and StopReason
  • structured AssistantMessageEvent streaming
  • model and provider registration APIs
  • cross-provider message normalization and synthetic tool-result insertion

New top-level core API

packages/agentic-kit/src/index.ts now exposes structured primitives:

  • stream(model, context, options)
  • complete(model, context, options)
  • completeText(model, context, options)
  • model/provider registry helpers

The old AgentKit class remains as a transition-layer compatibility wrapper.

Compatibility wrapper retained

The legacy prompt-oriented API still works for one transition release through:

  • AgentKit
  • createOpenAIKit
  • createAnthropicKit
  • createOllamaKit
  • createMultiProviderKit

That wrapper now delegates into the structured event-stream architecture instead of being the primary abstraction.

OpenAI-compatible adapter rewrite

packages/openai/src/index.ts was rewritten around the new contract.

It now supports:

  • provider/model descriptors
  • structured streaming events
  • partial JSON parsing for tool calls
  • usage tracking from streaming chunks
  • reasoning-aware request shaping
  • generalized OpenAI-compatible behavior rather than a brand-specific text adapter

Anthropic adapter rewrite

packages/anthropic/src/index.ts was rewritten to the same structured protocol.

It now supports:

  • message/tool schema translation
  • SSE event parsing into structured events
  • Anthropic tool-use streaming
  • thinking block streaming
  • usage tracking and stop reasons

Ollama adapter rewrite

packages/ollama/src/index.ts now includes:

  • retained OllamaClient functionality for model listing, pull/delete, and embeddings
  • a structured OllamaAdapter
  • streaming through the new assistant event model
  • updated tests that validate the new API shape

New @agentic-kit/agent package

Added a new package at packages/agent/.

This package provides a minimal v1 runtime:

  • sequential tool execution
  • lifecycle events
  • abort and continue support
  • pluggable context transforms
  • lightweight JSON Schema validation

This intentionally does not yet include richer steering/follow-up orchestration. The goal is to keep the first runtime layer minimal and validate the architecture first.

Docs and design record

Added:

  • REDESIGN_DECISIONS.md

Updated:

  • root README.md
  • packages/agentic-kit/README.md
  • packages/ollama/README.md

This also removes stale Ollama documentation that referenced methods no longer present in code.

Test coverage refresh

Replaced old tests that assumed string-only adapter behavior with new tests covering:

  • structured OpenAI-compatible streaming
  • Anthropic tool-use streaming
  • Ollama structured streaming
  • cross-provider message transforms
  • legacy compatibility wrapper behavior
  • minimal agent runtime loop

Migration Notes

This PR changes the architectural center of gravity, but keeps a compatibility path.

The intended migration path is:

  • old style: kit.generate({ model, prompt }, { onChunk })
  • new style: stream(model, context, options) or complete(model, context, options)

Legacy usage still works, but the structured API is now the primary contract.

Verification

Executed successfully:

  • pnpm install
  • pnpm -r build
  • pnpm -r test

Additional smoke checks performed:

  • required CJS dist output from packages/agentic-kit/dist/index.js
  • imported ESM dist output from packages/agentic-kit/dist/esm/index.js
  • imported ESM dist output from packages/agent/dist/esm/index.js

Infra / Packaging Notes

I found and fixed one real infra issue during this work:

  • ESM output initially emitted extensionless relative imports, which Node could not load from dist/esm.

Fix applied:

  • internal source imports/exports in the core and agent packages now use .js specifiers
  • Jest config was updated to map those .js relative imports back to TS sources during tests

Current remaining caveat:

  • importing dist/esm/*.js by file path triggers Node’s MODULE_TYPELESS_PACKAGE_JSON warning because the generated dist/package.json is not marked "type": "module"
  • this does not break builds, tests, or ESM loading, but it is still worth tightening in a follow-up if we want cleaner Node ESM ergonomics

Follow-ups

Recommended next follow-ups after this PR:

  • expand the curated built-in model registry
  • add richer provider compatibility handling beyond the initial set
  • add optional schema helpers for TypeBox/Zod
  • decide how to package ESM more cleanly to eliminate the remaining Node warning
  • add richer @agentic-kit/agent orchestration only after the lower-level protocol proves stable

Files of Interest

Core:

  • packages/agentic-kit/src/index.ts
  • packages/agentic-kit/src/types.ts
  • packages/agentic-kit/src/event-stream.ts
  • packages/agentic-kit/src/messages.ts
  • packages/agentic-kit/src/model-registry.ts
  • packages/agentic-kit/src/provider-registry.ts
  • packages/agentic-kit/src/transform-messages.ts

Adapters:

  • packages/openai/src/index.ts
  • packages/anthropic/src/index.ts
  • packages/ollama/src/index.ts

Agent runtime:

  • packages/agent/src/agent.ts
  • packages/agent/src/types.ts
  • packages/agent/src/validation.ts

Design record:

  • REDESIGN_DECISIONS.md

@yyyyaaa yyyyaaa requested a review from pyramation April 18, 2026 04:51
@yyyyaaa
Copy link
Copy Markdown
Author

yyyyaaa commented Apr 18, 2026

added live ollama tests

@yyyyaaa yyyyaaa changed the title (WIP) Redesign agentic-kit core around structured streams and add minimal agent runtim (WIP) Redesign agentic-kit core around structured streams and add minimal agent runtime Apr 19, 2026
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