| 1 | package builtin |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | |
| 7 | goaldomain "reasonix/internal/goal" |
| 8 | "reasonix/internal/tool" |
| 9 | ) |
| 10 | |
| 11 | func init() { tool.RegisterBuiltin(createGoal{}) } |
| 12 | |
| 13 | type createGoal struct{} |
| 14 | |
| 15 | func (createGoal) Name() string { return "create_goal" } |
| 16 | func (createGoal) Description() string { |
| 17 | return "Create one persisted same-session goal when the current direct human request is a long-running objective that should continue across autonomous rounds. You may infer that intent without requiring the user to name goal mode. Do not use this for routine single-turn work." |
| 18 | } |
| 19 | func (createGoal) Schema() json.RawMessage { |
| 20 | return json.RawMessage(`{"type":"object","additionalProperties":false,"properties":{"objective":{"type":"string","minLength":1},"max_goal_rounds":{"anyOf":[{"type":"integer","minimum":1},{"type":"null"}],"description":"Optional positive automatic-round limit; omit or null for unlimited."}},"required":["objective"]}`) |
| 21 | } |
| 22 | func (createGoal) ReadOnly() bool { return false } |
| 23 | func (createGoal) ProviderVisible(ctx context.Context) bool { |
| 24 | _, ok := tool.GoalLifecycleFromContext(ctx) |
| 25 | return ok |
| 26 | } |
| 27 | func (createGoal) Execute(ctx context.Context, args json.RawMessage) (string, error) { |
| 28 | var input struct { |
| 29 | Objective string `json:"objective"` |
| 30 | Limit optionalRoundLimit `json:"max_goal_rounds"` |
| 31 | } |
| 32 | if err := decodeGoalArgs(args, &input, "create_goal"); err != nil { |
| 33 | return "", err |
| 34 | } |
| 35 | objective, err := trimmedRequired(input.Objective, "objective") |
| 36 | if err != nil { |
| 37 | return "", err |
| 38 | } |
| 39 | var limit *uint64 |
| 40 | if input.Limit.Present { |
| 41 | limit, err = parseRoundLimit(input.Limit.Raw) |
| 42 | if err != nil { |
| 43 | return "", err |
| 44 | } |
| 45 | } |
| 46 | binding, err := goalBinding(ctx) |
| 47 | if err != nil { |
| 48 | return "", err |
| 49 | } |
| 50 | view, err := binding.Owner.CreateGoal(ctx, goaldomain.CreateRequest{Objective: objective, MaxGoalRounds: limit}, binding.Authority) |
| 51 | if err != nil { |
| 52 | return "", goalToolError("create_goal", err) |
| 53 | } |
| 54 | return goalToolResult(&view) |
| 55 | } |
| 56 |