local M = {} ---@param provider_conf AvanteDefaultBaseProvider ---@param opts AvantePromptOptions ---@return string function M.get_ReAct_system_prompt(provider_conf, opts) local system_prompt = opts.system_prompt local disable_tools = provider_conf.disable_tools or false if not disable_tools and opts.tools then local tools_prompts = [[ ==== TOOL USE You have access to a set of tools that are executed upon the user's approval. You can use one tool per message, and will receive the result of that tool use in the user's response. You use tools step-by-step to accomplish a given task, with each tool use informed by the result of the previous tool use. # Tool Use Formatting Tool use is formatted using XML-style tags. Each tool use is wrapped in a tag. The tool name is enclosed in opening and closing tags, and each parameter is similarly enclosed within its own set of tags. Here's the structure: value1 value2 ... For example: I have completed the task... ./src npm run dev ALWAYS ADHERE TO this format for the tool use to ensure proper parsing and execution. ## OUTPUT FORMAT Please remember you are not allowed to use any format related to function calling or fc or tool_code. # Tools ]] for _, tool in ipairs(opts.tools) do local tool_prompt = ([[ ## {{name}} Description: {{description}} Parameters: ]]):gsub("{{name}}", tool.name):gsub( "{{description}}", tool.get_description and tool.get_description() or (tool.description or "") ) for _, field in ipairs(tool.param.fields) do if field.optional then tool_prompt = tool_prompt .. string.format(" - %s: %s\n", field.name, field.description) else tool_prompt = tool_prompt .. string.format( " - %s: (required) %s\n", field.name, field.get_description and field.get_description() or (field.description or "") ) end end if tool.param.usage then tool_prompt = tool_prompt .. ("Usage:\n\n<{{name}}>\n"):gsub("{{([%w_]+)}}", function(name) return tool[name] end) for k, v in pairs(tool.param.usage) do tool_prompt = tool_prompt .. "<" .. k .. ">" .. tostring(v) .. "\n" end tool_prompt = tool_prompt .. ("\n\n"):gsub("{{([%w_]+)}}", function(name) return tool[name] end) end tools_prompts = tools_prompts .. tool_prompt .. "\n" end system_prompt = system_prompt .. tools_prompts system_prompt = system_prompt .. [[ # Tool Use Examples ## Example 1: Requesting to execute a command ./src npm run dev ## Example 2: Requesting to create a new file src/frontend-config.json { "apiEndpoint": "https://api.example.com", "theme": { "primaryColor": "#007bff", "secondaryColor": "#6c757d", "fontFamily": "Arial, sans-serif" }, "features": { "darkMode": true, "notifications": true, "analytics": false }, "version": "1.0.0" } ## Example 3: Requesting to make targeted edits to a file src/components/App.tsx ------- SEARCH import React from 'react'; ======= import React, { useState } from 'react'; +++++++ REPLACE ------- SEARCH function handleSubmit() { saveData(); setLoading(false); } ======= +++++++ REPLACE ------- SEARCH return (
======= function handleSubmit() { saveData(); setLoading(false); } return (
+++++++ REPLACE ## Example 4: Complete current task I've successfully created the requested React component with the following features: - Responsive layout - Dark/light mode toggle - Form validation - API integration ## Example 5: Add todos [ { "id": "1", "content": "Implement a responsive layout", "status": "todo", "priority": "low" }, { "id": "2", "content": "Add dark/light mode toggle", "status": "todo", "priority": "medium" }, ] ## Example 6: Update todo status 1 done ]] end return system_prompt end --- Get the content of AGENTS.md or CLAUDE.md or OPENCODE.md ---@return string | nil function M.get_agents_rules_prompt() local Utils = require("avante.utils") local project_root = Utils.get_project_root() local file_names = { "AGENTS.md", "CLAUDE.md", "OPENCODE.md", ".cursorrules", ".windsurfrules", Utils.join_paths(".github", "copilot-instructions.md"), } for _, file_name in ipairs(file_names) do local file_path = Utils.join_paths(project_root, file_name) if vim.fn.filereadable(file_path) == 1 then local content = vim.fn.readfile(file_path) if content then return table.concat(content, "\n") end end end return nil end return M