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 ¶
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 ¶
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 ¶
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 ¶
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.