Skip to content

Migration: pkg/chat extracted to the go/chat module

Superseded on provider registration

This note describes the extraction as it shipped. One claim below has since changed: pkg/chat no longer blank-imports the provider modules, so "nothing to do" no longer holds for a tool that builds its own main. See adapters registered by the tool's main.

The multi-provider AI chat client has been extracted from go-tool-base into the phpboyscout/go language subgroup as a standalone, SDK-free module plus one module per provider:

Module Provides
gitlab.com/phpboyscout/go/chat v0.1.0 the SDK-free core (client, ReAct loop, streaming, fallback, persistence, media) + the claude-local provider
gitlab.com/phpboyscout/go/chat-anthropic v0.1.0 the claude provider (anthropic-sdk-go)
gitlab.com/phpboyscout/go/chat-openai v0.1.0 the openai / openai-compatible providers (openai-go + tiktoken)
gitlab.com/phpboyscout/go/chat-gemini v0.1.0 the gemini provider (genai)

Documentation now lives at chat.go.phpboyscout.uk.

gtb CLI users: nothing changes

gtb ai, gtb docs ask, config keys (ai.provider, anthropic.api.env, …), and credential posture behave exactly as before. This migration only affects code that imports the chat packages.

What go-tool-base did

go-tool-base/pkg/chat is now a thin adapter that:

  • re-exports the module's public types/constructors (chat.Config, chat.New, chat.Tool, …), so existing GTB call sites are unchanged;
  • owns the GTB Viper config-key schema (ConfigKeyClaudeKey, ConfigKeyAIProvider, …) and the SettingsFromProps / NewFromProps / NewWithFallbackFromProps adapters that map Props into the module's typed Settings;
  • blank-imported all three provider modules at the time, so every provider was registered (no longer true; see the note above).

The chat core source (~4,400 lines) was deleted from the tree; only the adapter remains.

What you need to do

If you consume GTB's pkg/chat (e.g. chat.New, chat.Config, the config-key constants): the adapter re-exports the same API. It linked every provider when this note was written; today the tool's main links the providers it uses.

If you want the light, framework-free client directly (no go-tool-base): import the module and opt into only the provider(s) you use:

import (
    "gitlab.com/phpboyscout/go/chat"
    _ "gitlab.com/phpboyscout/go/chat-anthropic" // activate "claude"
)

client, err := chat.New(ctx, chat.Settings{
    Config: chat.Config{Provider: chat.ProviderClaude, Token: apiKey},
})

The module is config-system-agnostic: supply credentials via Config.Token, Config.Credentials, or the well-known env vars, the GTB Viper config schema stays in go-tool-base's adapter. See chat.go.phpboyscout.uk for the full API, provider matrix, and the core↔provider version-compatibility rules.