-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Agent Builder] Agent skills implementation #251209
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
49 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 0b608e6
skill registration
KDKHD c21fcde
add skill to the file store
KDKHD 78cadf8
use filestore to build skill prompt
KDKHD 41cb18c
add tool manager & load skill tools
KDKHD bf820d8
tests
KDKHD 33475d7
Merge branch 'main' of github.com:elastic/kibana into feature/agent-b…
KDKHD 2bbfb8d
Changes from node scripts/eslint_all_files --no-cache --fix
kibanamachine d694503
improve zod skill type, fix lint and type errors
KDKHD aed5857
Merge branch 'feature/agent-builder-skills2' of github.com:KDKHD/kiba…
KDKHD ab85374
Changes from node scripts/eslint_all_files --no-cache --fix
kibanamachine 9244354
minor fixes
KDKHD 5e6506f
Merge branch 'feature/agent-builder-skills2' of github.com:KDKHD/kiba…
KDKHD 81e74b7
fix dynamic tool carry over & limit to 7 skill tools
KDKHD 2d116d3
code review
KDKHD 49b20da
Merge branch 'main' into feature/agent-builder-skills2
KDKHD e2db8fb
Changes from node scripts/eslint_all_files --no-cache --fix
kibanamachine 4a2c2c2
fix types
KDKHD 6b1f94a
fix test
KDKHD 1d674fc
Merge branch 'main' into feature/agent-builder-skills2
KDKHD 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
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
27 changes: 27 additions & 0 deletions
27
x-pack/platform/packages/shared/agent-builder/agent-builder-server/runner/skills_service.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,27 @@ | ||
| /* | ||
| * 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 { SkillDefinition, SkillBoundedTool } from '../skills'; | ||
| import type { ExecutableTool } from './tool_provider'; | ||
|
|
||
| /** | ||
| * Service to access skill type definitions. | ||
| */ | ||
| export interface SkillsService { | ||
| /** | ||
| * Returns the list of skill type definitions | ||
| */ | ||
| list(): SkillDefinition[]; | ||
| /** | ||
| * Returns the skill type definition for a given skill id | ||
| */ | ||
| getSkillDefinition(skillId: string): SkillDefinition | undefined; | ||
| /** | ||
| * Convert a skill-scoped tool to a generic executable tool | ||
| */ | ||
| convertSkillTool(tool: SkillBoundedTool): ExecutableTool; | ||
| } |
25 changes: 25 additions & 0 deletions
25
x-pack/platform/packages/shared/agent-builder/agent-builder-server/runner/skills_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,25 @@ | ||
| /* | ||
| * 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 { SkillDefinition } from '../skills'; | ||
|
|
||
| /** | ||
| * Store to access skills during execution | ||
| */ | ||
| export interface SkillsStore { | ||
| has(skillId: string): boolean; | ||
| get(resultId: string): SkillDefinition; | ||
| } | ||
|
|
||
| /** | ||
| * Writable version of SkillsStore, used internally by the runner/agent | ||
| */ | ||
| export interface WritableSkillsStore extends SkillsStore { | ||
| add(result: SkillDefinition): void; | ||
| delete(skillId: string): boolean; | ||
| asReadonly(): SkillsStore; | ||
| } |
81 changes: 81 additions & 0 deletions
81
x-pack/platform/packages/shared/agent-builder/agent-builder-server/runner/tool_manager.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,81 @@ | ||
| /* | ||
| * 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 { StructuredTool } from '@langchain/core/tools'; | ||
| import type { BrowserApiToolMetadata } from '@kbn/agent-builder-common'; | ||
| import type { Logger } from '@kbn/logging'; | ||
| import type { AgentEventEmitterFn, ExecutableTool } from '..'; | ||
|
|
||
| export interface ToolManagerParams { | ||
| dynamicToolCapacity: number; | ||
| } | ||
|
|
||
| export type ToolName = string; | ||
|
|
||
| export interface AddToolOptions { | ||
| dynamic?: boolean; | ||
| } | ||
|
|
||
| export enum ToolManagerToolType { | ||
| executable = 'executable', | ||
| browser = 'browser', | ||
| } | ||
|
|
||
| export interface ExecutableToolInput { | ||
| type: ToolManagerToolType.executable; | ||
| tools: ExecutableTool | ExecutableTool[]; | ||
| logger: Logger; | ||
| eventEmitter?: AgentEventEmitterFn; | ||
| } | ||
|
|
||
| export interface BrowserToolInput { | ||
| type: ToolManagerToolType.browser; | ||
| tools: BrowserApiToolMetadata | BrowserApiToolMetadata[]; | ||
| } | ||
|
|
||
| export type AddToolInput = ExecutableToolInput | BrowserToolInput; | ||
|
|
||
| /** | ||
| * Interface for managing tools in the agent system. | ||
| * Handles both static and dynamic tools with LRU eviction for dynamic tools. | ||
| */ | ||
| export interface ToolManager { | ||
| /** | ||
| * Adds tools to the tool manager. | ||
| * Supports both executable tools and browser API tools. | ||
| * @param input - The tool input configuration (executable or browser) | ||
| * @param options - Optional configuration for tool storage (static vs dynamic) | ||
| */ | ||
| addTools(input: AddToolInput, options?: AddToolOptions): Promise<void>; | ||
|
|
||
| /** | ||
| * Lists all tools in the tool manager. | ||
| * @returns an array of all tools (static and dynamic) | ||
| */ | ||
| list(): StructuredTool[]; | ||
|
|
||
| /** | ||
| * Records the use of a tool, marking it as recently used. | ||
| * This affects LRU eviction for dynamic tools. | ||
| * @param name - the name of the tool to record usage for | ||
| */ | ||
| recordToolUse(langchainToolName: ToolName): void; | ||
|
|
||
| /** | ||
| * Gets the tool id mapping. | ||
| * Maps LangChain tool names to internal tool IDs. | ||
| * @returns the tool id mapping | ||
| */ | ||
| getToolIdMapping(): Map<string, string>; | ||
|
|
||
| /** | ||
| * Gets the internal tool IDs of all dynamic tools currently in the tool manager. | ||
| * Returns internal tool IDs (not LangChain names) for persistence. | ||
| * @returns array of internal tool IDs | ||
| */ | ||
| getDynamicToolIds(): string[]; | ||
| } |
16 changes: 16 additions & 0 deletions
16
x-pack/platform/packages/shared/agent-builder/agent-builder-server/skills/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 type { SkillDefinition } from './type_definition'; | ||
| export { validateSkillDefinition } from './type_definition'; | ||
| export type { | ||
| SkillBoundedTool, | ||
| BuiltinSkillBoundedTool, | ||
| IndexSearchSkillBoundedTool, | ||
| WorkflowSkillBoundedTool, | ||
| StaticEsqlSkillBoundedTool, | ||
| } from './tools'; |
34 changes: 34 additions & 0 deletions
34
x-pack/platform/packages/shared/agent-builder/agent-builder-server/skills/tools.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,34 @@ | ||
| /* | ||
| * 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 { ZodObject } from '@kbn/zod'; | ||
| import type { EsqlToolDefinition, ToolDefinition } from '@kbn/agent-builder-common'; | ||
| import type { | ||
| IndexSearchToolDefinition, | ||
| WorkflowToolDefinition, | ||
| } from '@kbn/agent-builder-common/tools'; | ||
| import type { BuiltinToolDefinition } from '../tools/builtin'; | ||
|
|
||
| export type BuiltinSkillBoundedTool<RunInput extends ZodObject<any> = ZodObject<any>> = Omit< | ||
| BuiltinToolDefinition<RunInput>, | ||
| 'tags' | 'availability' | ||
| >; | ||
|
|
||
| type SkillBoundToolMixin<T extends ToolDefinition> = Omit<T, 'readonly' | 'tags'>; | ||
|
|
||
| export type StaticEsqlSkillBoundedTool = SkillBoundToolMixin<EsqlToolDefinition>; | ||
| export type IndexSearchSkillBoundedTool = SkillBoundToolMixin<IndexSearchToolDefinition>; | ||
| export type WorkflowSkillBoundedTool = SkillBoundToolMixin<WorkflowToolDefinition>; | ||
|
|
||
| /** | ||
| * Definition of a tool which is bounded to a skill instance. | ||
| */ | ||
| export type SkillBoundedTool<RunInput extends ZodObject<any> = ZodObject<any>> = | ||
| | BuiltinSkillBoundedTool<RunInput> | ||
| | StaticEsqlSkillBoundedTool | ||
| | IndexSearchSkillBoundedTool | ||
| | WorkflowSkillBoundedTool; | ||
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.
Note for myself: need to factorize that with the attachment bounded tools later (perfectly fine to keep it that way in the PR, I'll handle it later)