diff --git a/chat.go b/chat.go index 86623f6..ef2ab79 100644 --- a/chat.go +++ b/chat.go @@ -145,11 +145,14 @@ func (r *Request) Parse() (*openrouter.ChatCompletionRequest, error) { request.Messages = append(request.Messages, openrouter.SystemMessage(prompt)) } - if model.Tools && r.Tools.Search && env.Tokens.Exa != "" { + if model.Tools && r.Tools.Search && env.Tokens.Exa != "" && r.Iterations > 1 { request.Tools = GetSearchTools() request.ToolChoice = "auto" - request.Messages = append(request.Messages, openrouter.SystemMessage(InternalToolsPrompt)) + request.Messages = append( + request.Messages, + openrouter.SystemMessage(fmt.Sprintf(InternalToolsPrompt, r.Iterations-1)), + ) } for _, message := range r.Messages { @@ -273,7 +276,7 @@ func HandleChat(w http.ResponseWriter, r *http.Request) { for iteration := range raw.Iterations { debug("iteration %d of %d", iteration+1, raw.Iterations) - if iteration == raw.Iterations-1 { + if len(request.Tools) > 0 && iteration == raw.Iterations-1 { debug("no more tool calls") request.Tools = nil diff --git a/internal/tools.txt b/internal/tools.txt index af7c8ce..0bb39aa 100644 --- a/internal/tools.txt +++ b/internal/tools.txt @@ -1 +1,3 @@ -You have access to web search tools. Use `search_web` with `query` (string) and `num_results` (1-10) to find current information - when searching for recent/latest information, always include specific dates or years (e.g., "august 2025"). Use `fetch_contents` with `urls` (array) to read full page content from search results or known URLs. Use `github_repository` with `owner` (string) and `repo` (string) to get repository overviews (info, branches, files, README) without cloning. Formulate specific, targeted queries and provide all required parameters. Call only one tool per response. \ No newline at end of file +You have access to web search tools. Use `search_web` with `query` (string) and `num_results` (1-10) to find current information - when searching for recent/latest information, always include specific dates or years (e.g., "august 2025"). Use `fetch_contents` with `urls` (array) to read full page content from search results or known URLs. Use `github_repository` with `owner` (string) and `repo` (string) to get repository overviews (info, branches, files, README) without cloning. Formulate specific, targeted queries and provide all required parameters. Call only one tool per response. + +You have %d tool calls available in total. \ No newline at end of file