Skip to content

Commit 89254a9

Browse files
[Agent Builder] initial support for conversation attachments (#240423)
## Summary Fix elastic/search-team#11699 Add the base server-side implementation for conversation attachments. ## Example ### Registering an attachment type ```ts /** Creates the definition for the `text` attachment type. */ export const createTextAttachmentType = (): InlineAttachmentTypeDefinition<TextAttachmentData> => { const textDataSchema = z.object({ content: z.string(), }); return { id: AttachmentType.text, type: 'inline', validate: (input) => { const parseResult = textDataSchema.safeParse(input); if (parseResult.success) { return { valid: true, data: parseResult.data }; } else { return { valid: false, error: parseResult.error.message }; } }, format: (input) => { return { type: 'text', value: input.content }; }, }; }; ``` ### Adding an attachment when calling an agent ```js POST kbn://api/agent_builder/converse { "input": "Can you describe this attachment?", "attachments": [ { "type": "text", "data": { "content": "Lorem ipsum"}} ] } ``` ```js { "conversation_id": "ff84f588-c1e7-4ccb-bcd5-a44ed4733c6e", "trace_id": "9d422006f7a32b12bb72d5a3e1834d5a", "steps": [], "response": { "message": `The attachment contains the text "Lorem ipsum," which is commonly used as placeholder or dummy text in publishing and design. It does not convey specific information or content.` } } ``` --------- Co-authored-by: kibanamachine <[email protected]>
1 parent 1b41310 commit 89254a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1992
-85
lines changed

oas_docs/bundle.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,37 @@
17271727
"description": "The ID of the agent to chat with. Defaults to the default Elastic AI agent.",
17281728
"type": "string"
17291729
},
1730+
"attachments": {
1731+
"description": "Optional attachments to send with the message.",
1732+
"items": {
1733+
"additionalProperties": false,
1734+
"properties": {
1735+
"data": {
1736+
"additionalProperties": {},
1737+
"description": "Payload of the attachment.",
1738+
"type": "object"
1739+
},
1740+
"hidden": {
1741+
"description": "When true, the attachment will not be displayed in the UI.",
1742+
"type": "boolean"
1743+
},
1744+
"id": {
1745+
"description": "Optional id for the attachment.",
1746+
"type": "string"
1747+
},
1748+
"type": {
1749+
"description": "Type of the attachment.",
1750+
"type": "string"
1751+
}
1752+
},
1753+
"required": [
1754+
"type",
1755+
"data"
1756+
],
1757+
"type": "object"
1758+
},
1759+
"type": "array"
1760+
},
17301761
"capabilities": {
17311762
"additionalProperties": false,
17321763
"description": "Controls agent capabilities during conversation. Currently supports visualization rendering for tabular tool results.",
@@ -1850,6 +1881,37 @@
18501881
"description": "The ID of the agent to chat with. Defaults to the default Elastic AI agent.",
18511882
"type": "string"
18521883
},
1884+
"attachments": {
1885+
"description": "Optional attachments to send with the message.",
1886+
"items": {
1887+
"additionalProperties": false,
1888+
"properties": {
1889+
"data": {
1890+
"additionalProperties": {},
1891+
"description": "Payload of the attachment.",
1892+
"type": "object"
1893+
},
1894+
"hidden": {
1895+
"description": "When true, the attachment will not be displayed in the UI.",
1896+
"type": "boolean"
1897+
},
1898+
"id": {
1899+
"description": "Optional id for the attachment.",
1900+
"type": "string"
1901+
},
1902+
"type": {
1903+
"description": "Type of the attachment.",
1904+
"type": "string"
1905+
}
1906+
},
1907+
"required": [
1908+
"type",
1909+
"data"
1910+
],
1911+
"type": "object"
1912+
},
1913+
"type": "array"
1914+
},
18531915
"capabilities": {
18541916
"additionalProperties": false,
18551917
"description": "Controls agent capabilities during conversation. Currently supports visualization rendering for tabular tool results.",

oas_docs/bundle.serverless.json

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,6 +1727,37 @@
17271727
"description": "The ID of the agent to chat with. Defaults to the default Elastic AI agent.",
17281728
"type": "string"
17291729
},
1730+
"attachments": {
1731+
"description": "Optional attachments to send with the message.",
1732+
"items": {
1733+
"additionalProperties": false,
1734+
"properties": {
1735+
"data": {
1736+
"additionalProperties": {},
1737+
"description": "Payload of the attachment.",
1738+
"type": "object"
1739+
},
1740+
"hidden": {
1741+
"description": "When true, the attachment will not be displayed in the UI.",
1742+
"type": "boolean"
1743+
},
1744+
"id": {
1745+
"description": "Optional id for the attachment.",
1746+
"type": "string"
1747+
},
1748+
"type": {
1749+
"description": "Type of the attachment.",
1750+
"type": "string"
1751+
}
1752+
},
1753+
"required": [
1754+
"type",
1755+
"data"
1756+
],
1757+
"type": "object"
1758+
},
1759+
"type": "array"
1760+
},
17301761
"capabilities": {
17311762
"additionalProperties": false,
17321763
"description": "Controls agent capabilities during conversation. Currently supports visualization rendering for tabular tool results.",
@@ -1850,6 +1881,37 @@
18501881
"description": "The ID of the agent to chat with. Defaults to the default Elastic AI agent.",
18511882
"type": "string"
18521883
},
1884+
"attachments": {
1885+
"description": "Optional attachments to send with the message.",
1886+
"items": {
1887+
"additionalProperties": false,
1888+
"properties": {
1889+
"data": {
1890+
"additionalProperties": {},
1891+
"description": "Payload of the attachment.",
1892+
"type": "object"
1893+
},
1894+
"hidden": {
1895+
"description": "When true, the attachment will not be displayed in the UI.",
1896+
"type": "boolean"
1897+
},
1898+
"id": {
1899+
"description": "Optional id for the attachment.",
1900+
"type": "string"
1901+
},
1902+
"type": {
1903+
"description": "Type of the attachment.",
1904+
"type": "string"
1905+
}
1906+
},
1907+
"required": [
1908+
"type",
1909+
"data"
1910+
],
1911+
"type": "object"
1912+
},
1913+
"type": "array"
1914+
},
18531915
"capabilities": {
18541916
"additionalProperties": false,
18551917
"description": "Controls agent capabilities during conversation. Currently supports visualization rendering for tabular tool results.",

oas_docs/output/kibana.serverless.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,29 @@ paths:
14641464
default: elastic-ai-agent
14651465
description: The ID of the agent to chat with. Defaults to the default Elastic AI agent.
14661466
type: string
1467+
attachments:
1468+
description: Optional attachments to send with the message.
1469+
items:
1470+
additionalProperties: false
1471+
type: object
1472+
properties:
1473+
data:
1474+
additionalProperties: {}
1475+
description: Payload of the attachment.
1476+
type: object
1477+
hidden:
1478+
description: When true, the attachment will not be displayed in the UI.
1479+
type: boolean
1480+
id:
1481+
description: Optional id for the attachment.
1482+
type: string
1483+
type:
1484+
description: Type of the attachment.
1485+
type: string
1486+
required:
1487+
- type
1488+
- data
1489+
type: array
14671490
capabilities:
14681491
additionalProperties: false
14691492
description: Controls agent capabilities during conversation. Currently supports visualization rendering for tabular tool results.
@@ -1546,6 +1569,29 @@ paths:
15461569
default: elastic-ai-agent
15471570
description: The ID of the agent to chat with. Defaults to the default Elastic AI agent.
15481571
type: string
1572+
attachments:
1573+
description: Optional attachments to send with the message.
1574+
items:
1575+
additionalProperties: false
1576+
type: object
1577+
properties:
1578+
data:
1579+
additionalProperties: {}
1580+
description: Payload of the attachment.
1581+
type: object
1582+
hidden:
1583+
description: When true, the attachment will not be displayed in the UI.
1584+
type: boolean
1585+
id:
1586+
description: Optional id for the attachment.
1587+
type: string
1588+
type:
1589+
description: Type of the attachment.
1590+
type: string
1591+
required:
1592+
- type
1593+
- data
1594+
type: array
15491595
capabilities:
15501596
additionalProperties: false
15511597
description: Controls agent capabilities during conversation. Currently supports visualization rendering for tabular tool results.

oas_docs/output/kibana.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,29 @@ paths:
16511651
default: elastic-ai-agent
16521652
description: The ID of the agent to chat with. Defaults to the default Elastic AI agent.
16531653
type: string
1654+
attachments:
1655+
description: Optional attachments to send with the message.
1656+
items:
1657+
additionalProperties: false
1658+
type: object
1659+
properties:
1660+
data:
1661+
additionalProperties: {}
1662+
description: Payload of the attachment.
1663+
type: object
1664+
hidden:
1665+
description: When true, the attachment will not be displayed in the UI.
1666+
type: boolean
1667+
id:
1668+
description: Optional id for the attachment.
1669+
type: string
1670+
type:
1671+
description: Type of the attachment.
1672+
type: string
1673+
required:
1674+
- type
1675+
- data
1676+
type: array
16541677
capabilities:
16551678
additionalProperties: false
16561679
description: Controls agent capabilities during conversation. Currently supports visualization rendering for tabular tool results.
@@ -1740,6 +1763,29 @@ paths:
17401763
default: elastic-ai-agent
17411764
description: The ID of the agent to chat with. Defaults to the default Elastic AI agent.
17421765
type: string
1766+
attachments:
1767+
description: Optional attachments to send with the message.
1768+
items:
1769+
additionalProperties: false
1770+
type: object
1771+
properties:
1772+
data:
1773+
additionalProperties: {}
1774+
description: Payload of the attachment.
1775+
type: object
1776+
hidden:
1777+
description: When true, the attachment will not be displayed in the UI.
1778+
type: boolean
1779+
id:
1780+
description: Optional id for the attachment.
1781+
type: string
1782+
type:
1783+
description: Type of the attachment.
1784+
type: string
1785+
required:
1786+
- type
1787+
- data
1788+
type: array
17431789
capabilities:
17441790
additionalProperties: false
17451791
description: Controls agent capabilities during conversation. Currently supports visualization rendering for tabular tool results.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
/**
9+
* List of internal / built-in attachment types.
10+
*
11+
* The list is not fixed, as contributors can add their own attachment types.
12+
*/
13+
export enum AttachmentType {
14+
screenContext = 'screen_context',
15+
text = 'text',
16+
}
17+
18+
interface AttachmentDataMap {
19+
[AttachmentType.text]: TextAttachmentData;
20+
[AttachmentType.screenContext]: ScreenContextAttachmentData;
21+
}
22+
23+
/**
24+
* Data for a text attachment.
25+
*/
26+
export interface TextAttachmentData {
27+
/** text content of the attachment */
28+
content: string;
29+
}
30+
31+
/**
32+
* Data for a screen context attachment.
33+
*/
34+
export interface ScreenContextAttachmentData {
35+
/** current url */
36+
url?: string;
37+
/** kibana app name */
38+
app?: string;
39+
/** app description */
40+
description?: string;
41+
/** arbitrary additional context data */
42+
additional_data?: Record<string, string>;
43+
}
44+
45+
export type AttachmentDataOf<Type extends AttachmentType> = AttachmentDataMap[Type];
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import type { AttachmentType, AttachmentDataOf } from './attachment_types';
9+
10+
/**
11+
* Represents a conversation attachment, as returned by the conversation API.
12+
*/
13+
export interface Attachment<
14+
Type extends string = string,
15+
DataType = Type extends AttachmentType ? AttachmentDataOf<Type> : Record<string, unknown>
16+
> {
17+
/** Unique identifier for the attachment */
18+
id: string;
19+
/** Type of the attachment */
20+
type: Type;
21+
/** data bound to the attachment */
22+
data: DataType;
23+
/** should the attachment be hidden from the user - e.g. for screen context */
24+
hidden?: boolean;
25+
}
26+
27+
// Strongly typed sub-types for known attachment types
28+
29+
export type TextAttachment = Attachment<AttachmentType.text>;
30+
export type ScreenContextAttachment = Attachment<AttachmentType.screenContext>;
31+
32+
/**
33+
* Input version of an attachment, where the id is optional
34+
*/
35+
export type AttachmentInput = Omit<Attachment, 'id'> & Partial<Pick<Attachment, 'id'>>;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
export type {
9+
Attachment,
10+
TextAttachment,
11+
ScreenContextAttachment,
12+
AttachmentInput,
13+
} from './attachments';
14+
export {
15+
AttachmentType,
16+
type TextAttachmentData,
17+
type ScreenContextAttachmentData,
18+
} from './attachment_types';

0 commit comments

Comments
 (0)