| Philip Zeyliger | 33d282f | 2025-05-03 04:01:54 +0000 | [diff] [blame] | 1 | package browse |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "log" |
| 6 | |
| 7 | "sketch.dev/llm" |
| 8 | ) |
| 9 | |
| 10 | // RegisterBrowserTools initializes the browser tools and returns all the tools |
| 11 | // ready to be added to an agent. It also returns a cleanup function that should |
| 12 | // be called when done to properly close the browser. |
| 13 | func RegisterBrowserTools(ctx context.Context) ([]*llm.Tool, func()) { |
| 14 | browserTools := NewBrowseTools(ctx) |
| 15 | |
| 16 | // Initialize the browser |
| 17 | if err := browserTools.Initialize(); err != nil { |
| 18 | log.Printf("Warning: Failed to initialize browser: %v", err) |
| 19 | } |
| 20 | |
| 21 | // Return all tools and a cleanup function |
| 22 | return browserTools.GetAllTools(), func() { |
| 23 | browserTools.Close() |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | // Tool is an alias for llm.Tool to make the documentation clearer |
| 28 | type Tool = llm.Tool |