| 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. |
| Philip Zeyliger | 72252cb | 2025-05-10 17:00:08 -0700 | [diff] [blame] | 13 | func RegisterBrowserTools(ctx context.Context, supportsScreenshots bool) ([]*llm.Tool, func()) { |
| Philip Zeyliger | 33d282f | 2025-05-03 04:01:54 +0000 | [diff] [blame] | 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 | |
| Philip Zeyliger | 72252cb | 2025-05-10 17:00:08 -0700 | [diff] [blame] | 21 | return browserTools.GetTools(supportsScreenshots), func() { |
| Philip Zeyliger | 33d282f | 2025-05-03 04:01:54 +0000 | [diff] [blame] | 22 | browserTools.Close() |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | // Tool is an alias for llm.Tool to make the documentation clearer |
| 27 | type Tool = llm.Tool |