-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Agent Builder] filestore: initial implementation #250043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
3c18b6c
add memfs to deps
pgayvallet e4879d6
work in progress
pgayvallet c1bca2f
I totally did that alone
pgayvallet b136796
move FS files, adapt tool result store and runner
pgayvallet 0f22dcd
Merge remote-tracking branch 'upstream/main' into ab-12348-fs-store
pgayvallet 9942e7e
preparing store interface
pgayvallet d0d69ff
implement fs_store, update read tool
pgayvallet 710fe39
create base set of tools
pgayvallet f71fe46
move types to server package
pgayvallet 97f1663
fix unit tests
pgayvallet 5e92995
plug FS tools to agent
pgayvallet f97f223
Merge remote-tracking branch 'upstream/main' into ab-12348-fs-store
pgayvallet 477cef4
remove memfs
pgayvallet 0b029fb
use constants for tool names
pgayvallet c17e3e8
fix mocks
pgayvallet 77bf6a0
export class to please TS
pgayvallet 42402db
add folder tree util
pgayvallet 5e51506
cleanup agent execution
pgayvallet 5351aaf
move timestamp to prompt factory
pgayvallet 0fd234b
clean exports
pgayvallet 1b0f548
fix types again
pgayvallet 8534c6d
Merge remote-tracking branch 'upstream/main' into ab-12348-fs-store
pgayvallet d716cd4
rename filesystem to filestore + cleanup
pgayvallet 36dcac4
change namespace
pgayvallet 72fbe61
remove duplicate instructions
pgayvallet 4a92f7d
add kill switch
pgayvallet 1a1e930
add filestore to descriptions
pgayvallet c7ffc30
update prompt
pgayvallet 447200b
update prompt again
pgayvallet e9ce8e4
last time
pgayvallet 701f784
Merge remote-tracking branch 'upstream/main' into ab-12348-fs-store
pgayvallet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...atform/packages/shared/agent-builder/agent-builder-genai-utils/tools/utils/token_count.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| /** | ||
| * Estimates token count for given string or arbitrary data. | ||
| * Uses a simple heuristic: ~4 characters per token. | ||
| */ | ||
| export const estimateTokens = (data: unknown): number => { | ||
| const str = typeof data === 'string' ? data : JSON.stringify(data); | ||
| return Math.ceil(str.length / 4); | ||
| }; | ||
|
|
||
| /** | ||
| * Truncates a string to a given number of tokens. | ||
| * Uses a simple heuristic: ~4 characters per token. | ||
| */ | ||
| export const truncateTokens = (data: string, maxTokens: number): string => { | ||
| return data.slice(0, maxTokens * 4); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...latform/packages/shared/agent-builder/agent-builder-server/runner/filestore/filesystem.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| /** | ||
| * Possible types of entries stored in the store. | ||
| */ | ||
| export enum FileEntryType { | ||
| toolResult = 'tool_result', | ||
| attachment = 'attachment', | ||
| } | ||
|
|
||
| export type FileEntryMetadata<TExtraMeta extends object = {}> = { | ||
| /** | ||
| * Type of the entry (tool_result, attachment...) | ||
| */ | ||
| type: FileEntryType; | ||
| /** | ||
| * Unique identifier of the entry, (unique for its type) | ||
| */ | ||
| id: string; | ||
| /** | ||
| * Estimated length, in tokens, of the content of the raw content. | ||
| */ | ||
| token_count: number; | ||
| /** | ||
| * Defines if the entry can be modified or not. | ||
| */ | ||
| readonly: boolean; | ||
| } /** extra per-type metadata */ & TExtraMeta; | ||
|
|
||
| export interface FileEntryContent<TData extends object = object> { | ||
| /** | ||
| * Raw content of the file. | ||
| */ | ||
| raw: TData; | ||
| /** | ||
| * Plain text representation of the file content, which can be used for grep. | ||
| */ | ||
| plain_text?: string; | ||
| } | ||
|
|
||
| /** | ||
| * A file entry in the virtual filesystem. | ||
| */ | ||
| export interface FileEntry<TContent extends object = object, TMeta extends object = object> { | ||
| path: string; | ||
| type: 'file'; | ||
| metadata: FileEntryMetadata<TMeta>; | ||
| content: FileEntryContent<TContent>; | ||
| } | ||
|
|
||
| /** | ||
| * A directory entry in the virtual filesystem. | ||
| */ | ||
| export interface DirEntry { | ||
| path: string; | ||
| type: 'dir'; | ||
| } | ||
|
|
||
| /** | ||
| * Either a file or directory entry. | ||
| */ | ||
| export type FsEntry = FileEntry | DirEntry; |
16 changes: 16 additions & 0 deletions
16
x-pack/platform/packages/shared/agent-builder/agent-builder-server/runner/filestore/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| export { | ||
| FileEntryType, | ||
| type FileEntry, | ||
| type FsEntry, | ||
| type FileEntryContent, | ||
| type FileEntryMetadata, | ||
| type DirEntry, | ||
| } from './filesystem'; | ||
| export type { IFileStore, IToolFileStore, LsEntry, DirEntryWithChildren, GrepMatch } from './store'; |
73 changes: 73 additions & 0 deletions
73
x-pack/platform/packages/shared/agent-builder/agent-builder-server/runner/filestore/store.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import type { FileEntry, DirEntry } from './filesystem'; | ||
|
|
||
| /** | ||
| * Main interface for the public API of the file store. | ||
| */ | ||
| export interface IFileStore { | ||
| /** | ||
| * Read a file entry from the store. | ||
| * | ||
| * @param path path of the file to read. | ||
| */ | ||
| read(path: string): Promise<FileEntry | undefined>; | ||
| /** | ||
| * List files and directories at the given path. | ||
| * | ||
| * @param path path of the directory to list. | ||
| * @param options.depth optional level of depth to include (default to 1). | ||
| */ | ||
| ls(path: string, options?: { depth?: number }): Promise<LsEntry[]>; | ||
| /** | ||
| * List files matching the given glob pattern. | ||
| * | ||
| * @param pattern glob pattern to match. | ||
| */ | ||
| glob(pattern: string): Promise<FileEntry[]>; | ||
| /** | ||
| * Search files with text matching the given pattern. | ||
| * | ||
| * @param pattern The pattern to search for. | ||
| * @param glob The glob pattern to match files against. | ||
| * @param options.context Optional number of lines of context to include before and after the match. | ||
| * @param options.fixed If true, treat pattern as literal text (like grep -F). Default: false (regex). | ||
| */ | ||
| grep( | ||
| pattern: string, | ||
| glob: string, | ||
| options?: { context?: number; fixed?: boolean } | ||
| ): Promise<GrepMatch[]>; | ||
| } | ||
|
|
||
| /** | ||
| * Distinct interface for the API exposed to tool handlers. | ||
| * The same for now, but will change in the future. | ||
| */ | ||
| export type IToolFileStore = IFileStore; | ||
|
|
||
| export interface DirEntryWithChildren extends DirEntry { | ||
| children?: LsEntry[]; | ||
| } | ||
|
|
||
| export type LsEntry = DirEntryWithChildren | FileEntry; | ||
|
|
||
| export interface GrepMatch { | ||
| /** | ||
| * Reference to the file entry that matched. | ||
| */ | ||
| entry: FileEntry; | ||
| /** | ||
| * Line number of the match. | ||
| */ | ||
| line: number; | ||
| /** | ||
| * The matched text, (with pre/post context lines depending on call options). | ||
| */ | ||
| match: string; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started with
platform.filestore, but then changed to justfilestorefor a few reasonsplatformprefix is used for "real"/"selectable" tools, I don't think we need those "internal" tools to use the same top-level prefixplatform.filestorewould have worked perfectly well too)Now if someone is strongly opposed or have another idea, please state so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep its a good idea. I very much doubt customers have already claimed this "namespace" but worth checking what happens in that case (who takes priority)