blob: 183bf14dd0a262ca5a7cdd51d1270455bb51f89c [file] [log] [blame]
Philip Zeyliger33d282f2025-05-03 04:01:54 +00001package browse
2
3import (
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 Zeyliger72252cb2025-05-10 17:00:08 -070013func RegisterBrowserTools(ctx context.Context, supportsScreenshots bool) ([]*llm.Tool, func()) {
Philip Zeyliger33d282f2025-05-03 04:01:54 +000014 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 Zeyliger72252cb2025-05-10 17:00:08 -070021 return browserTools.GetTools(supportsScreenshots), func() {
Philip Zeyliger33d282f2025-05-03 04:01:54 +000022 browserTools.Close()
23 }
24}
25
26// Tool is an alias for llm.Tool to make the documentation clearer
27type Tool = llm.Tool