Tool returns a fantasy.AgentTool that asks a nested model for concise strategic guidance. The nested advisor sees recent conversation context, runs without tools, and is limited to a single model step.
(opts ToolOptions)
| 30 | // strategic guidance. The nested advisor sees recent conversation |
| 31 | // context, runs without tools, and is limited to a single model step. |
| 32 | func Tool(opts ToolOptions) fantasy.AgentTool { |
| 33 | return fantasy.NewAgentTool( |
| 34 | ToolName, |
| 35 | "Ask a separate advisor pass for strategic guidance about planning, architecture, tradeoffs, or debugging strategy. Provide a brief question of 2000 runes or fewer, summarizing context instead of pasting long logs or transcripts. The advisor sees recent conversation context, runs without tools for a single step, and responds to the parent agent rather than the end user.", |
| 36 | func(ctx context.Context, args AdvisorArgs, call fantasy.ToolCall) (fantasy.ToolResponse, error) { |
| 37 | if opts.Runtime == nil { |
| 38 | return fantasy.NewTextErrorResponse("advisor runtime is not configured"), nil |
| 39 | } |
| 40 | if opts.GetConversationSnapshot == nil { |
| 41 | return fantasy.NewTextErrorResponse("conversation snapshot provider is not configured"), nil |
| 42 | } |
| 43 | |
| 44 | question := strings.TrimSpace(args.Question) |
| 45 | if question == "" { |
| 46 | return fantasy.NewTextErrorResponse("question is required"), nil |
| 47 | } |
| 48 | |
| 49 | var runOpts *RunAdvisorOptions |
| 50 | if call.ID != "" && (opts.PublishAdviceDelta != nil || opts.PublishAdviceReset != nil) { |
| 51 | runOpts = &RunAdvisorOptions{} |
| 52 | if opts.PublishAdviceDelta != nil { |
| 53 | runOpts.OnAdviceDelta = func(delta string) { |
| 54 | opts.PublishAdviceDelta(call.ID, delta) |
| 55 | } |
| 56 | } |
| 57 | if opts.PublishAdviceReset != nil { |
| 58 | runOpts.OnAdviceReset = func() { |
| 59 | opts.PublishAdviceReset(call.ID) |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | result, err := opts.Runtime.RunAdvisor(ctx, question, opts.GetConversationSnapshot(), runOpts) |
| 65 | if err != nil { |
| 66 | return fantasy.NewTextErrorResponse(err.Error()), nil |
| 67 | } |
| 68 | data, err := json.Marshal(result) |
| 69 | if err != nil { |
| 70 | return fantasy.NewTextResponse("{}"), nil |
| 71 | } |
| 72 | return fantasy.NewTextResponse(string(data)), nil |
| 73 | }, |
| 74 | ) |
| 75 | } |