params

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package params provides shared parameter extraction and error formatting utilities used by both Claude and Google tool implementations.

This package contains the core logic that is common across AI providers, avoiding duplication between claudetool and googletool packages.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(format string, args ...any) map[string]any

Error creates an error response map.

Example
package main

import (
	"fmt"

	"chainguard.dev/driftlessaf/agents/toolcall/params"
)

func main() {
	result := params.Error("invalid parameter %q", "foo")
	fmt.Println(result["error"])

}
Output:
invalid parameter "foo"

func ErrorWithContext

func ErrorWithContext(err error, context map[string]any) map[string]any

ErrorWithContext creates an error response with additional context fields.

Example
package main

import (
	"errors"
	"fmt"

	"chainguard.dev/driftlessaf/agents/toolcall/params"
)

func main() {
	result := params.ErrorWithContext(errors.New("file not found"), map[string]any{
		"path": "/tmp/missing.txt",
	})
	fmt.Println(result["error"])
	fmt.Println(result["path"])

}
Output:
file not found
/tmp/missing.txt

func Extract

func Extract[T any](args map[string]any, name string) (T, error)

Extract extracts a required parameter from args with type safety. Returns an error if the parameter is missing or cannot be converted to T.

Example
package main

import (
	"fmt"

	"chainguard.dev/driftlessaf/agents/toolcall/params"
)

func main() {
	args := map[string]any{
		"name":  "hello",
		"count": float64(42),
	}

	name, err := params.Extract[string](args, "name")
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	fmt.Println(name)

	count, err := params.Extract[int](args, "count")
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	fmt.Println(count)

}
Output:
hello
42

func ExtractOptional

func ExtractOptional[T any](args map[string]any, name string, defaultValue T) (T, error)

ExtractOptional extracts an optional parameter with a default value. Returns the default if the parameter doesn't exist, or an error if type conversion fails.

Example
package main

import (
	"fmt"

	"chainguard.dev/driftlessaf/agents/toolcall/params"
)

func main() {
	args := map[string]any{
		"name": "hello",
	}

	name, err := params.ExtractOptional(args, "name", "default")
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	fmt.Println(name)

	missing, err := params.ExtractOptional(args, "missing", "default")
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	fmt.Println(missing)

}
Output:
hello
default

Types

This section is empty.

Jump to

Keyboard shortcuts

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