mirror of
https://github.com/block/goose.git
synced 2026-07-17 12:56:20 +02:00
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 { logger } from "../logger";
|
||||
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 { aiTools } from "./tools";
|
||||
|
||||
@@ -48,8 +48,7 @@ export async function answerQuestion({
|
||||
system: SYSTEM_PROMPT,
|
||||
prompt,
|
||||
tools: aiTools,
|
||||
maxOutputTokens: 2048,
|
||||
stopWhen: stepCountIs(5),
|
||||
stopWhen: stepCountIs(MAX_STEPS),
|
||||
});
|
||||
|
||||
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.
|
||||
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:
|
||||
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)
|
||||
3. Cite the documentation source in your response (using its Web URL)
|
||||
2. Use the \`view_docs\` tool to read documentation (read multiple relevant files to get the full picture)
|
||||
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.`;
|
||||
|
||||
@@ -99,10 +99,11 @@ function generateWebUrl(filePath: string): string {
|
||||
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 lines = withoutFrontmatter.split("\n");
|
||||
let preview = "";
|
||||
const contentLines: string[] = [];
|
||||
let currentLength = 0;
|
||||
|
||||
for (const line of lines) {
|
||||
const cleanLine = line
|
||||
@@ -116,19 +117,23 @@ function getPreview(content: string, maxLength: number = 200): string {
|
||||
!cleanLine.startsWith("import") &&
|
||||
!cleanLine.startsWith("export")
|
||||
) {
|
||||
preview = cleanLine;
|
||||
break;
|
||||
if (currentLength + cleanLine.length > maxLength) {
|
||||
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) {
|
||||
preview = preview.substring(0, maxLength) + "...";
|
||||
}
|
||||
|
||||
const preview = contentLines.join("\n");
|
||||
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 results = search.search(query).slice(0, limit);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ function findDocFile(partialPath: string): string | null {
|
||||
function getDocChunk(
|
||||
filePath: string,
|
||||
startLine: number = 0,
|
||||
lineCount: number = 100,
|
||||
lineCount: number = 1500,
|
||||
): { fileName: string; content: string; webUrl: string } {
|
||||
const docsDir = path.resolve(getDocsDir());
|
||||
const fullPath = path.join(docsDir, filePath);
|
||||
@@ -94,7 +94,7 @@ function getDocChunk(
|
||||
export function viewDocs(
|
||||
filePaths: string | string[],
|
||||
startLine: number = 0,
|
||||
lineCount: number = 100,
|
||||
lineCount: number = 1500,
|
||||
): string {
|
||||
const paths = Array.isArray(filePaths) ? filePaths : [filePaths];
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ export const aiTools = {
|
||||
limit: z
|
||||
.number()
|
||||
.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);
|
||||
logger.verbose(
|
||||
`Searched docs for "${query}", found ${results.length} results`,
|
||||
@@ -42,7 +42,7 @@ export const aiTools = {
|
||||
filePaths: z
|
||||
.union([z.string(), z.array(z.string())])
|
||||
.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
|
||||
.number()
|
||||
@@ -51,9 +51,9 @@ export const aiTools = {
|
||||
lineCount: z
|
||||
.number()
|
||||
.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 {
|
||||
const result = viewDocs(filePaths, startLine, lineCount);
|
||||
const count = Array.isArray(filePaths) ? filePaths.length : 1;
|
||||
|
||||
Reference in New Issue
Block a user