rony-llm-agent/pkg/llm
Victor Vargas 3ac9d89b98 Fix tool call tracking and streaming assembly for all providers
- agent/loop.go: Record assistant message with ToolCalls before tool results,
  and set ToolCallID on tool-result messages so follow-up requests have complete
  context (prevents models from losing track of already-attempted tools).

- llm/providers/llamacpp/client.go: Buffer fragmented tool call deltas during
  streaming, assemble them into complete calls when finish_reason arrives.
  Add ToolCalls, ToolCallID, Name fields to request building.

- llm/providers/openai/client.go: Send ToolCalls, ToolCallID, Name when
  building chat requests so messages are wire-format correct.

- llm/types.go: Add ToolCalls field to Message struct for serialization
  back into conversation history.

- agent/integration_test.go: Move integration test skip from TestMain to a
  per-test skipUnlessIntegration() so it doesn't hide other package tests.

- sandbox & tools: Add edge-case tests (relative traversal, array paths,
  non-path strings, zero-value guards, sentinel errors).
2026-07-08 16:11:57 -07:00
..
mock test(llm,embeddings): add unit tests for mock client, types, and Ollama embedder 2026-07-03 14:22:41 -07:00
providers Fix tool call tracking and streaming assembly for all providers 2026-07-08 16:11:57 -07:00
README.es.md docs(i18n): translate all docs to English (with .es.md as Spanish alternative) 2026-06-30 13:40:37 -07:00
README.md docs(i18n): translate all docs to English (with .es.md as Spanish alternative) 2026-06-30 13:40:37 -07:00
types.go Fix tool call tracking and streaming assembly for all providers 2026-07-08 16:11:57 -07:00
types_test.go test(llm,embeddings): add unit tests for mock client, types, and Ollama embedder 2026-07-03 14:22:41 -07:00

pkg/llm

Multi-provider abstraction for language models.

Responsibility

Define a common interface (LLMClient) and adapters for the main providers.

Public API

type LLMClient interface {
    Generate(ctx context.Context, req CompletionRequest) (CompletionResponse, error)
    Stream(ctx context.Context, req CompletionRequest) iter.Seq2[StreamChunk, error]
    Name() string
    Capabilities() ProviderCapabilities
}

type CompletionRequest struct {
    Messages    []Message
    Tools       []tools.Tool
    ToolChoice  ToolChoice
    Model       string
    Temperature *float32
    MaxTokens   *int
}

type CompletionResponse struct {
    Content    string
    ToolCalls  []tools.Call
    Usage      TokenUsage
    StopReason string
}

type ProviderCapabilities struct {
    SupportsTools    bool
    SupportsVision   bool
    MaxContextWindow int
}

Included providers

Provider Package Tool support
OpenAI providers/openai
Anthropic providers/anthropic
Ollama providers/ollama (models that support it)
llama.cpp providers/llamacpp (with grammar)

Usage

import "github.com/VictorVargas/rony-llm-agent/pkg/llm/providers/anthropic"

client, err := anthropic.New(anthropic.Config{
    APIKey: os.Getenv("ANTHROPIC_API_KEY"),
    Model:  "claude-sonnet-4.5",
})

resp, err := client.Generate(ctx, llm.CompletionRequest{
    Messages: []llm.Message{
        {Role: llm.RoleUser, Content: "Hello"},
    },
})

Streaming

for chunk, err := range client.Stream(ctx, req) {
    if err != nil { return err }
    fmt.Print(chunk.Delta)
}

Mock for tests

import "github.com/VictorVargas/rony-llm-agent/pkg/llm/mock"

mockClient := mock.New(mock.Responses{
    {Match: "hello", Response: "Hi! How are you?"},
    {Match: "*",    Response: "default"},
})

See also