llmclient

package
v0.38.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

README

llmclient

LLM client package for code analysis.

  • AgenticClient: Provider-agnostic agentic client using native SDK implementations for each provider. Gives the LLM tools to explore a repository and answer questions about code.

AgenticClient

The agentic client runs a tool-calling loop where the LLM can explore code using read-only tools, then submits structured answers via submit_answer.

Tools: list_directory, read_file, grep, git (allowlisted subcommands), submit_answer

Providers: Google (Gemini), Anthropic (Claude), OpenAI

sequenceDiagram
    participant Caller
    participant AgenticClient
    participant LLM
    participant Tools

    Caller->>AgenticClient: CallLLM(prompt, repoPath, opts)
    AgenticClient->>LLM: system prompt + user prompt + tool definitions

    loop until submit_answer or 100 tool calls
        LLM-->>AgenticClient: tool call(s)
        alt submit_answer
            AgenticClient->>AgenticClient: collect answer
            AgenticClient-->>LLM: "Answer recorded"
        else read_file / list_directory / grep / git
            AgenticClient->>Tools: execute tool (sandboxed to repoPath)
            Tools-->>AgenticClient: result
            AgenticClient-->>LLM: tool result
        end
    end

    Note over LLM,AgenticClient: LLM sends message with no tool calls → done
    AgenticClient-->>Caller: []AnswerSchema

Debug logging

Set DEBUG=1 to write detailed logs to /tmp/validator-agentic-<timestamp>.log.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAPIKeyNotSet = errors.New("GEMINI_API_KEY not set")

Functions

func CleanUpPromptFiles added in v0.36.0

func CleanUpPromptFiles(dir string)

CleanUpPromptFiles removes agent config files and known output files from the given directory to avoid influencing the LLM.

Types

type AgenticCallOptions added in v0.38.0

type AgenticCallOptions struct {
	Model    string // e.g. "gemini-2.5-flash"
	Provider string // "google", "anthropic", "openai"
	APIKey   string

	// Tools selects specific exploration tools. When non-nil, takes precedence
	// over ToolSet. submit_answer is always included regardless.
	Tools []AgenticTool

	// ToolSet selects a preset collection of tools. Used when Tools is nil.
	// The zero value (DefaultTooling) includes all exploration tools.
	ToolSet ToolSet

	// SystemPrompt overrides the intro portion of the system prompt. The
	// AVAILABLE TOOLS section is always auto-appended. When empty, a default
	// intro is used.
	SystemPrompt string
}

AgenticCallOptions contains configuration for the agentic LLM call.

type AgenticClient added in v0.38.0

type AgenticClient interface {
	CallLLM(ctx context.Context, questions []string, repositoryPath string) ([]AnswerSchema, error)
}

AgenticClient is an interface for agentic LLM interactions

func NewAgenticClient added in v0.38.0

func NewAgenticClient(opts *AgenticCallOptions) (AgenticClient, error)

NewAgenticClient creates a new AgenticClient with the given options

type AgenticTool added in v0.38.0

type AgenticTool string

AgenticTool identifies an exploration tool available to the agent.

const (
	ToolReadFile      AgenticTool = "read_file"
	ToolListDirectory AgenticTool = "list_directory"
	ToolGrep          AgenticTool = "grep"
	ToolGit           AgenticTool = "git"
)

type AnswerSchema added in v0.38.0

type AnswerSchema struct {
	Question    string   `json:"question"`
	Answer      string   `json:"answer"`
	ShortAnswer bool     `json:"short_answer"`
	Files       []string `json:"files,omitempty"`
	CodeSnippet string   `json:"code_snippet,omitempty"`
	// Error is set when the agent failed to answer this question
	// (e.g. budget exhausted). Consumers should skip errored answers.
	Error string `json:"error,omitempty"`
}

AnswerSchema represents the structured response from the agentic client.

type CallLLMOptions added in v0.36.0

type CallLLMOptions struct {
	Model string // e.g. "gemini-2.5-flash", empty = CLI default
}

type GeminiClient

type GeminiClient struct{}

func NewGeminiClient

func NewGeminiClient() *GeminiClient

func (*GeminiClient) CallLLM

func (g *GeminiClient) CallLLM(prompt, repositoryPath string, opts *CallLLMOptions) error

func (*GeminiClient) CanUseLLM added in v0.36.0

func (g *GeminiClient) CanUseLLM() error

type LLMClient

type LLMClient interface {
	CanUseLLM() error
	CallLLM(prompt, repositoryPath string, opts *CallLLMOptions) error
}

type MockAgenticClient added in v0.38.0

type MockAgenticClient struct {
	// contains filtered or unexported fields
}

MockAgenticClient implements AgenticClient for testing.

func NewMockAgenticClient added in v0.38.0

func NewMockAgenticClient(answers []AnswerSchema) *MockAgenticClient

func (*MockAgenticClient) CallLLM added in v0.38.0

func (m *MockAgenticClient) CallLLM(ctx context.Context, questions []string, repoPath string) ([]AnswerSchema, error)

type MockLLMClient

type MockLLMClient struct {
	// contains filtered or unexported fields
}

func NewMockLLMClient

func NewMockLLMClient() *MockLLMClient

func (*MockLLMClient) CallLLM

func (m *MockLLMClient) CallLLM(prompt, repositoryPath string, opts *CallLLMOptions) error

func (*MockLLMClient) CanUseLLM added in v0.36.0

func (m *MockLLMClient) CanUseLLM() error

func (*MockLLMClient) WithResponses

func (m *MockLLMClient) WithResponses(responses []MockResponse) *MockLLMClient

type MockResponse

type MockResponse struct {
	Question     string   `json:"question"`
	Answer       string   `json:"answer"`
	RelatedFiles []string `json:"related_files"`
	CodeSnippet  string   `json:"code_snippet"`
	ShortAnswer  string   `json:"short_answer"`
}

type ToolSet added in v0.38.0

type ToolSet int

ToolSet is a preset collection of tools.

const (
	// DefaultTooling includes all exploration tools (read_file, list_directory,
	// grep, git) plus submit_answer. This is the zero value.
	DefaultTooling ToolSet = iota
	// NoTools includes only submit_answer with no exploration tools.
	NoTools
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL