ReadSkill returns an AgentTool that reads the full instructions for a skill by name. The model should call this before following any skill's instructions.
(options ReadSkillOptions)
| 281 | // for a skill by name. The model should call this before |
| 282 | // following any skill's instructions. |
| 283 | func ReadSkill(options ReadSkillOptions) fantasy.AgentTool { |
| 284 | return fantasy.NewAgentTool( |
| 285 | "read_skill", |
| 286 | "Read the full instructions for a skill by name. "+ |
| 287 | "Returns the skill meta file body and a list of "+ |
| 288 | "supporting files. Use read_skill before "+ |
| 289 | "following a skill's instructions.", |
| 290 | func(ctx context.Context, args ReadSkillArgs, _ fantasy.ToolCall) (fantasy.ToolResponse, error) { |
| 291 | if args.Name == "" { |
| 292 | return fantasy.NewTextErrorResponse( |
| 293 | "name is required", |
| 294 | ), nil |
| 295 | } |
| 296 | |
| 297 | resolved, err := resolveSkillAlias(options, args.Name) |
| 298 | if err != nil { |
| 299 | return skillResolveErrorResponse(args.Name, err), nil |
| 300 | } |
| 301 | |
| 302 | switch resolved.Source { |
| 303 | case skillspkg.SourcePersonal: |
| 304 | if options.LoadPersonalSkillBody == nil { |
| 305 | return fantasy.NewTextErrorResponse( |
| 306 | "personal skill loader is not configured", |
| 307 | ), nil |
| 308 | } |
| 309 | content, err := options.LoadPersonalSkillBody(ctx, resolved.Name) |
| 310 | if err != nil { |
| 311 | if xerrors.Is(err, skillspkg.ErrSkillNotFound) { |
| 312 | return skillNotFoundResponse(args.Name), nil |
| 313 | } |
| 314 | return fantasy.NewTextErrorResponse( |
| 315 | fmt.Sprintf("failed to load personal skill %q", args.Name), |
| 316 | ), nil |
| 317 | } |
| 318 | return toolResponse(map[string]any{ |
| 319 | "name": args.Name, |
| 320 | "body": content.Body, |
| 321 | "files": []string{}, |
| 322 | }), nil |
| 323 | case skillspkg.SourceWorkspace: |
| 324 | content, response, ok := readWorkspaceSkillBody(ctx, options, args.Name, resolved.Name) |
| 325 | if ok { |
| 326 | return response, nil |
| 327 | } |
| 328 | return toolResponse(map[string]any{ |
| 329 | "name": args.Name, |
| 330 | "body": content.Body, |
| 331 | "files": nonNilFiles(content.Files), |
| 332 | }), nil |
| 333 | default: |
| 334 | return skillNotFoundResponse(args.Name), nil |
| 335 | } |
| 336 | }, |
| 337 | ) |
| 338 | } |
| 339 | |
| 340 | // ReadSkillFileArgs are the parameters accepted by |