Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions services/ask-ai-bot/utils/ai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions services/ask-ai-bot/utils/ai/system-prompt.ts
Original file line number Diff line number Diff line change
@@ -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.`;
23 changes: 14 additions & 9 deletions services/ask-ai-bot/utils/ai/tools/docs-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions services/ask-ai-bot/utils/ai/tools/docs-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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];

Expand Down
10 changes: 5 additions & 5 deletions services/ask-ai-bot/utils/ai/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -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()
Expand All @@ -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;
Expand Down