v2 is a new Go module (v2/) with a dramatically simpler API: - Unified Message type (no more Input marker interface) - Define[T] for ergonomic tool creation with standard context.Context - Chat session with automatic tool-call loop (agent loop) - Streaming via pull-based StreamReader - MCP one-call connect (MCPStdioServer, MCPHTTPServer, MCPSSEServer) - Middleware support (logging, retry, timeout, usage tracking) - Decoupled JSON Schema (map[string]any, no provider coupling) - Sample tools: WebSearch, Browser, Exec, ReadFile, WriteFile, HTTP - Providers: OpenAI, Anthropic, Google (all with streaming) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
32 lines
1.5 KiB
Markdown
32 lines
1.5 KiB
Markdown
# CLAUDE.md for go-llm v2
|
|
|
|
## Build and Test Commands
|
|
- Build project: `cd v2 && go build ./...`
|
|
- Run all tests: `cd v2 && go test ./...`
|
|
- Run specific test: `cd v2 && go test -v -run <TestName> ./...`
|
|
- Tidy dependencies: `cd v2 && go mod tidy`
|
|
- Vet: `cd v2 && go vet ./...`
|
|
|
|
## Code Style Guidelines
|
|
- **Indentation**: Standard Go tabs
|
|
- **Naming**: `camelCase` for unexported, `PascalCase` for exported
|
|
- **Error Handling**: Always check and handle errors immediately. Wrap with `fmt.Errorf("%w: ...", err)`
|
|
- **Imports**: Standard library first, then third-party, then internal packages
|
|
|
|
## Package Structure
|
|
- Root package `llm` — public API (Client, Model, Chat, ToolBox, Message types)
|
|
- `provider/` — Provider interface that backends implement
|
|
- `openai/`, `anthropic/`, `google/` — Provider implementations
|
|
- `tools/` — Ready-to-use sample tools (WebSearch, Browser, Exec, ReadFile, WriteFile, HTTP)
|
|
- `internal/schema/` — JSON Schema generation from Go structs
|
|
- `internal/imageutil/` — Image compression utilities
|
|
|
|
## Key Design Decisions
|
|
1. Unified `Message` type instead of marker interfaces
|
|
2. `map[string]any` JSON Schema (no provider coupling)
|
|
3. Tool functions return `(string, error)`, use standard `context.Context`
|
|
4. `Chat.Send()` auto-loops tool calls; `Chat.SendRaw()` for manual control
|
|
5. MCP one-call connect: `MCPStdioServer(ctx, cmd, args...)`
|
|
6. Streaming via pull-based `StreamReader.Next()`
|
|
7. Middleware for logging, retry, timeout, usage tracking
|