mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-18 13:21:55 +00:00
feat(tool): add recursive flag to section content retrieval
- Introduce `recursive` boolean argument (default true) to the getSectionContent tool schema. - Update descriptions to clarify that recursive fetching occurs only when `recursive=true`. - Pass the `recursive` parameter from the CLI wrapper to the core tool function. - Modify the content fetching logic to traverse child sections only when `recursive` is enabled.
This commit is contained in:
@@ -10,7 +10,7 @@ import { createGetSectionContentTool } from "../../src/agent-tools";
|
|||||||
export default tool({
|
export default tool({
|
||||||
description:
|
description:
|
||||||
"Retrieves all text chunks from a specific ECMAScript specification section by section ID. " +
|
"Retrieves all text chunks from a specific ECMAScript specification section by section ID. " +
|
||||||
"Supports recursive fetching - if a section has children, it will fetch all descendants. " +
|
"Supports recursive fetching - if recursive=true and the section has children, it will fetch all descendants. " +
|
||||||
"Use this to get complete spec text when you know the section ID (e.g., 'sec-if-statement').",
|
"Use this to get complete spec text when you know the section ID (e.g., 'sec-if-statement').",
|
||||||
args: {
|
args: {
|
||||||
sectionId: tool.schema
|
sectionId: tool.schema
|
||||||
@@ -18,9 +18,17 @@ export default tool({
|
|||||||
.describe(
|
.describe(
|
||||||
"The section ID (e.g., 'sec-if-statement', 'sec-array-prototype-map') to fetch content for",
|
"The section ID (e.g., 'sec-if-statement', 'sec-array-prototype-map') to fetch content for",
|
||||||
),
|
),
|
||||||
|
recursive: tool.schema
|
||||||
|
.boolean()
|
||||||
|
.default(true)
|
||||||
|
.describe(
|
||||||
|
"If true, recursively fetches content from all child sections and descendants. " +
|
||||||
|
"If false, only returns content from the specified section itself. " +
|
||||||
|
"Use false when you only need the specific section's content without subsections.",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
async execute(args, context) {
|
async execute(args, context) {
|
||||||
const { sectionId } = args;
|
const { sectionId, recursive } = args;
|
||||||
const { worktree } = context;
|
const { worktree } = context;
|
||||||
|
|
||||||
// Connect to LanceDB
|
// Connect to LanceDB
|
||||||
@@ -30,7 +38,7 @@ export default tool({
|
|||||||
|
|
||||||
// Create and execute tool
|
// Create and execute tool
|
||||||
const contentTool = createGetSectionContentTool(table);
|
const contentTool = createGetSectionContentTool(table);
|
||||||
const result = await contentTool.func({ sectionId });
|
const result = await contentTool.func({ sectionId, recursive });
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,6 +11,14 @@ const getSectionContentSchema = z.object({
|
|||||||
sectionId: z
|
sectionId: z
|
||||||
.string()
|
.string()
|
||||||
.describe("The section ID (e.g., 'sec-if-statement') to fetch chunks for"),
|
.describe("The section ID (e.g., 'sec-if-statement') to fetch chunks for"),
|
||||||
|
recursive: z
|
||||||
|
.boolean()
|
||||||
|
.default(true)
|
||||||
|
.describe(
|
||||||
|
"If true, recursively fetches content from all child sections and their descendants. " +
|
||||||
|
"If false, only returns content from the specified section itself. " +
|
||||||
|
"Use false when you only need the specific section's content without subsections.",
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,10 +32,10 @@ export function createGetSectionContentTool(table: Table) {
|
|||||||
name: "ask262_get_section_content",
|
name: "ask262_get_section_content",
|
||||||
description:
|
description:
|
||||||
"Retrieves all text chunks from a specific specification section by sectionid. " +
|
"Retrieves all text chunks from a specific specification section by sectionid. " +
|
||||||
"Supports recursive fetching - if a section has children, it will fetch all descendants. " +
|
"Supports recursive fetching - if recursive=true and the section has children, it will fetch all descendants. " +
|
||||||
"Use this to get complete content when you see 'Subsection available' or 'partial section' references.",
|
"Use this to get complete content when you see 'Subsection available' or 'partial section' references.",
|
||||||
schema: getSectionContentSchema,
|
schema: getSectionContentSchema,
|
||||||
func: async ({ sectionId }) => {
|
func: async ({ sectionId, recursive }) => {
|
||||||
const allDocs: string[] = [];
|
const allDocs: string[] = [];
|
||||||
const queue: string[] = [sectionId];
|
const queue: string[] = [sectionId];
|
||||||
const visited = new Set<string>();
|
const visited = new Set<string>();
|
||||||
@@ -61,8 +69,9 @@ export function createGetSectionContentTool(table: Table) {
|
|||||||
allDocs.push(typedResult.text);
|
allDocs.push(typedResult.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add children to queue for recursive fetching
|
// Add children to queue for recursive fetching only if recursive is true
|
||||||
if (
|
if (
|
||||||
|
recursive &&
|
||||||
typedResult.childrensectionids &&
|
typedResult.childrensectionids &&
|
||||||
Array.isArray(typedResult.childrensectionids)
|
Array.isArray(typedResult.childrensectionids)
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in New Issue
Block a user