fix ask-ai bot hitting tool call limits (#7162)
Signed-off-by: The-Best-Codes <106822363+The-Best-Codes@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,7 @@ import type { Message, ThreadChannel } from "discord.js";
|
|||||||
import { model } from "../../clients/ai";
|
import { model } from "../../clients/ai";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger";
|
||||||
import { chunkMarkdown } from "./chunk-markdown";
|
import { chunkMarkdown } from "./chunk-markdown";
|
||||||
import { SYSTEM_PROMPT } from "./system-prompt";
|
import { MAX_STEPS, SYSTEM_PROMPT } from "./system-prompt";
|
||||||
import { ToolTracker } from "./tool-tracker";
|
import { ToolTracker } from "./tool-tracker";
|
||||||
import { aiTools } from "./tools";
|
import { aiTools } from "./tools";
|
||||||
|
|
||||||
@@ -48,8 +48,7 @@ export async function answerQuestion({
|
|||||||
system: SYSTEM_PROMPT,
|
system: SYSTEM_PROMPT,
|
||||||
prompt,
|
prompt,
|
||||||
tools: aiTools,
|
tools: aiTools,
|
||||||
maxOutputTokens: 2048,
|
stopWhen: stepCountIs(MAX_STEPS),
|
||||||
stopWhen: stepCountIs(5),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for await (const event of result.fullStream) {
|
for await (const event of result.fullStream) {
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
|
export const MAX_STEPS = 10;
|
||||||
export const SYSTEM_PROMPT = `You are a helpful assistant in the goose Discord server.
|
export const SYSTEM_PROMPT = `You are a helpful assistant in the goose Discord server.
|
||||||
Your role is to provide assistance and answer questions about codename goose, an open-source AI agent developed by Block. codename goose's website is \`https://block.github.io/goose\`. Your answers should be short and to the point. Always assume that a user's question is related to codename goose unless they specifically state otherwise. DO NOT capitalize "goose" or "codename goose".
|
Your role is to provide assistance and answer questions about codename goose, an open-source AI agent developed by Block. codename goose's website is \`https://block.github.io/goose\`. Your answers should be short and to the point. Always assume that a user's question is related to codename goose unless they specifically state otherwise. DO NOT capitalize "goose" or "codename goose".
|
||||||
|
|
||||||
|
You can perform a maximum of ${MAX_STEPS} steps (tool calls, text outputs, etc.). If you exceed this limit, no response will be provided to the user. BEFORE you reach the limit, STOP calling tools, respond to the user, and don't call any tools after your final response until the user asks another question.
|
||||||
|
|
||||||
When answering questions about goose:
|
When answering questions about goose:
|
||||||
1. Use the \`search_docs\` tool to find relevant documentation
|
1. Use the \`search_docs\` tool to find relevant documentation
|
||||||
2. Use the \`view_docs\` tool to read documentation (read all relevant files to get the full picture)
|
2. Use the \`view_docs\` tool to read documentation (read multiple relevant files to get the full picture)
|
||||||
3. Cite the documentation source in your response (using its Web URL)
|
3. Iterate on steps 1 and 2 (not necessarily in order) until you have a deep understanding of the question and relevant documentation
|
||||||
|
4. Cite the documentation source in your response (using its Web URL)
|
||||||
|
|
||||||
When providing links, wrap the URL in angle brackets (e.g., \`<https://example.com>\` or \`[Example](<https://example.com>)\`) to prevent excessive link previews. Do not use backtick characters around the URL.`;
|
When providing links, wrap the URL in angle brackets (e.g., \`<https://example.com>\` or \`[Example](<https://example.com>)\`) to prevent excessive link previews. Do not use backtick characters around the URL.`;
|
||||||
|
|||||||
@@ -99,10 +99,11 @@ function generateWebUrl(filePath: string): string {
|
|||||||
return `${baseUrl}/${urlPath}`;
|
return `${baseUrl}/${urlPath}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPreview(content: string, maxLength: number = 200): string {
|
function getPreview(content: string, maxLength: number = 1000): string {
|
||||||
const withoutFrontmatter = content.replace(/^---[\s\S]*?---\n/, "");
|
const withoutFrontmatter = content.replace(/^---[\s\S]*?---\n/, "");
|
||||||
const lines = withoutFrontmatter.split("\n");
|
const lines = withoutFrontmatter.split("\n");
|
||||||
let preview = "";
|
const contentLines: string[] = [];
|
||||||
|
let currentLength = 0;
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
const cleanLine = line
|
const cleanLine = line
|
||||||
@@ -116,19 +117,23 @@ function getPreview(content: string, maxLength: number = 200): string {
|
|||||||
!cleanLine.startsWith("import") &&
|
!cleanLine.startsWith("import") &&
|
||||||
!cleanLine.startsWith("export")
|
!cleanLine.startsWith("export")
|
||||||
) {
|
) {
|
||||||
preview = cleanLine;
|
if (currentLength + cleanLine.length > maxLength) {
|
||||||
break;
|
const remaining = maxLength - currentLength;
|
||||||
|
if (remaining > 0) {
|
||||||
|
contentLines.push(cleanLine.substring(0, remaining) + "...");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
contentLines.push(cleanLine);
|
||||||
|
currentLength += cleanLine.length + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preview.length > maxLength) {
|
const preview = contentLines.join("\n");
|
||||||
preview = preview.substring(0, maxLength) + "...";
|
|
||||||
}
|
|
||||||
|
|
||||||
return preview || "(No preview available)";
|
return preview || "(No preview available)";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function searchDocs(query: string, limit: number = 5): SearchResult[] {
|
export function searchDocs(query: string, limit: number = 15): SearchResult[] {
|
||||||
const search = initializeSearch();
|
const search = initializeSearch();
|
||||||
const results = search.search(query).slice(0, limit);
|
const results = search.search(query).slice(0, limit);
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ function findDocFile(partialPath: string): string | null {
|
|||||||
function getDocChunk(
|
function getDocChunk(
|
||||||
filePath: string,
|
filePath: string,
|
||||||
startLine: number = 0,
|
startLine: number = 0,
|
||||||
lineCount: number = 100,
|
lineCount: number = 1500,
|
||||||
): { fileName: string; content: string; webUrl: string } {
|
): { fileName: string; content: string; webUrl: string } {
|
||||||
const docsDir = path.resolve(getDocsDir());
|
const docsDir = path.resolve(getDocsDir());
|
||||||
const fullPath = path.join(docsDir, filePath);
|
const fullPath = path.join(docsDir, filePath);
|
||||||
@@ -94,7 +94,7 @@ function getDocChunk(
|
|||||||
export function viewDocs(
|
export function viewDocs(
|
||||||
filePaths: string | string[],
|
filePaths: string | string[],
|
||||||
startLine: number = 0,
|
startLine: number = 0,
|
||||||
lineCount: number = 100,
|
lineCount: number = 1500,
|
||||||
): string {
|
): string {
|
||||||
const paths = Array.isArray(filePaths) ? filePaths : [filePaths];
|
const paths = Array.isArray(filePaths) ? filePaths : [filePaths];
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ export const aiTools = {
|
|||||||
limit: z
|
limit: z
|
||||||
.number()
|
.number()
|
||||||
.optional()
|
.optional()
|
||||||
.describe("Maximum number of results to return (default 5)"),
|
.describe("Maximum number of results to return (default 15)"),
|
||||||
}),
|
}),
|
||||||
execute: async ({ query, limit = 5 }) => {
|
execute: async ({ query, limit = 15 }) => {
|
||||||
const results = searchDocs(query, limit);
|
const results = searchDocs(query, limit);
|
||||||
logger.verbose(
|
logger.verbose(
|
||||||
`Searched docs for "${query}", found ${results.length} results`,
|
`Searched docs for "${query}", found ${results.length} results`,
|
||||||
@@ -42,7 +42,7 @@ export const aiTools = {
|
|||||||
filePaths: z
|
filePaths: z
|
||||||
.union([z.string(), z.array(z.string())])
|
.union([z.string(), z.array(z.string())])
|
||||||
.describe(
|
.describe(
|
||||||
"Path or array of paths to documentation files (example: 'quickstart.md' or ['guides/managing-projects.md', 'api/overview.md'])",
|
"Path or array of paths to documentation files (example: 'quickstart.md' or ['guides/managing-projects.md', 'mcp/asana-mcp.md'])",
|
||||||
),
|
),
|
||||||
startLine: z
|
startLine: z
|
||||||
.number()
|
.number()
|
||||||
@@ -51,9 +51,9 @@ export const aiTools = {
|
|||||||
lineCount: z
|
lineCount: z
|
||||||
.number()
|
.number()
|
||||||
.optional()
|
.optional()
|
||||||
.describe("Number of lines to show (default 100)"),
|
.describe("Number of lines to show (default 1500)"),
|
||||||
}),
|
}),
|
||||||
execute: async ({ filePaths, startLine = 0, lineCount = 100 }) => {
|
execute: async ({ filePaths, startLine = 0, lineCount = 1500 }) => {
|
||||||
try {
|
try {
|
||||||
const result = viewDocs(filePaths, startLine, lineCount);
|
const result = viewDocs(filePaths, startLine, lineCount);
|
||||||
const count = Array.isArray(filePaths) ? filePaths.length : 1;
|
const count = Array.isArray(filePaths) ? filePaths.length : 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user