Let the model call your code safely
You wrap a host capability with a name, purpose, typed arguments, result, and handler. The model sees when and how to call it while your app keeps control of execution.
Worked example
See the idea in context
search := axllm.Fn("search").WithHandler(func(args map[string]axllm.Value) (axllm.Value, error) {
return axllm.Object("title", "Ax docs"), nil
})- Explain when to call it
The name and description orient the model toward product documentation searches.
- Constrain the call
query must be a string and the result is declared as a string.
- Bind trusted code
searchDocs runs in your host environment when the tool is selected.
Run itIn your own project
go get github.com/ax-llm/ax/packages/go
package main
import (
"context"
"fmt"
"os"
axllm "github.com/ax-llm/ax/packages/go"
)
func main() {
client := axllm.NewAI("openai", map[string]axllm.Value{"apiKey": os.Getenv("OPENAI_API_KEY")})
classify := axllm.NewAx("review:string -> sentiment:class \"positive, negative, neutral\"", nil)
result, err := classify.Forward(context.Background(), client, map[string]axllm.Value{
"review": "Useful and boring in the best way."
}, nil)
if err != nil {
panic(err)
}
fmt.Println("sentiment:", result.(map[string]axllm.Value)["sentiment"])
}Set OPENAI_APIKEY in your environment before running provider-backed code.
From a clone of the ax repo:
npm run example -- go src/examples/go/generation/basic_generation.goActive practice
Answer 2 in a row to learn this · attempt 1