rony-llm-agent/pkg/tools
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
..
sandbox 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
registry.go feat(tools): add Tool definitions, Registry pattern, and filesystem sandbox with path validation 2026-06-30 23:53:32 -07:00
registry_test.go feat(tools): add Tool definitions, Registry pattern, and filesystem sandbox with path validation 2026-06-30 23:53:32 -07:00
types.go feat(tools): add Tool definitions, Registry pattern, and filesystem sandbox with path validation 2026-06-30 23:53:32 -07:00
types_test.go Fix tool call tracking and streaming assembly for all providers 2026-07-08 16:11:57 -07:00

pkg/tools

Tools system (function calling) with JSON Schema, sandbox, and permissions.

Responsibility

Allow the LLM to invoke functions defined in Go, with schema validation and sandboxing.

Public API

type Tool struct {
    Name        string
    Description string
    InputSchema json.RawMessage  // JSON Schema draft-07+
    Handler     Handler          // func(ctx, args json.RawMessage) (Result, error)
    Permission  Permission       // Allow | Ask | Deny
    Examples    []Example        // few-shot for the LLM
}

type Registry interface {
    Register(tool Tool) error
    Get(name string) (Tool, bool)
    List() []Tool
    Filter(policy Policy) []Tool
}

type Call struct {
    ID        string
    Name      string
    Arguments json.RawMessage
    Thought   string           // optional: chain-of-thought from the LLM
}

type Result struct {
    Content   string
    IsError   bool
    Metadata  map[string]string
    Artifacts []Artifact
}

type Permission int

const (
    Allow Permission = iota
    Ask
    Deny
)

Integrated sandbox

pkg/tools uses os.Root (Go 1.24+) for filesystem sandbox:

sandbox := tools.NewSandbox("./workspace")
sandbox.Register(myReadTool)  // can only read inside the workspace

See pkg/tools/sandbox/ for details.

Generic tools included

  • http_fetch — GET URL with HTML→markdown
  • json_parse — Parse arbitrary JSON
  • datetime_now — Current timestamp

Product-specific tools (e.g., read_file, bash for software dev) are defined by each consumer in their own internal/tools/.

See also