Skip to content

The open alternative to Salesforce, designed for AI.

Record runAgent calls made without a thread (#27337)

Félix Malfait2c846b35a1b3
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
index 07b16669f9d..814c72c8420 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
@@ -3620,6 +3620,34 @@ type RecordExport {
downloadPath: String
}
+type AgentRun {
+ id: UUID!
+ threadId: UUID!
+ threadTitle: String
+ status: AgentTurnStatus!
+ errorMessage: String
+ createdAt: DateTime!
+ startedAt: DateTime
+ endedAt: DateTime
+ modelId: String
+ inputTokens: Int
+ outputTokens: Int
+ credits: Float
+ creatorSource: String!
+ creatorName: String!
+ input: String
+ reply: String
+ toolNames: [String!]!
+}
+
+enum AgentTurnStatus {
+ RUNNING
+ WAITING_FOR_INPUT
+ COMPLETED
+ CANCELLED
+ FAILED
+}
+
type WorkspaceAiStats {
conversationsCount: Int!
skillsCount: Int!
@@ -3995,6 +4023,7 @@ type Query {
getAiSystemPromptPreview: AiSystemPromptPreview!
skills: [Skill!]!
skill(id: UUID!): Skill
+ agentRuns(agentId: UUID!, limit: Int! = 100): [AgentRun!]!
validationRules(objectMetadataId: UUID!): [ValidationRule!]!
timelineActivityTypes: [TimelineActivityType!]!
metadataTranslations(input: MetadataTranslationsInput!): [MetadataTranslation!]!
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.ts b/packages/twenty-client-sdk/src/metadata/generated/schema.ts
index e42a07e77a4..0a1678b1cb7 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/schema.ts
+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.ts
@@ -3178,6 +3178,29 @@ export interface RecordExport {
__typename: 'RecordExport'
}
+export interface AgentRun {
+ id: Scalars['UUID']
+ threadId: Scalars['UUID']
+ threadTitle?: Scalars['String']
+ status: AgentTurnStatus
+ errorMessage?: Scalars['String']
+ createdAt: Scalars['DateTime']
+ startedAt?: Scalars['DateTime']
+ endedAt?: Scalars['DateTime']
+ modelId?: Scalars['String']
+ inputTokens?: Scalars['Int']
+ outputTokens?: Scalars['Int']
+ credits?: Scalars['Float']
+ creatorSource: Scalars['String']
+ creatorName: Scalars['String']
+ input?: Scalars['String']
+ reply?: Scalars['String']
+ toolNames: Scalars['String'][]
+ __typename: 'AgentRun'
+}
+
+export type AgentTurnStatus = 'RUNNING' | 'WAITING_FOR_INPUT' | 'COMPLETED' | 'CANCELLED' | 'FAILED'
+
export interface WorkspaceAiStats {
conversationsCount: Scalars['Int']
skillsCount: Scalars['Int']
@@ -3480,6 +3503,7 @@ export interface Query {
getAiSystemPromptPreview: AiSystemPromptPreview
skills: Skill[]
skill?: Skill
+ agentRuns: AgentRun[]
validationRules: ValidationRule[]
timelineActivityTypes: TimelineActivityType[]
metadataTranslations: MetadataTranslation[]
@@ -7120,6 +7144,28 @@ export interface RecordExportGenqlSelection{
__scalar?: boolean | number
}
+export interface AgentRunGenqlSelection{
+ id?: boolean | number
+ threadId?: boolean | number
+ threadTitle?: boolean | number
+ status?: boolean | number
+ errorMessage?: boolean | number
+ createdAt?: boolean | number
+ startedAt?: boolean | number
+ endedAt?: boolean | number
+ modelId?: boolean | number
+ inputTokens?: boolean | number
+ outputTokens?: boolean | number
+ credits?: boolean | number
+ creatorSource?: boolean | number
+ creatorName?: boolean | number
+ input?: boolean | number
+ reply?: boolean | number
+ toolNames?: boolean | number
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
export interface WorkspaceAiStatsGenqlSelection{
conversationsCount?: boolean | number
skillsCount?: boolean | number
@@ -7430,6 +7476,7 @@ export interface QueryGenqlSelection{
getAiSystemPromptPreview?: AiSystemPromptPreviewGenqlSelection
skills?: SkillGenqlSelection
skill?: (SkillGenqlSelection & { __args: {id: Scalars['UUID']} })
+ agentRuns?: (AgentRunGenqlSelection & { __args: {agentId: Scalars['UUID'], limit: Scalars['Int']} })
validationRules?: (ValidationRuleGenqlSelection & { __args: {objectMetadataId: Scalars['UUID']} })
timelineActivityTypes?: TimelineActivityTypeGenqlSelection
metadataTranslations?: (MetadataTranslationGenqlSelection & { __args: {input: MetadataTranslationsInput} })
@@ -10618,6 +10665,14 @@ export interface CreateRecordExportInput {objectMetadataId: Scalars['UUID'],fiel
+ const AgentRun_possibleTypes: string[] = ['AgentRun']
+ export const isAgentRun = (obj?: { __typename?: any } | null): obj is AgentRun => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isAgentRun"')
+ return AgentRun_possibleTypes.includes(obj.__typename)
+ }
+
+
+
const WorkspaceAiStats_possibleTypes: string[] = ['WorkspaceAiStats']
export const isWorkspaceAiStats = (obj?: { __typename?: any } | null): obj is WorkspaceAiStats => {
if (!obj?.__typename) throw new Error('__typename is missing in "isWorkspaceAiStats"')
@@ -11608,6 +11663,14 @@ export const enumWorkspaceSetupChatOutcome = {
UNAVAILABLE: 'UNAVAILABLE' as const
}
+export const enumAgentTurnStatus = {
+ RUNNING: 'RUNNING' as const,
+ WAITING_FOR_INPUT: 'WAITING_FOR_INPUT' as const,
+ COMPLETED: 'COMPLETED' as const,
+ CANCELLED: 'CANCELLED' as const,
+ FAILED: 'FAILED' as const
+}
+
export const enumAppKeyValueScope = {
WORKSPACE: 'WORKSPACE' as const,
SERVER: 'SERVER' as const
diff --git a/packages/twenty-client-sdk/src/metadata/generated/types.ts b/packages/twenty-client-sdk/src/metadata/generated/types.ts
index 8ba1b8234ca..11d2e9f5bb7 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/types.ts
+++ b/packages/twenty-client-sdk/src/metadata/generated/types.ts
@@ -99,20 +99,21 @@ export default {
356,
359,
394,
- 405,
+ 402,
407,
- 408,
409,
410,
+ 411,
412,
414,
- 421,
- 439,
- 443,
- 454,
- 574,
- 581,
- 609
+ 416,
+ 423,
+ 441,
+ 445,
+ 456,
+ 576,
+ 583,
+ 611
],
"types": {
"BillingProductDTO": {
@@ -7099,6 +7100,63 @@ export default {
1
]
},
+ "AgentRun": {
+ "id": [
+ 3
+ ],
+ "threadId": [
+ 3
+ ],
+ "threadTitle": [
+ 1
+ ],
+ "status": [
+ 402
+ ],
+ "errorMessage": [
+ 1
+ ],
+ "createdAt": [
+ 4
+ ],
+ "startedAt": [
+ 4
+ ],
+ "endedAt": [
+ 4
+ ],
+ "modelId": [
+ 1
+ ],
+ "inputTokens": [
+ 31
+ ],
+ "outputTokens": [
+ 31
+ ],
+ "credits": [
+ 15
+ ],
+ "creatorSource": [
+ 1
+ ],
+ "creatorName": [
+ 1
+ ],
+ "input": [
+ 1
+ ],
+ "reply": [
+ 1
+ ],
+ "toolNames": [
+ 1
+ ],
+ "__typename": [
+ 1
+ ]
+ },
+ "AgentTurnStatus": {},
"WorkspaceAiStats": {
"conversationsCount": [
31
@@ -7152,7 +7210,7 @@ export default {
9
],
"scope": [
- 405
+ 407
],
"__typename": [
1
@@ -7167,19 +7225,19 @@ export default {
1
],
"syncStatus": [
- 407
+ 409
],
"syncStage": [
- 408
+ 410
],
"visibility": [
- 409
+ 411
],
"isContactAutoCreationEnabled": [
8
],
"contactAutoCreationPolicy": [
- 410
+ 412
],
"isSyncEnabled": [
8
@@ -7230,7 +7288,7 @@ export default {
1
],
"pendingSyncAction": [
- 412
+ 414
],
"messageChannelId": [
3
@@ -7272,7 +7330,7 @@ export default {
1
],
"provenance": [
- 414
+ 416
],
"__typename": [
1
@@ -7301,7 +7359,7 @@ export default {
3
],
"through": [
- 415
+ 417
],
"__typename": [
1
@@ -7321,7 +7379,7 @@ export default {
1
],
"emit": [
- 416
+ 418
],
"action": [
1
@@ -7423,7 +7481,7 @@ export default {
},
"CollectionHash": {
"collectionName": [
- 421
+ 423
],
"hash": [
1
@@ -7487,13 +7545,13 @@ export default {
},
"MinimalMetadata": {
"objectMetadataItems": [
- 422
+ 424
],
"views": [
- 423
+ 425
],
"collectionHashes": [
- 420
+ 422
],
"__typename": [
1
@@ -7504,7 +7562,7 @@ export default {
189,
{
"target": [
- 426,
+ 428,
"RecordTargetInput!"
]
}
@@ -7513,7 +7571,7 @@ export default {
191,
{
"targets": [
- 426,
+ 428,
"[RecordTargetInput!]!"
]
}
@@ -7580,7 +7638,7 @@ export default {
175,
{
"input": [
- 427,
+ 429,
"UsageQuotaScopeInput!"
]
}
@@ -7589,7 +7647,7 @@ export default {
166,
{
"input": [
- 428
+ 430
]
}
],
@@ -7747,7 +7805,7 @@ export default {
10,
{
"input": [
- 429,
+ 431,
"AgentIdInput!"
]
}
@@ -7760,7 +7818,7 @@ export default {
"CursorPaging!"
],
"filter": [
- 430,
+ 432,
"ObjectFilter!"
]
}
@@ -7793,7 +7851,7 @@ export default {
23,
{
"input": [
- 431,
+ 433,
"LogicFunctionIdInput!"
]
}
@@ -7805,7 +7863,7 @@ export default {
9,
{
"input": [
- 431,
+ 433,
"LogicFunctionIdInput!"
]
}
@@ -7814,7 +7872,7 @@ export default {
1,
{
"input": [
- 431,
+ 433,
"LogicFunctionIdInput!"
]
}
@@ -7900,7 +7958,7 @@ export default {
2,
{
"input": [
- 432,
+ 434,
"GetApiKeyInput!"
]
}
@@ -8142,7 +8200,7 @@ export default {
349,
{
"input": [
- 433,
+ 435,
"PreviewMessageCampaignAudienceInput!"
]
}
@@ -8151,7 +8209,7 @@ export default {
357,
{
"input": [
- 434,
+ 436,
"FindMessageSuppressionsInput!"
]
}
@@ -8171,7 +8229,7 @@ export default {
338,
{
"filter": [
- 435
+ 437
]
}
],
@@ -8203,7 +8261,7 @@ export default {
}
],
"myMessageFolders": [
- 411,
+ 413,
{
"messageChannelId": [
3
@@ -8211,7 +8269,7 @@ export default {
}
],
"myCalendarChannels": [
- 406,
+ 408,
{
"connectedAccountId": [
3
@@ -8219,20 +8277,20 @@ export default {
}
],
"getPermissionFlags": [
- 419
+ 421
],
"minimalMetadata": [
- 424
+ 426
],
"appKeyValue": [
- 404,
+ 406,
{
"key": [
1,
"String!"
],
"scope": [
- 405
+ 407
]
}
],
@@ -8249,7 +8307,7 @@ export default {
246,
{
"filter": [
- 436
+ 438
]
}
],
@@ -8263,7 +8321,7 @@ export default {
}
],
"findWorkspaceAiStats": [
- 401
+ 403
],
"aiChatUsage": [
382
@@ -8310,8 +8368,21 @@ export default {
]
}
],
+ "agentRuns": [
+ 401,
+ {
+ "agentId": [
+ 3,
+ "UUID!"
+ ],
+ "limit": [
+ 31,
+ "Int!"
+ ]
+ }
+ ],
"validationRules": [
- 418,
+ 420,
{
"objectMetadataId": [
3,
@@ -8320,13 +8391,13 @@ export default {
}
],
"timelineActivityTypes": [
- 417
+ 419
],
"metadataTranslations": [
- 413,
+ 415,
{
"input": [
- 437,
+ 439,
"MetadataTranslationsInput!"
]
}
@@ -8392,7 +8463,7 @@ export default {
399,
{
"input": [
- 438,
+ 440,
"EventLogQueryInput!"
]
}
@@ -8401,7 +8472,7 @@ export default {
380,
{
"input": [
- 444,
+ 446,
"PieChartDataInput!"
]
}
@@ -8410,7 +8481,7 @@ export default {
378,
{
"input": [
- 445,
+ 447,
"LineChartDataInput!"
]
}
@@ -8419,7 +8490,7 @@ export default {
375,
{
"input": [
- 446,
+ 448,
"BarChartDataInput!"
]
}
@@ -8563,10 +8634,10 @@ export default {
},
"ObjectFilter": {
"and": [
- 430
+ 432
],
"or": [
- 430
+ 432
],
"id": [
34
@@ -8684,10 +8755,10 @@ export default {
},
"EventLogQueryInput": {
"table": [
- 439
+ 441
],
"filters": [
- 440
+ 442
],
"first": [
31
@@ -8708,7 +8779,7 @@ export default {
1
],
"dateRange": [
- 441
+ 443
],
"recordId": [
1
@@ -8717,7 +8788,7 @@ export default {
1
],
"fieldFilters": [
- 442
+ 444
],
"__typename": [
1
@@ -8739,7 +8810,7 @@ export default {
1
],
"operand": [
- 443
+ 445
],
"values": [
1
@@ -8787,7 +8858,7 @@ export default {
8,
{
"input": [
- 448,
+ 450,
"AddQuerySubscriptionInput!"
]
}
@@ -8796,7 +8867,7 @@ export default {
8,
{
"input": [
- 449,
+ 451,
"RemoveQueryFromEventStreamInput!"
]
}
@@ -8805,7 +8876,7 @@ export default {
189,
{
"target": [
- 426,
+ 428,
"RecordTargetInput!"
],
"accessLevel": [
@@ -8818,11 +8889,11 @@ export default {
189,
{
"target": [
- 426,
+ 428,
"RecordTargetInput!"
],
"principal": [
- 450,
+ 452,
"RecordSharePrincipalInput!"
],
"accessLevel": [
@@ -8835,11 +8906,11 @@ export default {
189,
{
"target": [
- 426,
+ 428,
"RecordTargetInput!"
],
"principal": [
- 450,
+ 452,
"RecordSharePrincipalInput!"
]
}
@@ -8848,7 +8919,7 @@ export default {
180,
{
"inputs": [
- 451,
+ 453,
"[CreateNavigationMenuItemInput!]!"
]
}
@@ -8857,7 +8928,7 @@ export default {
180,
{
"input": [
- 451,
+ 453,
"CreateNavigationMenuItemInput!"
]
}
@@ -8866,7 +8937,7 @@ export default {
180,
{
"inputs": [
- 452,
+ 454,
"[UpdateOneNavigationMenuItemInput!]!"
]
}
@@ -8875,7 +8946,7 @@ export default {
180,
{
"input": [
- 452,
+ 454,
"UpdateOneNavigationMenuItemInput!"
]
}
@@ -8949,7 +9020,7 @@ export default {
177,
{
"file": [
- 454,
+ 456,
"Upload!"
]
}
@@ -8958,7 +9029,7 @@ export default {
177,
{
"file": [
- 454,
+ 456,
"Upload!"
]
}
@@ -8985,7 +9056,7 @@ export default {
177,
{
"file": [
- 454,
+ 456,
"Upload!"
],
"fieldMetadataUniversalIdentifier": [
@@ -8998,7 +9069,7 @@ export default {
176,
{
"input": [
- 455,
+ 457,
"CreateUsageLimitInput!"
]
}
@@ -9007,7 +9078,7 @@ export default {
176,
{
"input": [
- 456,
+ 458,
"UpdateUsageLimitInput!"
]
}
@@ -9025,7 +9096,7 @@ export default {
103,
{
"input": [
- 457,
+ 459,
"CreatePageLayoutWidgetInput!"
]
}
@@ -9038,7 +9109,7 @@ export default {
"String!"
],
"input": [
- 458,
+ 460,
"UpdatePageLayoutWidgetInput!"
]
}
@@ -9056,7 +9127,7 @@ export default {
149,
{
"input": [
- 459,
+ 461,
"CreatePageLayoutTabInput!"
]
}
@@ -9069,7 +9140,7 @@ export default {
"String!"
],
"input": [
- 460,
+ 462,
"UpdatePageLayoutTabInput!"
]
}
@@ -9087,7 +9158,7 @@ export default {
150,
{
"input": [
- 461,
+ 463,
"CreatePageLayoutInput!"
]
}
@@ -9100,7 +9171,7 @@ export default {
"String!"
],
"input": [
- 462,
+ 464,
"UpdatePageLayoutInput!"
]
}
@@ -9122,7 +9193,7 @@ export default {
"String!"
],
"input": [
- 463,
+ 465,
"UpdatePageLayoutWithTabsInput!"
]
}
@@ -9158,7 +9229,7 @@ export default {
66,
{
"input": [
- 466,
+ 468,
"CreateViewInput!"
]
}
@@ -9171,7 +9242,7 @@ export default {
"String!"
],
"input": [
- 467,
+ 469,
"UpdateViewInput!"
]
}
@@ -9198,7 +9269,7 @@ export default {
66,
{
"input": [
- 468,
+ 470,
"UpsertViewWidgetInput!"
]
}
@@ -9207,7 +9278,7 @@ export default {
63,
{
"input": [
- 474,
+ 476,
"CreateViewSortInput!"
]
}
@@ -9216,7 +9287,7 @@ export default {
63,
{
"input": [
- 475,
+ 477,
"UpdateViewSortInput!"
]
}
@@ -9225,7 +9296,7 @@ export default {
8,
{
"input": [
- 477,
+ 479,
"DeleteViewSortInput!"
]
}
@@ -9234,7 +9305,7 @@ export default {
8,
{
"input": [
- 478,
+ 480,
"DestroyViewSortInput!"
]
}
@@ -9243,7 +9314,7 @@ export default {
60,
{
"input": [
- 479,
+ 481,
"CreateViewFilterInput!"
]
}
@@ -9252,7 +9323,7 @@ export default {
60,
{
"input": [
- 480,
+ 482,
"UpdateViewFilterInput!"
]
}
@@ -9261,7 +9332,7 @@ export default {
60,
{
"input": [
- 482,
+ 484,
"DeleteViewFilterInput!"
]
}
@@ -9270,7 +9341,7 @@ export default {
60,
{
"input": [
- 483,
+ 485,
"DestroyViewFilterInput!"
]
}
@@ -9279,7 +9350,7 @@ export default {
56,
{
"input": [
- 484,
+ 486,
"UpdateViewFieldInput!"
]
}
@@ -9288,7 +9359,7 @@ export default {
56,
{
"input": [
- 486,
+ 488,
"CreateViewFieldInput!"
]
}
@@ -9297,7 +9368,7 @@ export default {
56,
{
"inputs": [
- 486,
+ 488,
"[CreateViewFieldInput!]!"
]
}
@@ -9306,7 +9377,7 @@ export default {
56,
{
"input": [
- 487,
+ 489,
"DeleteViewFieldInput!"
]
}
@@ -9315,7 +9386,7 @@ export default {
56,
{
"input": [
- 488,
+ 490,
"DestroyViewFieldInput!"
]
}
@@ -9324,7 +9395,7 @@ export default {
65,
{
"input": [
- 489,
+ 491,
"UpdateViewFieldGroupInput!"
]
}
@@ -9333,7 +9404,7 @@ export default {
65,
{
"input": [
- 491,
+ 493,
"CreateViewFieldGroupInput!"
]
}
@@ -9342,7 +9413,7 @@ export default {
65,
{
"inputs": [
- 491,
+ 493,
"[CreateViewFieldGroupInput!]!"
]
}
@@ -9351,7 +9422,7 @@ export default {
65,
{
"input": [
- 492,
+ 494,
"DeleteViewFieldGroupInput!"
]
}
@@ -9360,7 +9431,7 @@ export default {
65,
{
"input": [
- 493,
+ 495,
"DestroyViewFieldGroupInput!"
]
}
@@ -9369,7 +9440,7 @@ export default {
66,
{
"input": [
- 494,
+ 496,
"UpsertFieldsWidgetInput!"
]
}
@@ -9378,7 +9449,7 @@ export default {
10,
{
"input": [
- 497,
+ 499,
"CreateAgentInput!"
]
}
@@ -9387,7 +9458,7 @@ export default {
10,
{
"input": [
- 498,
+ 500,
"UpdateAgentInput!"
]
}
@@ -9396,7 +9467,7 @@ export default {
10,
{
"input": [
- 429,
+ 431,
"AgentIdInput!"
]
}
@@ -9405,7 +9476,7 @@ export default {
25,
{
"input": [
- 499,
+ 501,
"CreateOneObjectInput!"
]
}
@@ -9414,7 +9485,7 @@ export default {
25,
{
"input": [
- 501,
+ 503,
"DeleteOneObjectInput!"
]
}
@@ -9423,7 +9494,7 @@ export default {
25,
{
"input": [
- 502,
+ 504,
"UpdateOneObjectInput!"
]
}
@@ -9432,7 +9503,7 @@ export default {
25,
{
"inputs": [
- 502,
+ 504,
"[UpdateOneObjectInput!]!"
]
}
@@ -9441,7 +9512,7 @@ export default {
279,
{
"input": [
- 505,
+ 507,
"CreateOneIndexInput!"
]
}
@@ -9450,7 +9521,7 @@ export default {
279,
{
"input": [
- 508,
+ 510,
"DeleteOneIndexInput!"
]
}
@@ -9471,7 +9542,7 @@ export default {
23,
{
"input": [
- 431,
+ 433,
"LogicFunctionIdInput!"
]
}
@@ -9480,7 +9551,7 @@ export default {
23,
{
"input": [
- 509,
+ 511,
"CreateLogicFunctionFromSourceInput!"
]
}
@@ -9489,7 +9560,7 @@ export default {
154,
{
"input": [
- 510,
+ 512,
"ExecuteOneLogicFunctionInput!"
]
}
@@ -9498,7 +9569,7 @@ export default {
8,
{
"input": [
- 511,
+ 513,
"UpdateLogicFunctionFromSourceInput!"
]
}
@@ -9507,7 +9578,7 @@ export default {
14,
{
"input": [
- 513,
+ 515,
"CreateCommandMenuItemInput!"
]
}
@@ -9516,7 +9587,7 @@ export default {
14,
{
"input": [
- 514,
+ 516,
"UpdateCommandMenuItemInput!"
]
}
@@ -9552,7 +9623,7 @@ export default {
13,
{
"input": [
- 515,
+ 517,
"CreateFrontComponentInput!"
]
}
@@ -9561,7 +9632,7 @@ export default {
13,
{
"input": [
- 516,
+ 518,
"UpdateFrontComponentInput!"
]
}
@@ -9737,7 +9808,7 @@ export default {
201,
{
"input": [
- 518,
+ 520,
"CreateApprovedAccessDomainInput!"
]
}
@@ -9746,7 +9817,7 @@ export default {
8,
{
"input": [
- 519,
+ 521,
"DeleteApprovedAccessDomainInput!"
]
}
@@ -9755,7 +9826,7 @@ export default {
201,
{
"input": [
- 520,
+ 522,
"ValidateApprovedAccessDomainInput!"
]
}
@@ -9777,7 +9848,7 @@ export default {
51,
{
"createRoleInput": [
- 521,
+ 523,
"CreateRoleInput!"
]
}
@@ -9786,7 +9857,7 @@ export default {
51,
{
"updateRoleInput": [
- 522,
+ 524,
"UpdateRoleInput!"
]
}
@@ -9804,7 +9875,7 @@ export default {
48,
{
"upsertObjectPermissionsInput": [
- 524,
+ 526,
"UpsertObjectPermissionsInput!"
]
}
@@ -9813,7 +9884,7 @@ export default {
49,
{
"upsertPermissionFlagsInput": [
- 526,
+ 528,
"UpsertPermissionFlagsInput!"
]
}
@@ -9822,7 +9893,7 @@ export default {
43,
{
"upsertFieldPermissionsInput": [
- 527,
+ 529,
"UpsertFieldPermissionsInput!"
]
}
@@ -9831,7 +9902,7 @@ export default {
292,
{
"input": [
- 529,
+ 531,
"UpsertRowLevelPermissionPredicatesInput!"
]
}
@@ -9862,7 +9933,7 @@ export default {
2,
{
"input": [
- 532,
+ 534,
"CreateApiKeyInput!"
]
}
@@ -9871,7 +9942,7 @@ export default {
2,
{
"input": [
- 533,
+ 535,
"UpdateApiKeyInput!"
]
}
@@ -9880,7 +9951,7 @@ export default {
2,
{
"input": [
- 534,
+ 536,
"RevokeApiKeyInput!"
]
}
@@ -9902,7 +9973,7 @@ export default {
58,
{
"input": [
- 535,
+ 537,
"CreateViewFilterGroupInput!"
]
}
@@ -9915,7 +9986,7 @@ export default {
"String!"
],
"input": [
- 536,
+ 538,
"UpdateViewFilterGroupInput!"
]
}
@@ -9960,7 +10031,7 @@ export default {
72,
{
"data": [
- 537,
+ 539,
"ActivateWorkspaceInput!"
]
}
@@ -9969,7 +10040,7 @@ export default {
72,
{
"data": [
- 538,
+ 540,
"UpdateWorkspaceInput!"
]
}
@@ -9978,7 +10049,7 @@ export default {
72,
{
"data": [
- 539,
+ 541,
"UpdateWorkspaceAllowedIframeOriginsInput!"
]
}
@@ -10009,7 +10080,7 @@ export default {
243,
{
"input": [
- 540,
+ 542,
"CreateApplicationRegistrationInput!"
]
}
@@ -10018,7 +10089,7 @@ export default {
79,
{
"input": [
- 541,
+ 543,
"UpdateApplicationRegistrationInput!"
]
}
@@ -10045,7 +10116,7 @@ export default {
215,
{
"input": [
- 543,
+ 545,
"UpdateApplicationRegistrationVariableInput!"
]
}
@@ -10063,7 +10134,7 @@ export default {
79,
{
"file": [
- 454,
+ 456,
"Upload!"
],
"universalIdentifier": [
@@ -10097,7 +10168,7 @@ export default {
267,
{
"input": [
- 545,
+ 547,
"GrantApplicationCapabilitiesInput!"
]
}
@@ -10130,7 +10201,7 @@ export default {
265,
{
"input": [
- 546,
+ 548,
"TriggerInstallApplicationJobInput!"
]
}
@@ -10139,7 +10210,7 @@ export default {
266,
{
"input": [
- 547,
+ 549,
"TriggerUninstallApplicationJobInput!"
]
}
@@ -10152,7 +10223,7 @@ export default {
"UUID!"
],
"input": [
- 548,
+ 550,
"UpdateApplicationInput!"
]
}
@@ -10182,7 +10253,7 @@ export default {
271,
{
"input": [
- 549,
+ 551,
"CreateOneFieldMetadataInput!"
]
}
@@ -10191,7 +10262,7 @@ export default {
271,
{
"input": [
- 551,
+ 553,
"UpdateOneFieldMetadataInput!"
]
}
@@ -10200,7 +10271,7 @@ export default {
271,
{
"input": [
- 553,
+ 555,
"DeleteOneFieldInput!"
]
}
@@ -10209,7 +10280,7 @@ export default {
62,
{
"input": [
- 554,
+ 556,
"CreateViewGroupInput!"
]
}
@@ -10218,7 +10289,7 @@ export default {
62,
{
"inputs": [
- 554,
+ 556,
"[CreateViewGroupInput!]!"
]
}
@@ -10227,7 +10298,7 @@ export default {
62,
{
"input": [
- 555,
+ 557,
"UpdateViewGroupInput!"
]
}
@@ -10236,7 +10307,7 @@ export default {
62,
{
"inputs": [
- 555,
+ 557,
"[UpdateViewGroupInput!]!"
]
}
@@ -10245,7 +10316,7 @@ export default {
62,
{
"input": [
- 557,
+ 559,
"DeleteViewGroupInput!"
]
}
@@ -10254,7 +10325,7 @@ export default {
62,
{
"input": [
- 558,
+ 560,
"DestroyViewGroupInput!"
]
}
@@ -10263,7 +10334,7 @@ export default {
352,
{
"input": [
- 559,
+ 561,
"SendMessageCampaignInput!"
]
}
@@ -10272,7 +10343,7 @@ export default {
350,
{
"input": [
- 560,
+ 562,
"CancelMessageCampaignInput!"
]
}
@@ -10281,7 +10352,7 @@ export default {
351,
{
"input": [
- 561,
+ 563,
"SendMessageCampaignTestInput!"
]
}
@@ -10299,7 +10370,7 @@ export default {
354,
{
"input": [
- 562,
+ 564,
"CreateMessageSuppressionInput!"
]
}
@@ -10317,7 +10388,7 @@ export default {
358,
{
"input": [
- 563,
+ 565,
"CreateUnsubscribeTopicInput!"
]
}
@@ -10326,7 +10397,7 @@ export default {
358,
{
"input": [
- 564,
+ 566,
"UpdateUnsubscribeTopicInput!"
]
}
@@ -10344,7 +10415,7 @@ export default {
338,
{
"input": [
- 565,
+ 567,
"UpdateMessageChannelInput!"
]
}
@@ -10353,7 +10424,7 @@ export default {
348,
{
"input": [
- 567,
+ 569,
"CreateEmailGroupChannelInput!"
]
}
@@ -10362,7 +10433,7 @@ export default {
338,
{
"input": [
- 568,
+ 570,
"UpdateEmailGroupChannelInput!"
]
}
@@ -10380,7 +10451,7 @@ export default {
338,
{
"input": [
- 569,
+ 571,
"CreateAppMessageChannelInput!"
]
}
@@ -10389,7 +10460,7 @@ export default {
338,
{
"input": [
- 570,
+ 572,
"UpdateAppMessageChannelInput!"
]
}
@@ -10407,7 +10478,7 @@ export default {
347,
{
"input": [
- 571,
+ 573,
"IngestAppMessagesInput!"
]
}
@@ -10416,7 +10487,7 @@ export default {
334,
{
"input": [
- 575,
+ 577,
"CreateEmailingDomainInput!"
]
}
@@ -10443,7 +10514,7 @@ export default {
367,
{
"input": [
- 576,
+ 578,
"CreateWebhookInput!"
]
}
@@ -10452,7 +10523,7 @@ export default {
367,
{
"input": [
- 577,
+ 579,
"UpdateWebhookInput!"
]
}
@@ -10470,43 +10541,43 @@ export default {
371,
{
"input": [
- 579,
+ 581,
"RunAgentInput!"
]
}
],
"updateMessageFolder": [
- 411,
+ 413,
{
"input": [
- 584,
+ 586,
"UpdateMessageFolderInput!"
]
}
],
"updateMessageFolders": [
- 411,
+ 413,
{
"input": [
- 586,
+ 588,
"UpdateMessageFoldersInput!"
]
}
],
"updateCalendarChannel": [
- 406,
+ 408,
{
"input": [
- 587,
+ 589,
"UpdateCalendarChannelInput!"
]
}
],
"setAppKeyValue": [
- 404,
+ 406,
{
"input": [
- 589,
+ 591,
"SetAppKeyValueInput!"
]
}
@@ -10519,24 +10590,24 @@ export default {
"String!"
],
"scope": [
- 405
+ 407
]
}
],
"enqueueJob": [
- 402,
+ 404,
{
"input": [
- 590,
+ 592,
"EnqueueJobInput!"
]
}
],
"enqueueJobs": [
- 403,
+ 405,
{
"input": [
- 591,
+ 593,
"EnqueueJobsInput!"
]
}
@@ -10545,7 +10616,7 @@ export default {
8,
{
"input": [
- 593,
+ 595,
"ReportAppConnectionAuthFailureInput!"
]
}
@@ -10575,7 +10646,7 @@ export default {
1
],
"fileAttachments": [
- 594,
+ 596,
"[FileAttachmentInput!]"
]
}
@@ -10687,7 +10758,7 @@ export default {
392,
{
"input": [
- 595,
+ 597,
"SendInboxMessageInput!"
]
}
@@ -10696,7 +10767,7 @@ export default {
383,
{
"input": [
- 596,
+ 598,
"CreateSkillInput!"
]
}
@@ -10705,7 +10776,7 @@ export default {
383,
{
"input": [
- 597,
+ 599,
"UpdateSkillInput!"
]
}
@@ -10738,25 +10809,25 @@ export default {
}
],
"createValidationRule": [
- 418,
+ 420,
{
"input": [
- 598,
+ 600,
"CreateValidationRuleInput!"
]
}
],
"updateValidationRule": [
- 418,
+ 420,
{
"input": [
- 599,
+ 601,
"UpdateValidationRuleInput!"
]
}
],
"deleteValidationRule": [
- 418,
+ 420,
{
"id": [
3,
@@ -10765,16 +10836,16 @@ export default {
}
],
"updateTimelineActivityType": [
- 417,
+ 419,
{
"input": [
- 601,
+ 603,
"UpdateTimelineActivityTypeInput!"
]
}
],
"resetTimelineActivityType": [
- 417,
+ 419,
{
"id": [
3,
@@ -10786,7 +10857,7 @@ export default {
301,
{
"input": [
- 602,
+ 604,
"GetAuthorizationUrlForSSOInput!"
]
}
@@ -10952,7 +11023,7 @@ export default {
304,
{
"input": [
- 603
+ 605
]
}
],
@@ -10964,7 +11035,7 @@ export default {
"String!"
],
"file": [
- 454,
+ 456,
"Upload!"
]
}
@@ -11160,7 +11231,7 @@ export default {
8,
{
"input": [
- 604,
+ 606,
"UpdateWorkspaceMemberSettingsInput!"
]
}
@@ -11194,7 +11265,7 @@ export default {
252,
{
"input": [
- 605,
+ 607,
"SetupOIDCSsoInput!"
]
}
@@ -11203,7 +11274,7 @@ export default {
252,
{
"input": [
- 606,
+ 608,
"SetupSAMLSsoInput!"
]
}
@@ -11212,7 +11283,7 @@ export default {
248,
{
"input": [
- 607,
+ 609,
"DeleteSsoInput!"
]
}
@@ -11221,7 +11292,7 @@ export default {
249,
{
"input": [
- 608,
+ 610,
"EditSsoInput!"
]
}
@@ -11250,7 +11321,7 @@ export default {
396,
{
"type": [
- 609,
+ 611,
"AnalyticsType!"
],
"name": [
@@ -11293,7 +11364,7 @@ export default {
373,
{
"input": [
- 610,
+ 612,
"CreateCalendarEventInput!"
]
}
@@ -11302,7 +11373,7 @@ export default {
395,
{
"input": [
- 611,
+ 613,
"SendEmailInput!"
]
}
@@ -11324,7 +11395,7 @@ export default {
"String!"
],
"connectionParameters": [
- 613,
+ 615,
"EmailAccountConnectionParameters!"
],
"id": [
@@ -11336,7 +11407,7 @@ export default {
212,
{
"input": [
- 615,
+ 617,
"UpdateLabPublicFeatureFlagInput!"
]
}
@@ -11404,7 +11475,7 @@ export default {
318,
{
"file": [
- 454,
+ 456,
"Upload!"
],
"applicationUniversalIdentifier": [
@@ -11429,7 +11500,7 @@ export default {
"String!"
],
"files": [
- 616,
+ 618,
"[ApplicationFileUploadRequestInput!]!"
]
}
@@ -11554,7 +11625,7 @@ export default {
3
],
"update": [
- 453
+ 455
],
"__typename": [
1
@@ -11627,7 +11698,7 @@ export default {
3
],
"payload": [
- 455
+ 457
],
"__typename": [
1
@@ -11761,7 +11832,7 @@ export default {
8
],
"tabs": [
- 464
+ 466
],
"__typename": [
1
@@ -11784,7 +11855,7 @@ export default {
107
],
"widgets": [
- 465
+ 467
],
"__typename": [
1
@@ -11951,19 +12022,19 @@ export default {
3
],
"view": [
- 469
+ 471
],
"viewFields": [
- 470
+ 472
],
"viewFilters": [
- 471
+ 473
],
"viewFilterGroups": [
- 472
+ 474
],
"viewSorts": [
- 473
+ 475
],
"__typename": [
1
@@ -12112,7 +12183,7 @@ export default {
3
],
"update": [
- 476
+ 478
],
"__typename": [
1
@@ -12182,7 +12253,7 @@ export default {
3
],
"update": [
- 481
+ 483
],
"__typename": [
1
@@ -12235,7 +12306,7 @@ export default {
3
],
"update": [
- 485
+ 487
],
"__typename": [
1
@@ -12311,7 +12382,7 @@ export default {
3
],
"update": [
- 490
+ 492
],
"__typename": [
1
@@ -12375,10 +12446,10 @@ export default {
3
],
"groups": [
- 495
+ 497
],
"fields": [
- 496
+ 498
],
"__typename": [
1
@@ -12398,7 +12469,7 @@ export default {
8
],
"fields": [
- 496
+ 498
],
"__typename": [
1
@@ -12496,7 +12567,7 @@ export default {
},
"CreateOneObjectInput": {
"object": [
- 500
+ 502
],
"__typename": [
1
@@ -12556,7 +12627,7 @@ export default {
},
"UpdateOneObjectInput": {
"update": [
- 503
+ 505
],
"id": [
3
@@ -12615,7 +12686,7 @@ export default {
28
],
"translations": [
- 504
+ 506
],
"__typename": [
1
@@ -12637,7 +12708,7 @@ export default {
},
"CreateOneIndexInput": {
"index": [
- 506
+ 508
],
"__typename": [
1
@@ -12648,7 +12719,7 @@ export default {
3
],
"fields": [
- 507
+ 509
],
"indexType": [
280
@@ -12733,7 +12804,7 @@ export default {
3
],
"update": [
- 512
+ 514
],
"__typename": [
1
@@ -12902,7 +12973,7 @@ export default {
3
],
"update": [
- 517
+ 519
],
"__typename": [
1
@@ -12995,7 +13066,7 @@ export default {
},
"UpdateRoleInput": {
"update": [
- 523
+ 525
],
"id": [
3
@@ -13050,7 +13121,7 @@ export default {
3
],
"objectPermissions": [
- 525
+ 527
],
"__typename": [
1
@@ -13092,7 +13163,7 @@ export default {
3
],
"fieldPermissions": [
- 528
+ 530
],
"__typename": [
1
@@ -13123,10 +13194,10 @@ export default {
3
],
"predicates": [
- 530
+ 532
],
"predicateGroups": [
- 531
+ 533
],
"__typename": [
1
@@ -13393,7 +13464,7 @@ export default {
1
],
"update": [
- 542
+ 544
],
"__typename": [
1
@@ -13418,7 +13489,7 @@ export default {
1
],
"update": [
- 544
+ 546
],
"__typename": [
1
@@ -13475,7 +13546,7 @@ export default {
},
"CreateOneFieldMetadataInput": {
"field": [
- 550
+ 552
],
"__typename": [
1
@@ -13554,7 +13625,7 @@ export default {
3
],
"update": [
- 552
+ 554
],
"__typename": [
1
@@ -13619,7 +13690,7 @@ export default {
9
],
"translations": [
- 504
+ 506
],
"__typename": [
1
@@ -13658,7 +13729,7 @@ export default {
3
],
"update": [
- 556
+ 558
],
"__typename": [
1
@@ -13783,7 +13854,7 @@ export default {
3
],
"update": [
- 566
+ 568
],
"__typename": [
1
@@ -13876,7 +13947,7 @@ export default {
3
],
"messages": [
- 572
+ 574
],
"__typename": [
1
@@ -13899,7 +13970,7 @@ export default {
4
],
"participants": [
- 573
+ 575
],
"__typename": [
1
@@ -13907,7 +13978,7 @@ export default {
},
"AppMessageParticipantInput": {
"role": [
- 574
+ 576
],
"handle": [
1
@@ -13959,7 +14030,7 @@ export default {
3
],
"update": [
- 578
+ 580
],
"__typename": [
1
@@ -13993,16 +14064,16 @@ export default {
3
],
"messages": [
- 580
+ 582
],
"input": [
- 580
+ 582
],
"additionalInstructions": [
1
],
"thread": [
- 583
+ 585
],
"__typename": [
1
@@ -14010,13 +14081,13 @@ export default {
},
"RunAgentMessageInput": {
"role": [
- 581
+ 583
],
"content": [
1
],
"attachments": [
- 582
+ 584
],
"__typename": [
1
@@ -14050,7 +14121,7 @@ export default {
3
],
"update": [
- 585
+ 587
],
"__typename": [
1
@@ -14069,7 +14140,7 @@ export default {
3
],
"update": [
- 585
+ 587
],
"__typename": [
1
@@ -14080,7 +14151,7 @@ export default {
3
],
"update": [
- 588
+ 590
],
"__typename": [
1
@@ -14088,13 +14159,13 @@ export default {
},
"UpdateCalendarChannelInputUpdates": {
"visibility": [
- 409
+ 411
],
"isContactAutoCreationEnabled": [
8
],
"contactAutoCreationPolicy": [
- 410
+ 412
],
"isSyncEnabled": [
8
@@ -14111,7 +14182,7 @@ export default {
9
],
"scope": [
- 405
+ 407
],
"__typename": [
1
@@ -14145,7 +14216,7 @@ export default {
9
],
"jobs": [
- 592
+ 594
],
"retryLimit": [
31
@@ -14296,7 +14367,7 @@ export default {
3
],
"update": [
- 600
+ 602
],
"__typename": [
1
@@ -14342,7 +14413,7 @@ export default {
8
],
"translations": [
- 504
+ 506
],
"__typename": [
1
@@ -14508,7 +14579,7 @@ export default {
1
],
"files": [
- 612
+ 614
],
"__typename": [
1
@@ -14530,13 +14601,13 @@ export default {
1
],
"IMAP": [
- 614
+ 616
],
"SMTP": [
- 614
+ 616
],
"CALDAV": [
- 614
+ 616
],
"__typename": [
1
@@ -14601,7 +14672,7 @@ export default {
293,
{
"input": [
- 618,
+ 620,
"LogicFunctionLogsInput!"
]
}
@@ -14619,11 +14690,11 @@ export default {
397,
{
"table": [
- 439,
+ 441,
"EventLogTable!"
],
"fieldFilters": [
- 442,
+ 444,
"[EventLogFieldFilterInput!]"
]
}
@@ -14632,7 +14703,7 @@ export default {
400,
{
"input": [
- 619,
+ 621,
"CreateRecordExportInput!"
]
}
diff --git a/packages/twenty-docs/developers/extend/apps/logic/skills-and-agents.mdx b/packages/twenty-docs/developers/extend/apps/logic/skills-and-agents.mdx
index ed2f04d8f85..f1cdd367eb9 100644
--- a/packages/twenty-docs/developers/extend/apps/logic/skills-and-agents.mdx
+++ b/packages/twenty-docs/developers/extend/apps/logic/skills-and-agents.mdx
@@ -121,6 +121,9 @@ Key points:
`thread` rather than replaying earlier turns yourself.
- The agent runs **synchronously** and can read/update records itself via its
own tools — `runAgent()` resolves once the run completes.
+- Every call is stored with its input and status, plus its reply and usage
+ when it completes, so it shows up in the agent's runs. Without a `thread`, a call gets a conversation of its
+ own: `threadId` names it, and a later call never sees it.
- An app can only run its own agents.
- The app's [default role](/developers/extend/apps/config/roles) must grant the
`AI` permission flag — add `SystemPermissionFlag.AI` to its
diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts
index 8e7b68cf4c4..84570a0d121 100644
--- a/packages/twenty-front/src/generated-metadata/graphql.ts
+++ b/packages/twenty-front/src/generated-metadata/graphql.ts
@@ -134,6 +134,35 @@ export type AgentMessagePart = {
type: Scalars['String']['output'];
};
+export type AgentRun = {
+ __typename?: 'AgentRun';
+ createdAt: Scalars['DateTime']['output'];
+ creatorName: Scalars['String']['output'];
+ creatorSource: Scalars['String']['output'];
+ credits?: Maybe<Scalars['Float']['output']>;
+ endedAt?: Maybe<Scalars['DateTime']['output']>;
+ errorMessage?: Maybe<Scalars['String']['output']>;
+ id: Scalars['UUID']['output'];
+ input?: Maybe<Scalars['String']['output']>;
+ inputTokens?: Maybe<Scalars['Int']['output']>;
+ modelId?: Maybe<Scalars['String']['output']>;
+ outputTokens?: Maybe<Scalars['Int']['output']>;
+ reply?: Maybe<Scalars['String']['output']>;
+ startedAt?: Maybe<Scalars['DateTime']['output']>;
+ status: AgentTurnStatus;
+ threadId: Scalars['UUID']['output'];
+ threadTitle?: Maybe<Scalars['String']['output']>;
+ toolNames: Array<Scalars['String']['output']>;
+};
+
+export enum AgentTurnStatus {
+ CANCELLED = 'CANCELLED',
+ COMPLETED = 'COMPLETED',
+ FAILED = 'FAILED',
+ RUNNING = 'RUNNING',
+ WAITING_FOR_INPUT = 'WAITING_FOR_INPUT'
+}
+
export type AggregateChartConfiguration = {
__typename?: 'AggregateChartConfiguration';
aggregateFieldMetadataId: Scalars['UUID']['output'];
@@ -5213,6 +5242,7 @@ export type PublicWorkspaceDataSummary = {
export type Query = {
__typename?: 'Query';
+ agentRuns: Array<AgentRun>;
aiChatUsage?: Maybe<AiChatUsage>;
apiKey?: Maybe<ApiKey>;
apiKeys: Array<ApiKey>;
@@ -5350,6 +5380,12 @@ export type Query = {
};
+export type QueryAgentRunsArgs = {
+ agentId: Scalars['UUID']['input'];
+ limit?: Scalars['Int']['input'];
+};
+
+
export type QueryApiKeyArgs = {
input: GetApiKeyInput;
};
@@ -8184,6 +8220,13 @@ export type FindWorkspaceAiStatsQueryVariables = Exact<{ [key: string]: never; }
export type FindWorkspaceAiStatsQuery = { __typename?: 'Query', findWorkspaceAiStats: { __typename?: 'WorkspaceAiStats', conversationsCount: number, skillsCount: number, toolsCount: number } };
+export type GetAgentRunsQueryVariables = Exact<{
+ agentId: Scalars['UUID']['input'];
+}>;
+
+
+export type GetAgentRunsQuery = { __typename?: 'Query', agentRuns: Array<{ __typename?: 'AgentRun', id: string, threadId: string, threadTitle?: string | null, status: AgentTurnStatus, errorMessage?: string | null, createdAt: string, startedAt?: string | null, endedAt?: string | null, modelId?: string | null, inputTokens?: number | null, outputTokens?: number | null, credits?: number | null, creatorSource: string, creatorName: string, input?: string | null, reply?: string | null, toolNames: Array<string> }> };
+
export type GetAiChatUsageQueryVariables = Exact<{ [key: string]: never; }>;
@@ -10690,6 +10733,7 @@ export const FindManySkillsForSuggestionDocument = {"kind":"Document","definitio
export const FindOneAgentDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"FindOneAgent"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"findOneAgent"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"AgentFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AgentFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Agent"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"prompt"}},{"kind":"Field","name":{"kind":"Name","value":"modelId"}},{"kind":"Field","name":{"kind":"Name","value":"responseFormat"}},{"kind":"Field","name":{"kind":"Name","value":"roleId"}},{"kind":"Field","name":{"kind":"Name","value":"isCustom"}},{"kind":"Field","name":{"kind":"Name","value":"isSystem"}},{"kind":"Field","name":{"kind":"Name","value":"modelConfiguration"}},{"kind":"Field","name":{"kind":"Name","value":"triggers"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<FindOneAgentQuery, FindOneAgentQueryVariables>;
export const FindOneSkillDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"FindOneSkill"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"skill"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SkillFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SkillFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Skill"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"content"}},{"kind":"Field","name":{"kind":"Name","value":"isCustom"}},{"kind":"Field","name":{"kind":"Name","value":"isSystem"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<FindOneSkillQuery, FindOneSkillQueryVariables>;
export const FindWorkspaceAiStatsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"FindWorkspaceAiStats"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"findWorkspaceAiStats"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"conversationsCount"}},{"kind":"Field","name":{"kind":"Name","value":"skillsCount"}},{"kind":"Field","name":{"kind":"Name","value":"toolsCount"}}]}}]}}]} as unknown as DocumentNode<FindWorkspaceAiStatsQuery, FindWorkspaceAiStatsQueryVariables>;
+export const GetAgentRunsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAgentRuns"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"agentId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"agentRuns"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"agentId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"agentId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"threadTitle"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"errorMessage"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"startedAt"}},{"kind":"Field","name":{"kind":"Name","value":"endedAt"}},{"kind":"Field","name":{"kind":"Name","value":"modelId"}},{"kind":"Field","name":{"kind":"Name","value":"inputTokens"}},{"kind":"Field","name":{"kind":"Name","value":"outputTokens"}},{"kind":"Field","name":{"kind":"Name","value":"credits"}},{"kind":"Field","name":{"kind":"Name","value":"creatorSource"}},{"kind":"Field","name":{"kind":"Name","value":"creatorName"}},{"kind":"Field","name":{"kind":"Name","value":"input"}},{"kind":"Field","name":{"kind":"Name","value":"reply"}},{"kind":"Field","name":{"kind":"Name","value":"toolNames"}}]}}]}}]} as unknown as DocumentNode<GetAgentRunsQuery, GetAgentRunsQueryVariables>;
export const GetAiChatUsageDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAiChatUsage"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"aiChatUsage"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"limitValue"}},{"kind":"Field","name":{"kind":"Name","value":"consumedValue"}},{"kind":"Field","name":{"kind":"Name","value":"periodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"kind"}}]}}]}}]} as unknown as DocumentNode<GetAiChatUsageQuery, GetAiChatUsageQueryVariables>;
export const GetChatMessagesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetChatMessages"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chatMessages"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"turnId"}},{"kind":"Field","name":{"kind":"Name","value":"senderUserWorkspaceId"}},{"kind":"Field","name":{"kind":"Name","value":"role"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"parts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"messageId"}},{"kind":"Field","name":{"kind":"Name","value":"orderIndex"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"textContent"}},{"kind":"Field","name":{"kind":"Name","value":"reasoningContent"}},{"kind":"Field","name":{"kind":"Name","value":"toolName"}},{"kind":"Field","name":{"kind":"Name","value":"toolCallId"}},{"kind":"Field","name":{"kind":"Name","value":"toolInput"}},{"kind":"Field","name":{"kind":"Name","value":"toolOutput"}},{"kind":"Field","name":{"kind":"Name","value":"state"}},{"kind":"Field","name":{"kind":"Name","value":"providerExecuted"}},{"kind":"Field","name":{"kind":"Name","value":"errorMessage"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlSourceId"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlUrl"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlTitle"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentSourceId"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentMediaType"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentTitle"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentFilename"}},{"kind":"Field","name":{"kind":"Name","value":"fileMediaType"}},{"kind":"Field","name":{"kind":"Name","value":"fileFilename"}},{"kind":"Field","name":{"kind":"Name","value":"fileUrl"}},{"kind":"Field","name":{"kind":"Name","value":"fileId"}},{"kind":"Field","name":{"kind":"Name","value":"providerMetadata"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"chatStreamCatchupChunks"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chunks"}},{"kind":"Field","name":{"kind":"Name","value":"maxSeq"}},{"kind":"Field","name":{"kind":"Name","value":"error"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"code"}},{"kind":"Field","name":{"kind":"Name","value":"message"}}]}}]}}]}}]} as unknown as DocumentNode<GetChatMessagesQuery, GetChatMessagesQueryVariables>;
export const GetToolIndexDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetToolIndex"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"getToolIndex"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"category"}},{"kind":"Field","name":{"kind":"Name","value":"objectName"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"widgetName"}},{"kind":"Field","name":{"kind":"Name","value":"frontComponentId"}}]}}]}}]} as unknown as DocumentNode<GetToolIndexQuery, GetToolIndexQueryVariables>;
diff --git a/packages/twenty-front/src/modules/ai/graphql/queries/getAgentRuns.ts b/packages/twenty-front/src/modules/ai/graphql/queries/getAgentRuns.ts
new file mode 100644
index 00000000000..8dede041157
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/graphql/queries/getAgentRuns.ts
@@ -0,0 +1,25 @@
+import { gql } from '@apollo/client';
+
+export const GET_AGENT_RUNS = gql`
+ query GetAgentRuns($agentId: UUID!) {
+ agentRuns(agentId: $agentId) {
+ id
+ threadId
+ threadTitle
+ status
+ errorMessage
+ createdAt
+ startedAt
+ endedAt
+ modelId
+ inputTokens
+ outputTokens
+ credits
+ creatorSource
+ creatorName
+ input
+ reply
+ toolNames
+ }
+ }
+`;
diff --git a/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentFormContent.tsx b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentFormContent.tsx
index 97cf3f3b159..dd04b7988ed 100644
--- a/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentFormContent.tsx
+++ b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentFormContent.tsx
@@ -3,7 +3,13 @@ import { t } from '@lingui/core/macro';
import { useState } from 'react';
import { isDefined } from 'twenty-shared/utils';
import { Section } from 'twenty-ui/components';
-import { IconBolt, IconLock, IconSettings, useIcons } from 'twenty-ui/icon';
+import {
+ IconBolt,
+ IconLock,
+ IconSettings,
+ IconTerminal,
+ useIcons,
+} from 'twenty-ui/icon';
import { useTheme, themeCssVariables } from 'twenty-ui/theme';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
@@ -20,6 +26,7 @@ import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAto
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { type FindOneAgentQuery } from '~/generated-metadata/graphql';
import { CoreAgentRoleTab } from '@/object-core/agents/components/CoreAgentRoleTab';
+import { CoreAgentRunsTab } from '@/object-core/agents/components/CoreAgentRunsTab';
import { CoreAgentSettingsTab } from '@/object-core/agents/components/CoreAgentSettingsTab';
import { CoreAgentTriggersTab } from '@/object-core/agents/components/CoreAgentTriggersTab';
import { CORE_AGENT_DETAIL_TABS } from '@/object-core/agents/constants/CoreAgentDetailTabs';
@@ -113,6 +120,11 @@ export const CoreAgentFormContent = ({ agent }: CoreAgentFormContentProps) => {
title: t`Triggers`,
Icon: IconBolt,
},
+ {
+ id: CORE_AGENT_DETAIL_TABS.TABS_IDS.RUNS,
+ title: t`Runs`,
+ Icon: IconTerminal,
+ },
];
const title = agent.label;
@@ -123,6 +135,7 @@ export const CoreAgentFormContent = ({ agent }: CoreAgentFormContentProps) => {
activeTabId === CORE_AGENT_DETAIL_TABS.TABS_IDS.SETTINGS;
const isTriggersTab =
activeTabId === CORE_AGENT_DETAIL_TABS.TABS_IDS.TRIGGERS;
+ const isRunsTab = activeTabId === CORE_AGENT_DETAIL_TABS.TABS_IDS.RUNS;
const isFormDisabled = isReadonlyMode || !agent.isCustom;
@@ -172,6 +185,7 @@ export const CoreAgentFormContent = ({ agent }: CoreAgentFormContentProps) => {
disabled={isFormDisabled}
/>
)}
+ {isRunsTab && <CoreAgentRunsTab agentId={agentId} />}
</StyledContentContainer>
</Section.Root>
</SettingsPageContainer>
diff --git a/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunConversation.tsx b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunConversation.tsx
new file mode 100644
index 00000000000..411535e87a8
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunConversation.tsx
@@ -0,0 +1,97 @@
+import { plural } from '@lingui/core/macro';
+import { isDefined } from 'twenty-shared/utils';
+import { IconChevronDown, IconChevronRight } from 'twenty-ui/icon';
+import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';
+import { themeCssVariables, useTheme } from 'twenty-ui/theme';
+
+import { CoreAgentRunRow } from '@/object-core/agents/components/CoreAgentRunRow';
+import { CoreAgentRunStatus } from '@/object-core/agents/components/CoreAgentRunStatus';
+import { CORE_AGENT_RUNS_GRID_TEMPLATE_COLUMNS } from '@/object-core/agents/constants/CoreAgentRunsGridTemplateColumns';
+import { type CoreAgentRun } from '@/object-core/agents/types/CoreAgentRun';
+import { handleCoreAgentRunToggleKeyDown } from '@/object-core/agents/utils/handleCoreAgentRunToggleKeyDown';
+import { TableCell } from '@/ui/layout/table/components/TableCell';
+import { TableRow } from '@/ui/layout/table/components/TableRow';
+import { beautifyPastDateRelativeToNow } from '~/utils/date-utils';
+import { formatNumber } from '~/utils/format/formatNumber';
+
+type CoreAgentRunConversationProps = {
+ title: string | null;
+ runs: CoreAgentRun[];
+ isExpanded: boolean;
+ onToggle: () => void;
+ expandedRunIds: Set<string>;
+ onToggleRun: (runId: string) => void;
+};
+
+export const CoreAgentRunConversation = ({
+ title,
+ runs,
+ isExpanded,
+ onToggle,
+ expandedRunIds,
+ onToggleRun,
+}: CoreAgentRunConversationProps) => {
+ const theme = useTheme();
+ const [latestRun] = runs;
+ const ChevronIcon = isExpanded ? IconChevronDown : IconChevronRight;
+ // a total missing some runs' usage would read as the whole conversation's cost
+ const hasCreditsForEveryRun = runs.every((run) => isDefined(run.credits));
+ const totalCredits = runs.reduce(
+ (credits, run) => credits + (run.credits ?? 0),
+ 0,
+ );
+ const runCount = runs.length;
+
+ return (
+ <>
+ <TableRow
+ gridTemplateColumns={CORE_AGENT_RUNS_GRID_TEMPLATE_COLUMNS}
+ isExpanded={isExpanded}
+ onClick={onToggle}
+ onKeyDown={handleCoreAgentRunToggleKeyDown(onToggle)}
+ role="button"
+ tabIndex={0}
+ ariaExpanded={isExpanded}
+ >
+ <TableCell gap={themeCssVariables.spacing[1]}>
+ <ChevronIcon
+ size={theme.icon.size.sm}
+ stroke={theme.icon.stroke.sm}
+ />
+ <CoreAgentRunStatus status={latestRun.status} />
+ </TableCell>
+ <TableCell color={themeCssVariables.font.color.tertiary}>
+ {beautifyPastDateRelativeToNow(
+ latestRun.startedAt ?? latestRun.createdAt,
+ )}
+ </TableCell>
+ <TableCell color={themeCssVariables.font.color.secondary}>
+ {plural(runCount, { one: '# run', other: '# runs' })}
+ </TableCell>
+ <TableCell overflow="hidden">
+ <OverflowingTextWithTooltip
+ text={<>{title ?? latestRun.input}</>}
+ tooltipContent={title ?? latestRun.input ?? ''}
+ />
+ </TableCell>
+ <TableCell />
+ <TableCell align="right" color={themeCssVariables.font.color.secondary}>
+ {hasCreditsForEveryRun
+ ? formatNumber(totalCredits, { decimals: 2 })
+ : '-'}
+ </TableCell>
+ <TableCell />
+ </TableRow>
+ {isExpanded &&
+ runs.map((run) => (
+ <CoreAgentRunRow
+ key={run.id}
+ run={run}
+ isNested
+ isExpanded={expandedRunIds.has(run.id)}
+ onToggle={() => onToggleRun(run.id)}
+ />
+ ))}
+ </>
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunDetails.tsx b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunDetails.tsx
new file mode 100644
index 00000000000..79f6b0d9e9d
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunDetails.tsx
@@ -0,0 +1,81 @@
+import { styled } from '@linaria/react';
+import { t } from '@lingui/core/macro';
+import { isNonEmptyString } from '@sniptt/guards';
+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';
+import { Tag } from 'twenty-ui/primitives/data-display';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+import { CoreAgentModelCell } from '@/object-core/agents/components/CoreAgentModelCell';
+import { type CoreAgentRun } from '@/object-core/agents/types/CoreAgentRun';
+
+const StyledDetails = styled.div`
+ border-bottom: 1px solid ${themeCssVariables.border.color.light};
+ display: grid;
+ gap: ${themeCssVariables.spacing[2]} ${themeCssVariables.spacing[4]};
+ grid-template-columns: 120px minmax(0, 1fr);
+ padding: ${themeCssVariables.spacing[3]} ${themeCssVariables.spacing[2]};
+`;
+
+const StyledLabel = styled.div`
+ color: ${themeCssVariables.font.color.tertiary};
+`;
+
+const StyledText = styled.div`
+ color: ${themeCssVariables.font.color.primary};
+ min-width: 0;
+ overflow-wrap: anywhere;
+ white-space: pre-wrap;
+`;
+
+const StyledError = styled(StyledText)`
+ color: ${themeCssVariables.color.red};
+`;
+
+const StyledTags = styled.div`
+ display: flex;
+ flex-wrap: wrap;
+ gap: ${themeCssVariables.spacing[1]};
+`;
+
+type CoreAgentRunDetailsProps = {
+ run: CoreAgentRun;
+};
+
+export const CoreAgentRunDetails = ({ run }: CoreAgentRunDetailsProps) => (
+ <StyledDetails>
+ {isNonEmptyString(run.errorMessage) && (
+ <>
+ <StyledLabel>{t`Error`}</StyledLabel>
+ <StyledError>{run.errorMessage}</StyledError>
+ </>
+ )}
+ <StyledLabel>{t`Input`}</StyledLabel>
+ <StyledText>{run.input ?? t`No input`}</StyledText>
+ <StyledLabel>{t`Reply`}</StyledLabel>
+ <StyledText>{run.reply ?? t`No reply`}</StyledText>
+ {isNonEmptyArray(run.toolNames) && (
+ <>
+ <StyledLabel>{t`Tools`}</StyledLabel>
+ <StyledTags>
+ {run.toolNames.map((toolName) => (
+ <Tag key={toolName} color="gray">
+ {toolName}
+ </Tag>
+ ))}
+ </StyledTags>
+ </>
+ )}
+ {isDefined(run.modelId) && (
+ <>
+ <StyledLabel>{t`Model`}</StyledLabel>
+ <CoreAgentModelCell modelId={run.modelId} />
+ </>
+ )}
+ {isNonEmptyString(run.threadTitle) && (
+ <>
+ <StyledLabel>{t`Conversation`}</StyledLabel>
+ <StyledText>{run.threadTitle}</StyledText>
+ </>
+ )}
+ </StyledDetails>
+);
diff --git a/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunRow.tsx b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunRow.tsx
new file mode 100644
index 00000000000..c0685639fc3
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunRow.tsx
@@ -0,0 +1,93 @@
+import { t } from '@lingui/core/macro';
+import { isDefined } from 'twenty-shared/utils';
+import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+import { CoreAgentRunDetails } from '@/object-core/agents/components/CoreAgentRunDetails';
+import { CoreAgentRunSource } from '@/object-core/agents/components/CoreAgentRunSource';
+import { CoreAgentRunStatus } from '@/object-core/agents/components/CoreAgentRunStatus';
+import { CORE_AGENT_RUNS_GRID_TEMPLATE_COLUMNS } from '@/object-core/agents/constants/CoreAgentRunsGridTemplateColumns';
+import { type CoreAgentRun } from '@/object-core/agents/types/CoreAgentRun';
+import { handleCoreAgentRunToggleKeyDown } from '@/object-core/agents/utils/handleCoreAgentRunToggleKeyDown';
+import { TableCell } from '@/ui/layout/table/components/TableCell';
+import { TableRow } from '@/ui/layout/table/components/TableRow';
+import { formatDuration } from '@/workflow/workflow-steps/workflow-actions/utils/formatDuration';
+import { beautifyPastDateRelativeToNow } from '~/utils/date-utils';
+import { formatNumber } from '~/utils/format/formatNumber';
+
+type CoreAgentRunRowProps = {
+ run: CoreAgentRun;
+ isExpanded: boolean;
+ onToggle: () => void;
+ isNested?: boolean;
+};
+
+const getRunTokens = (run: CoreAgentRun): number | null =>
+ isDefined(run.inputTokens) || isDefined(run.outputTokens)
+ ? (run.inputTokens ?? 0) + (run.outputTokens ?? 0)
+ : null;
+
+const getRunDurationMs = (run: CoreAgentRun): number | null =>
+ isDefined(run.startedAt) && isDefined(run.endedAt)
+ ? new Date(run.endedAt).getTime() - new Date(run.startedAt).getTime()
+ : null;
+
+export const CoreAgentRunRow = ({
+ run,
+ isExpanded,
+ onToggle,
+ isNested = false,
+}: CoreAgentRunRowProps) => {
+ const tokens = getRunTokens(run);
+ const durationMs = getRunDurationMs(run);
+
+ return (
+ <>
+ <TableRow
+ gridTemplateColumns={CORE_AGENT_RUNS_GRID_TEMPLATE_COLUMNS}
+ isExpanded={isExpanded}
+ onClick={onToggle}
+ onKeyDown={handleCoreAgentRunToggleKeyDown(onToggle)}
+ role="button"
+ tabIndex={0}
+ ariaExpanded={isExpanded}
+ >
+ <TableCell
+ padding={
+ isNested ? `0 0 0 ${themeCssVariables.spacing[4]}` : undefined
+ }
+ >
+ <CoreAgentRunStatus status={run.status} />
+ </TableCell>
+ <TableCell color={themeCssVariables.font.color.tertiary}>
+ {beautifyPastDateRelativeToNow(run.startedAt ?? run.createdAt)}
+ </TableCell>
+ <TableCell overflow="hidden">
+ <CoreAgentRunSource
+ creatorSource={run.creatorSource}
+ creatorName={run.creatorName}
+ />
+ </TableCell>
+ <TableCell overflow="hidden">
+ {/* plain text: links would sit inside the row's button */}
+ <OverflowingTextWithTooltip
+ text={<>{run.input ?? t`No input`}</>}
+ tooltipContent={run.input ?? t`No input`}
+ />
+ </TableCell>
+ <TableCell align="right" color={themeCssVariables.font.color.secondary}>
+ {isDefined(tokens) ? formatNumber(tokens, { abbreviate: true }) : '-'}
+ </TableCell>
+ <TableCell align="right" color={themeCssVariables.font.color.secondary}>
+ {isDefined(run.credits)
+ ? formatNumber(run.credits, { decimals: 2 })
+ : '-'}
+ </TableCell>
+ <TableCell align="right" color={themeCssVariables.font.color.secondary}>
+ {isDefined(durationMs) ? formatDuration(durationMs) : '-'}
+ </TableCell>
+ </TableRow>
+ {isExpanded && <CoreAgentRunDetails run={run} />}
+ </>
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunSource.tsx b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunSource.tsx
new file mode 100644
index 00000000000..91e1e327188
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunSource.tsx
@@ -0,0 +1,56 @@
+import { styled } from '@linaria/react';
+import { t } from '@lingui/core/macro';
+import { FieldActorSource } from 'twenty-shared/types';
+import { isDefined } from 'twenty-shared/utils';
+import {
+ IconApi,
+ IconApps,
+ IconBolt,
+ IconSettingsAutomation,
+ IconUsers,
+} from 'twenty-ui/icon';
+import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';
+import { themeCssVariables, useTheme } from 'twenty-ui/theme';
+
+const StyledContainer = styled.div`
+ align-items: center;
+ color: ${themeCssVariables.font.color.secondary};
+ display: flex;
+ gap: ${themeCssVariables.spacing[1]};
+ min-width: 0;
+`;
+
+const SOURCE_ICONS: Partial<Record<string, typeof IconApps>> = {
+ [FieldActorSource.WORKFLOW]: IconSettingsAutomation,
+ [FieldActorSource.APPLICATION]: IconApps,
+ [FieldActorSource.API]: IconApi,
+ [FieldActorSource.MANUAL]: IconUsers,
+ [FieldActorSource.AGENT]: IconBolt,
+};
+
+type CoreAgentRunSourceProps = {
+ creatorSource: string;
+ creatorName: string;
+};
+
+export const CoreAgentRunSource = ({
+ creatorSource,
+ creatorName,
+}: CoreAgentRunSourceProps) => {
+ const theme = useTheme();
+ const SourceIcon = SOURCE_ICONS[creatorSource];
+
+ return (
+ <StyledContainer>
+ {isDefined(SourceIcon) ? (
+ <SourceIcon size={theme.icon.size.sm} stroke={theme.icon.stroke.sm} />
+ ) : null}
+ <OverflowingTextWithTooltip
+ text={
+ // trigger runs are recorded as the agent itself, which this page already names
+ creatorSource === FieldActorSource.AGENT ? t`Trigger` : creatorName
+ }
+ />
+ </StyledContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunStatus.tsx b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunStatus.tsx
new file mode 100644
index 00000000000..0cf754541b6
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunStatus.tsx
@@ -0,0 +1,30 @@
+import { t } from '@lingui/core/macro';
+import { assertUnreachable } from 'twenty-shared/utils';
+import { Status } from 'twenty-ui/primitives/data-display';
+
+import { AgentTurnStatus } from '~/generated-metadata/graphql';
+
+type CoreAgentRunStatusProps = {
+ status: AgentTurnStatus;
+};
+
+export const CoreAgentRunStatus = ({ status }: CoreAgentRunStatusProps) => {
+ switch (status) {
+ case AgentTurnStatus.RUNNING:
+ return (
+ <Status color="blue" loading>
+ {t`Running`}
+ </Status>
+ );
+ case AgentTurnStatus.WAITING_FOR_INPUT:
+ return <Status color="orange">{t`Waiting`}</Status>;
+ case AgentTurnStatus.COMPLETED:
+ return <Status color="green">{t`Done`}</Status>;
+ case AgentTurnStatus.CANCELLED:
+ return <Status color="gray">{t`Cancelled`}</Status>;
+ case AgentTurnStatus.FAILED:
+ return <Status color="red">{t`Failed`}</Status>;
+ default:
+ return assertUnreachable(status);
+ }
+};
diff --git a/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunsTab.tsx b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunsTab.tsx
new file mode 100644
index 00000000000..90f34d5c406
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-core/agents/components/CoreAgentRunsTab.tsx
@@ -0,0 +1,150 @@
+import { useQuery } from '@apollo/client/react';
+import { styled } from '@linaria/react';
+import { t } from '@lingui/core/macro';
+import { useState } from 'react';
+import Skeleton from 'react-loading-skeleton';
+import { isDefined } from 'twenty-shared/utils';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+import { CoreAgentRunConversation } from '@/object-core/agents/components/CoreAgentRunConversation';
+import { CoreAgentRunRow } from '@/object-core/agents/components/CoreAgentRunRow';
+import { CORE_AGENT_RUNS_GRID_TEMPLATE_COLUMNS } from '@/object-core/agents/constants/CoreAgentRunsGridTemplateColumns';
+import { groupCoreAgentRunsByConversation } from '@/object-core/agents/utils/groupCoreAgentRunsByConversation';
+import { AnimatedPlaceholder } from '@/ui/feedback/empty-state/components/AnimatedPlaceholder/AnimatedPlaceholder';
+import { EmptyState } from '@/ui/feedback/empty-state/components/EmptyState';
+import { Table } from '@/ui/layout/table/components/Table';
+import { TableHeader } from '@/ui/layout/table/components/TableHeader';
+import { TableRow } from '@/ui/layout/table/components/TableRow';
+import { GetAgentRunsDocument } from '~/generated-metadata/graphql';
+
+const RUNS_POLL_INTERVAL_MS = 10000;
+
+const StyledTableContainer = styled.div`
+ margin-top: ${themeCssVariables.spacing[3]};
+`;
+
+const StyledTableHeaderRowContainer = styled.div`
+ margin-bottom: ${themeCssVariables.spacing[2]};
+`;
+
+const toggleId = (ids: Set<string>, id: string): Set<string> => {
+ const nextIds = new Set(ids);
+
+ if (nextIds.has(id)) {
+ nextIds.delete(id);
+ } else {
+ nextIds.add(id);
+ }
+
+ return nextIds;
+};
+
+type CoreAgentRunsTabProps = {
+ agentId: string;
+};
+
+export const CoreAgentRunsTab = ({ agentId }: CoreAgentRunsTabProps) => {
+ const [expandedRunIds, setExpandedRunIds] = useState<Set<string>>(new Set());
+ const [expandedThreadIds, setExpandedThreadIds] = useState<Set<string>>(
+ new Set(),
+ );
+
+ // runs start and settle outside this page, so the list refreshes while it is visible
+ const { data, loading, error } = useQuery(GetAgentRunsDocument, {
+ variables: { agentId },
+ pollInterval: RUNS_POLL_INTERVAL_MS,
+ skipPollAttempt: () => document.hidden,
+ });
+
+ const runs = data?.agentRuns ?? [];
+
+ const header = (
+ <StyledTableHeaderRowContainer>
+ <TableRow gridTemplateColumns={CORE_AGENT_RUNS_GRID_TEMPLATE_COLUMNS}>
+ <TableHeader>{t`Status`}</TableHeader>
+ <TableHeader>{t`Started`}</TableHeader>
+ <TableHeader>{t`Source`}</TableHeader>
+ <TableHeader>{t`Input`}</TableHeader>
+ <TableHeader align="right">{t`Tokens`}</TableHeader>
+ <TableHeader align="right">{t`Credits`}</TableHeader>
+ <TableHeader align="right">{t`Duration`}</TableHeader>
+ </TableRow>
+ </StyledTableHeaderRowContainer>
+ );
+
+ if (loading && runs.length === 0) {
+ return (
+ <StyledTableContainer>
+ <Table>
+ {header}
+ {Array.from({ length: 3 }).map((_, index) => (
+ <Skeleton height={32} borderRadius={4} key={index} />
+ ))}
+ </Table>
+ </StyledTableContainer>
+ );
+ }
+
+ if (isDefined(error) && runs.length === 0) {
+ return (
+ <EmptyState.Root>
+ <AnimatedPlaceholder type="errorIndex" />
+ <EmptyState.Content>
+ <EmptyState.Title>{t`Could not load runs`}</EmptyState.Title>
+ <EmptyState.Description>
+ {t`Try again in a moment`}
+ </EmptyState.Description>
+ </EmptyState.Content>
+ </EmptyState.Root>
+ );
+ }
+
+ if (runs.length === 0) {
+ return (
+ <EmptyState.Root>
+ <AnimatedPlaceholder type="emptyTimeline" />
+ <EmptyState.Content>
+ <EmptyState.Title>{t`No runs yet`}</EmptyState.Title>
+ <EmptyState.Description>
+ {t`Runs appear here once a workflow or an app uses this agent`}
+ </EmptyState.Description>
+ </EmptyState.Content>
+ </EmptyState.Root>
+ );
+ }
+
+ const handleToggleRun = (runId: string) =>
+ setExpandedRunIds((runIds) => toggleId(runIds, runId));
+
+ return (
+ <StyledTableContainer>
+ <Table>
+ {header}
+ {groupCoreAgentRunsByConversation(runs).map((item) =>
+ item.type === 'conversation' ? (
+ <CoreAgentRunConversation
+ key={item.threadId}
+ title={item.title}
+ runs={item.runs}
+ isExpanded={expandedThreadIds.has(item.threadId)}
+ onToggle={() =>
+ setExpandedThreadIds((threadIds) =>
+ toggleId(threadIds, item.threadId),
+ )
+ }
+ expandedRunIds={expandedRunIds}
+ onToggleRun={handleToggleRun}
+ />
+ ) : (
+ <CoreAgentRunRow
+ key={item.run.id}
+ run={item.run}
+ isExpanded={expandedRunIds.has(item.run.id)}
+ onToggle={() => handleToggleRun(item.run.id)}
+ />
+ ),
+ )}
+ </Table>
+ </StyledTableContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-core/agents/constants/CoreAgentDetailTabs.ts b/packages/twenty-front/src/modules/object-core/agents/constants/CoreAgentDetailTabs.ts
index b172f8cefa3..cc0f2937e83 100644
--- a/packages/twenty-front/src/modules/object-core/agents/constants/CoreAgentDetailTabs.ts
+++ b/packages/twenty-front/src/modules/object-core/agents/constants/CoreAgentDetailTabs.ts
@@ -4,5 +4,6 @@ export const CORE_AGENT_DETAIL_TABS = {
ROLE: 'role',
SETTINGS: 'settings',
TRIGGERS: 'triggers',
+ RUNS: 'runs',
},
};
diff --git a/packages/twenty-front/src/modules/object-core/agents/constants/CoreAgentRunsGridTemplateColumns.ts b/packages/twenty-front/src/modules/object-core/agents/constants/CoreAgentRunsGridTemplateColumns.ts
new file mode 100644
index 00000000000..6cf8cb2b2c4
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-core/agents/constants/CoreAgentRunsGridTemplateColumns.ts
@@ -0,0 +1,2 @@
+export const CORE_AGENT_RUNS_GRID_TEMPLATE_COLUMNS =
+ '110px 100px 160px minmax(0, 1fr) 80px 80px 80px';
diff --git a/packages/twenty-front/src/modules/object-core/agents/types/CoreAgentRun.ts b/packages/twenty-front/src/modules/object-core/agents/types/CoreAgentRun.ts
new file mode 100644
index 00000000000..d47e92ec961
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-core/agents/types/CoreAgentRun.ts
@@ -0,0 +1,3 @@
+import { type GetAgentRunsQuery } from '~/generated-metadata/graphql';
+
+export type CoreAgentRun = GetAgentRunsQuery['agentRuns'][number];
diff --git a/packages/twenty-front/src/modules/object-core/agents/types/CoreAgentRunListItem.ts b/packages/twenty-front/src/modules/object-core/agents/types/CoreAgentRunListItem.ts
new file mode 100644
index 00000000000..1efbfb0891f
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-core/agents/types/CoreAgentRunListItem.ts
@@ -0,0 +1,12 @@
+import { type CoreAgentRun } from '@/object-core/agents/types/CoreAgentRun';
+
+export type CoreAgentRunListItem<
+ TRun extends Pick<CoreAgentRun, 'threadId' | 'threadTitle'> = CoreAgentRun,
+> =
+ | { type: 'run'; run: TRun }
+ | {
+ type: 'conversation';
+ threadId: string;
+ title: string | null;
+ runs: TRun[];
+ };
diff --git a/packages/twenty-front/src/modules/object-core/agents/utils/__tests__/groupCoreAgentRunsByConversation.test.ts b/packages/twenty-front/src/modules/object-core/agents/utils/__tests__/groupCoreAgentRunsByConversation.test.ts
new file mode 100644
index 00000000000..ded3a2e5c43
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-core/agents/utils/__tests__/groupCoreAgentRunsByConversation.test.ts
@@ -0,0 +1,33 @@
+import { groupCoreAgentRunsByConversation } from '@/object-core/agents/utils/groupCoreAgentRunsByConversation';
+
+const buildRun = (id: string, threadId: string) => ({
+ id,
+ threadId,
+ threadTitle: `Conversation ${threadId}`,
+});
+
+describe('groupCoreAgentRunsByConversation', () => {
+ it('keeps a conversation with a single run as a plain row', () => {
+ expect(
+ groupCoreAgentRunsByConversation([buildRun('run-1', 'thread-1')]),
+ ).toEqual([{ type: 'run', run: buildRun('run-1', 'thread-1') }]);
+ });
+
+ it('folds runs of one conversation under it, at the position of its latest run', () => {
+ const runs = [
+ buildRun('run-3', 'thread-a'),
+ buildRun('run-2', 'thread-b'),
+ buildRun('run-1', 'thread-a'),
+ ];
+
+ expect(groupCoreAgentRunsByConversation(runs)).toEqual([
+ {
+ type: 'conversation',
+ threadId: 'thread-a',
+ title: 'Conversation thread-a',
+ runs: [runs[0], runs[2]],
+ },
+ { type: 'run', run: runs[1] },
+ ]);
+ });
+});
diff --git a/packages/twenty-front/src/modules/object-core/agents/utils/groupCoreAgentRunsByConversation.ts b/packages/twenty-front/src/modules/object-core/agents/utils/groupCoreAgentRunsByConversation.ts
new file mode 100644
index 00000000000..5486fe53815
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-core/agents/utils/groupCoreAgentRunsByConversation.ts
@@ -0,0 +1,42 @@
+import { type CoreAgentRun } from '@/object-core/agents/types/CoreAgentRun';
+import { type CoreAgentRunListItem } from '@/object-core/agents/types/CoreAgentRunListItem';
+
+// Runs sharing a conversation fold under it, placed at its latest run; a
+// conversation with a single run stays a plain row
+export const groupCoreAgentRunsByConversation = <
+ TRun extends Pick<CoreAgentRun, 'threadId' | 'threadTitle'>,
+>(
+ runs: TRun[],
+): CoreAgentRunListItem<TRun>[] => {
+ const runsByThreadId = new Map<string, TRun[]>();
+
+ for (const run of runs) {
+ runsByThreadId.set(run.threadId, [
+ ...(runsByThreadId.get(run.threadId) ?? []),
+ run,
+ ]);
+ }
+
+ const listedThreadIds = new Set<string>();
+
+ return runs.flatMap((run): CoreAgentRunListItem<TRun>[] => {
+ if (listedThreadIds.has(run.threadId)) {
+ return [];
+ }
+
+ listedThreadIds.add(run.threadId);
+
+ const conversationRuns = runsByThreadId.get(run.threadId) ?? [run];
+
+ return conversationRuns.length > 1
+ ? [
+ {
+ type: 'conversation',
+ threadId: run.threadId,
+ title: run.threadTitle ?? null,
+ runs: conversationRuns,
+ },
+ ]
+ : [{ type: 'run', run }];
+ });
+};
diff --git a/packages/twenty-front/src/modules/object-core/agents/utils/handleCoreAgentRunToggleKeyDown.ts b/packages/twenty-front/src/modules/object-core/agents/utils/handleCoreAgentRunToggleKeyDown.ts
new file mode 100644
index 00000000000..b8cb3e4e88e
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-core/agents/utils/handleCoreAgentRunToggleKeyDown.ts
@@ -0,0 +1,11 @@
+import { type KeyboardEvent } from 'react';
+
+export const handleCoreAgentRunToggleKeyDown =
+ (onToggle: () => void) => (event: KeyboardEvent<HTMLDivElement>) => {
+ if (event.key !== 'Enter' && event.key !== ' ') {
+ return;
+ }
+
+ event.preventDefault();
+ onToggle();
+ };
diff --git a/packages/twenty-front/src/modules/ui/layout/table/components/TableRow.tsx b/packages/twenty-front/src/modules/ui/layout/table/components/TableRow.tsx
index 86de6f86484..7d600832932 100644
--- a/packages/twenty-front/src/modules/ui/layout/table/components/TableRow.tsx
+++ b/packages/twenty-front/src/modules/ui/layout/table/components/TableRow.tsx
@@ -60,6 +60,10 @@ type TableRowProps = {
isExpanded?: boolean;
isClickable?: boolean;
onClick?: () => void;
+ onKeyDown?: React.KeyboardEventHandler<HTMLDivElement>;
+ role?: React.AriaRole;
+ tabIndex?: number;
+ ariaExpanded?: boolean;
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
to?: string;
@@ -79,6 +83,10 @@ export const TableRow = ({
isExpanded,
isClickable,
onClick,
+ onKeyDown,
+ role,
+ tabIndex,
+ ariaExpanded,
onMouseEnter,
onMouseLeave,
to,
@@ -97,6 +105,10 @@ export const TableRow = ({
isSelected={isSelected}
isExpanded={isExpanded}
onClick={onClick}
+ onKeyDown={onKeyDown}
+ role={role}
+ tabIndex={tabIndex}
+ aria-expanded={ariaExpanded}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
gridAutoColumns={gridAutoColumns}
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/__tests__/agent-run-conversation.service.spec.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/__tests__/agent-run-conversation.service.spec.ts
new file mode 100644
index 00000000000..cca58a3502f
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/__tests__/agent-run-conversation.service.spec.ts
@@ -0,0 +1,80 @@
+import { FieldActorSource } from 'twenty-shared/types';
+
+import { AgentRunConversationService } from 'src/engine/metadata-modules/ai/ai-agent-execution/services/agent-run-conversation.service';
+import { AgentMessageRole } from 'src/engine/metadata-modules/ai/ai-history/enums/agent-message-role.enum';
+
+const buildService = () => {
+ const scope = { insert: jest.fn().mockResolvedValue(undefined) };
+ const conversationWriterService = {
+ runInTransaction: jest
+ .fn()
+ .mockImplementation(async (_workspaceId, work) => work(scope)),
+ insertTurn: jest.fn().mockResolvedValue('turn-id'),
+ insertMessage: jest.fn().mockResolvedValue(undefined),
+ };
+
+ return {
+ service: new AgentRunConversationService(
+ { findOne: jest.fn().mockResolvedValue(null) } as never,
+ conversationWriterService as never,
+ {} as never,
+ {} as never,
+ ),
+ conversationWriterService,
+ };
+};
+
+describe('AgentRunConversationService openTurn', () => {
+ it('stores handed-over replies as assistant messages with no sender', async () => {
+ const { service, conversationWriterService } = buildService();
+
+ await service.openTurn({
+ workspaceId: 'workspace-id',
+ threadId: 'thread-id',
+ title: 'Helper',
+ agentId: 'agent-id',
+ senderUserWorkspaceId: 'user-workspace-id',
+ senderApplicationId: null,
+ createdBy: {
+ source: FieldActorSource.MANUAL,
+ name: 'Tim Apple',
+ workspaceMemberId: 'workspace-member-id',
+ context: {},
+ },
+ messages: [
+ { role: 'user', content: 'Who is our biggest customer?' },
+ { role: 'assistant', content: 'Acme.' },
+ { role: 'user', content: 'And the second one?' },
+ ],
+ });
+
+ expect(conversationWriterService.insertMessage).toHaveBeenCalledTimes(3);
+ expect(
+ conversationWriterService.insertMessage.mock.calls.map(([message]) => ({
+ role: message.role,
+ agentId: message.agentId,
+ senderUserWorkspaceId: message.senderUserWorkspaceId,
+ text: message.parts[0].text,
+ })),
+ ).toEqual([
+ {
+ role: AgentMessageRole.USER,
+ agentId: null,
+ senderUserWorkspaceId: 'user-workspace-id',
+ text: 'Who is our biggest customer?',
+ },
+ {
+ role: AgentMessageRole.ASSISTANT,
+ agentId: null,
+ senderUserWorkspaceId: null,
+ text: 'Acme.',
+ },
+ {
+ role: AgentMessageRole.USER,
+ agentId: null,
+ senderUserWorkspaceId: 'user-workspace-id',
+ text: 'And the second one?',
+ },
+ ]);
+ });
+});
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/__tests__/agent-run.service.spec.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/__tests__/agent-run.service.spec.ts
index 0b842716aca..f219d7697c6 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/__tests__/agent-run.service.spec.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/__tests__/agent-run.service.spec.ts
@@ -13,6 +13,12 @@ const AGENT = {
universalIdentifier: 'slack-assistant',
};
const RUN_AS_USER_WORKSPACE_ID = 'user-workspace-id';
+const RUN_AS_ACTOR = {
+ source: 'API',
+ name: 'Tim Apple',
+ workspaceMemberId: 'workspace-member-id',
+ context: {},
+};
const PRIOR_MESSAGES = [{ id: 'message-1', role: 'user', parts: [] }];
const buildService = () => {
@@ -35,7 +41,7 @@ const buildService = () => {
};
const agentActorContextService = {
buildRunAsWorkspaceMemberContext: jest.fn().mockResolvedValue({
- actorContext: {},
+ actorContext: RUN_AS_ACTOR,
authContext: { userWorkspaceId: RUN_AS_USER_WORKSPACE_ID },
roleId: 'role-id',
}),
@@ -62,11 +68,17 @@ const buildService = () => {
const run = (
service: AgentRunService,
input: Record<string, unknown>,
- { isCalledByApplication = true }: { isCalledByApplication?: boolean } = {},
+ {
+ isCalledByApplication = true,
+ requestUserWorkspaceId = null,
+ }: {
+ isCalledByApplication?: boolean;
+ requestUserWorkspaceId?: string | null;
+ } = {},
) =>
service.run({
workspace: WORKSPACE,
- requestUserWorkspaceId: null,
+ requestUserWorkspaceId,
requestWorkspaceMemberId: null,
callerApplication: isCalledByApplication
? (APPLICATION as never)
@@ -77,7 +89,7 @@ const run = (
const userInput = (content: string) => [{ role: 'user', content }];
describe('AgentRunService', () => {
- it('runs without a conversation when no thread is given', async () => {
+ it('records a run without a thread in a conversation of its own', async () => {
const {
service,
agentAsyncExecutorService,
@@ -88,20 +100,58 @@ describe('AgentRunService', () => {
const result = await run(service, {
input: userInput('Who is our biggest customer?'),
});
+ const secondResult = await run(service, {
+ input: userInput('Who is our biggest customer?'),
+ });
expect(result).toEqual({
result: { response: 'Acme is your biggest customer' },
error: null,
success: true,
- threadId: null,
+ threadId: expect.any(String),
});
+ expect(secondResult.threadId).not.toBe(result.threadId);
+ expect(agentRunConversationService.openTurn).toHaveBeenCalledWith(
+ expect.objectContaining({ threadId: secondResult.threadId }),
+ );
+ expect(agentRunConversationService.closeTurn).toHaveBeenCalledWith(
+ expect.objectContaining({ threadId: secondResult.threadId }),
+ );
expect(conversationReaderService.loadMessages).not.toHaveBeenCalled();
- expect(agentRunConversationService.openTurn).not.toHaveBeenCalled();
+ expect(agentRunConversationService.withThreadLock).not.toHaveBeenCalled();
+ expect(agentRunConversationService.openTurn).toHaveBeenCalledWith(
+ expect.objectContaining({
+ threadId: result.threadId,
+ title: AGENT.label,
+ senderUserWorkspaceId: null,
+ senderApplicationId: APPLICATION.id,
+ createdBy: expect.objectContaining({ source: 'APPLICATION' }),
+ messages: userInput('Who is our biggest customer?'),
+ }),
+ );
+ expect(agentRunConversationService.closeTurn).toHaveBeenCalledWith(
+ expect.objectContaining({ threadId: result.threadId, turnId: 'turn-id' }),
+ );
expect(agentAsyncExecutorService.executeAgent).toHaveBeenCalledWith(
expect.objectContaining({ priorMessages: [] }),
);
});
+ it('keeps the replies a run without a thread hands over as its input', async () => {
+ const { service, agentRunConversationService } = buildService();
+ const history = [
+ { role: 'user', content: 'Who is our biggest customer?' },
+ { role: 'assistant', content: 'Acme.' },
+ { role: 'user', content: 'And the second one?' },
+ ];
+
+ await run(service, { input: history });
+
+ expect(agentRunConversationService.openTurn).toHaveBeenCalledWith(
+ expect.objectContaining({ messages: history }),
+ );
+ });
+
it('keeps accepting a prompt', async () => {
const { service, agentAsyncExecutorService } = buildService();
@@ -152,7 +202,8 @@ describe('AgentRunService', () => {
expect.objectContaining({
threadId,
title: AGENT.label,
- actor,
+ senderUserWorkspaceId: RUN_AS_USER_WORKSPACE_ID,
+ createdBy: RUN_AS_ACTOR,
messages: userInput('And the second one?'),
}),
);
@@ -184,7 +235,27 @@ describe('AgentRunService', () => {
expect.objectContaining({
title: 'Acme renewal',
messages: userInput('And the second one?'),
- actor: { type: 'application', applicationId: APPLICATION.id },
+ senderUserWorkspaceId: null,
+ }),
+ );
+ });
+
+ it('records the member who called without an application as the sender', async () => {
+ const { service, agentRunConversationService } = buildService();
+
+ await run(
+ service,
+ { input: userInput('Who is our biggest customer?') },
+ {
+ isCalledByApplication: false,
+ requestUserWorkspaceId: 'caller-user-workspace-id',
+ },
+ );
+
+ expect(agentRunConversationService.openTurn).toHaveBeenCalledWith(
+ expect.objectContaining({
+ senderUserWorkspaceId: 'caller-user-workspace-id',
+ senderApplicationId: null,
}),
);
});
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/agent-run-conversation.service.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/agent-run-conversation.service.ts
index a1776b72627..085bbbe081f 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/agent-run-conversation.service.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/agent-run-conversation.service.ts
@@ -9,8 +9,6 @@ import { type RunAgentMessage } from 'twenty-shared/application';
import { type ActorMetadata } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
-import { buildCreatedByFromApplication } from 'src/engine/core-modules/actor/utils/build-created-by-from-application.util';
-import { type FlatApplication } from 'src/engine/core-modules/application/types/flat-application.type';
import { CacheLockService } from 'src/engine/core-modules/cache-lock/cache-lock.service';
import { type AgentExecutionResult } from 'src/engine/metadata-modules/ai/ai-agent-execution/types/agent-execution-result.type';
import { mapErrorToStreamError } from 'src/engine/metadata-modules/ai/ai-chat/utils/map-error-to-stream-error.util';
@@ -25,7 +23,6 @@ import { AgentHistoryRepository } from 'src/engine/metadata-modules/ai/ai-histor
import { InjectAgentHistoryRepository } from 'src/engine/metadata-modules/ai/ai-history/repositories/inject-agent-history-repository.decorator';
import { AgentConversationWriterService } from 'src/engine/metadata-modules/ai/ai-history/services/agent-conversation-writer.service';
import { type AgentChatThreadWorkspaceEntity } from 'src/engine/metadata-modules/ai/ai-history/standard-objects/agent-chat-thread.workspace-entity';
-import { type AgentConversationActor } from 'src/engine/metadata-modules/ai/ai-history/types/agent-conversation-actor.type';
@Injectable()
export class AgentRunConversationService {
@@ -65,18 +62,18 @@ export class AgentRunConversationService {
threadId,
title,
agentId,
- application,
+ senderUserWorkspaceId,
+ senderApplicationId,
createdBy,
- actor,
messages,
}: {
workspaceId: string;
threadId: string;
title: string;
agentId: string;
- application: FlatApplication;
- createdBy?: ActorMetadata;
- actor: AgentConversationActor;
+ senderUserWorkspaceId: string | null;
+ senderApplicationId: string | null;
+ createdBy: ActorMetadata;
messages: RunAgentMessage[];
}): Promise<string> {
const existingThread = await this.threadRepository.findOne(workspaceId, {
@@ -96,22 +93,28 @@ export class AgentRunConversationService {
threadId,
agentId,
status: AgentTurnStatus.RUNNING,
- createdBy:
- createdBy ?? buildCreatedByFromApplication({ application }),
+ createdBy,
scope,
});
for (const message of messages) {
+ const isAssistantMessage = message.role === 'assistant';
+
await this.conversationWriterService.insertMessage({
workspaceId,
threadId,
turnId,
- role: AgentMessageRole.USER,
+ role: isAssistantMessage
+ ? AgentMessageRole.ASSISTANT
+ : AgentMessageRole.USER,
agentId: null,
- senderUserWorkspaceId:
- actor.type === 'user' ? actor.userWorkspaceId : null,
- senderApplicationId: application.id,
- parts: this.buildUserMessageParts(message),
+ senderUserWorkspaceId: isAssistantMessage
+ ? null
+ : senderUserWorkspaceId,
+ senderApplicationId: isAssistantMessage
+ ? null
+ : senderApplicationId,
+ parts: this.buildMessageParts(message),
scope,
});
}
@@ -176,9 +179,7 @@ export class AgentRunConversationService {
});
}
- private buildUserMessageParts(
- message: RunAgentMessage,
- ): ExtendedUIMessagePart[] {
+ private buildMessageParts(message: RunAgentMessage): ExtendedUIMessagePart[] {
const fileParts = (message.attachments ?? []).map(
(attachment): ExtendedFileUIPart => ({
type: 'file',
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/agent-run.service.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/agent-run.service.ts
index ad37928c777..1bc7a696b60 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/agent-run.service.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-execution/services/agent-run.service.ts
@@ -1,15 +1,21 @@
import { Injectable, Logger, NotFoundException } from '@nestjs/common';
+import { randomUUID } from 'node:crypto';
+
import { isNonEmptyString } from '@sniptt/guards';
import {
type RunAgentMessage,
type RunAgentResult,
type RunAgentThread,
} from 'twenty-shared/application';
+import { type ActorMetadata } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
+import { buildActorMetadataFromAuthContext } from 'src/engine/core-modules/actor/utils/build-actor-metadata-from-auth-context.util';
+import { buildCreatedByFromApplication } from 'src/engine/core-modules/actor/utils/build-created-by-from-application.util';
import { ApplicationLookupService } from 'src/engine/core-modules/application/application-lookup/application-lookup.service';
import { type FlatApplication } from 'src/engine/core-modules/application/types/flat-application.type';
+import { workspaceAuthContextStorage } from 'src/engine/core-modules/auth/storage/workspace-auth-context.storage';
import { type WorkspaceAuthContext } from 'src/engine/core-modules/auth/types/workspace-auth-context.type';
import { type FlatWorkspace } from 'src/engine/core-modules/workspace/types/flat-workspace.type';
import { AgentActorContextService } from 'src/engine/metadata-modules/ai/ai-agent-execution/services/agent-actor-context.service';
@@ -143,6 +149,12 @@ export class AgentRunService {
}
: { type: 'application', applicationId: application.id };
+ const senderUserWorkspaceId = this.resolveRunSender({
+ runAsContext,
+ callerApplication,
+ requestUserWorkspaceId,
+ });
+
const threadTitle = isNonEmptyString(thread?.title)
? thread.title
: agent.label;
@@ -153,7 +165,11 @@ export class AgentRunService {
agentId: agent.id,
threadKey: thread.key,
})
- : null;
+ : randomUUID();
+
+ const createdBy =
+ runAsContext?.actorContext ??
+ this.buildRunCreator({ callerApplication, application });
const executionMessages = isNonEmptyString(input.additionalInstructions)
? addAdditionalInstructionsToLastRunAgentMessage({
@@ -163,7 +179,7 @@ export class AgentRunService {
: messages;
const runTurn = async (): Promise<RunAgentResult> => {
- const priorMessages = isDefined(threadId)
+ const priorMessages = isDefined(thread)
? await this.conversationReaderService.loadMessages({
workspaceId: workspace.id,
threadId,
@@ -171,23 +187,21 @@ export class AgentRunService {
})
: [];
- const turnId = isDefined(threadId)
- ? await this.recordConversation({
+ const turnId = await this.recordConversation({
+ threadId,
+ agentUniversalIdentifier: input.agentUniversalIdentifier,
+ record: () =>
+ this.agentRunConversationService.openTurn({
+ workspaceId: workspace.id,
threadId,
- agentUniversalIdentifier: input.agentUniversalIdentifier,
- record: () =>
- this.agentRunConversationService.openTurn({
- workspaceId: workspace.id,
- threadId,
- title: threadTitle,
- agentId: agent.id,
- application,
- actor,
- createdBy: runAsContext?.actorContext,
- messages,
- }),
- })
- : null;
+ title: threadTitle,
+ agentId: agent.id,
+ senderUserWorkspaceId,
+ senderApplicationId: callerApplication?.id ?? null,
+ createdBy,
+ messages,
+ }),
+ });
let executionResult: AgentExecutionResult;
@@ -209,7 +223,7 @@ export class AgentRunService {
}),
);
} catch (error) {
- if (isDefined(threadId) && isDefined(turnId)) {
+ if (isDefined(turnId)) {
await this.recordConversation({
threadId,
agentUniversalIdentifier: input.agentUniversalIdentifier,
@@ -225,7 +239,7 @@ export class AgentRunService {
throw error;
}
- if (isDefined(threadId) && isDefined(turnId)) {
+ if (isDefined(turnId)) {
await this.recordConversation({
threadId,
agentUniversalIdentifier: input.agentUniversalIdentifier,
@@ -258,7 +272,7 @@ export class AgentRunService {
};
try {
- return isDefined(threadId)
+ return isDefined(thread)
? await this.agentRunConversationService.withThreadLock({
workspaceId: workspace.id,
threadId,
@@ -287,6 +301,45 @@ export class AgentRunService {
}
}
+ // a member calling without runAs still sent the input, while an app's call has no member behind it
+ private resolveRunSender({
+ runAsContext,
+ callerApplication,
+ requestUserWorkspaceId,
+ }: {
+ runAsContext?: RunAsWorkspaceMemberContext;
+ callerApplication?: FlatApplication;
+ requestUserWorkspaceId: string | null;
+ }): string | null {
+ if (isDefined(runAsContext)) {
+ return runAsContext.authContext.userWorkspaceId;
+ }
+
+ if (isDefined(callerApplication)) {
+ return null;
+ }
+
+ return requestUserWorkspaceId;
+ }
+
+ private buildRunCreator({
+ callerApplication,
+ application,
+ }: {
+ callerApplication?: FlatApplication;
+ application: FlatApplication;
+ }): ActorMetadata {
+ if (isDefined(callerApplication)) {
+ return buildCreatedByFromApplication({ application: callerApplication });
+ }
+
+ const requestAuthContext = workspaceAuthContextStorage.getStore();
+
+ return isDefined(requestAuthContext)
+ ? buildActorMetadataFromAuthContext(requestAuthContext)
+ : buildCreatedByFromApplication({ application });
+ }
+
// A record of the run, not its outcome, so a write failure must not fail the run
private async recordConversation<TResult>({
threadId,
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/ai-agent-runs.module.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/ai-agent-runs.module.ts
new file mode 100644
index 00000000000..25361747459
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/ai-agent-runs.module.ts
@@ -0,0 +1,12 @@
+import { Module } from '@nestjs/common';
+
+import { AgentRunsResolver } from 'src/engine/metadata-modules/ai/ai-agent-runs/resolvers/agent-runs.resolver';
+import { AgentRunsService } from 'src/engine/metadata-modules/ai/ai-agent-runs/services/agent-runs.service';
+import { AgentHistoryModule } from 'src/engine/metadata-modules/ai/ai-history/ai-history.module';
+import { PermissionsModule } from 'src/engine/metadata-modules/permissions/permissions.module';
+
+@Module({
+ imports: [AgentHistoryModule, PermissionsModule],
+ providers: [AgentRunsResolver, AgentRunsService],
+})
+export class AiAgentRunsModule {}
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/constants/agent-runs-max-limit.constant.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/constants/agent-runs-max-limit.constant.ts
new file mode 100644
index 00000000000..ab7e213c087
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/constants/agent-runs-max-limit.constant.ts
@@ -0,0 +1 @@
+export const AGENT_RUNS_MAX_LIMIT = 200;
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/dtos/agent-run.dto.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/dtos/agent-run.dto.ts
new file mode 100644
index 00000000000..2db034a8ffe
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/dtos/agent-run.dto.ts
@@ -0,0 +1,58 @@
+import { Field, Float, Int, ObjectType } from '@nestjs/graphql';
+
+import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
+import { AgentTurnStatus } from 'src/engine/metadata-modules/ai/ai-history/enums/agent-turn-status.enum';
+
+@ObjectType('AgentRun')
+export class AgentRunDTO {
+ @Field(() => UUIDScalarType)
+ id: string;
+
+ @Field(() => UUIDScalarType)
+ threadId: string;
+
+ @Field(() => String, { nullable: true })
+ threadTitle: string | null;
+
+ @Field(() => AgentTurnStatus)
+ status: AgentTurnStatus;
+
+ @Field(() => String, { nullable: true })
+ errorMessage: string | null;
+
+ @Field(() => Date)
+ createdAt: Date;
+
+ @Field(() => Date, { nullable: true })
+ startedAt: Date | null;
+
+ @Field(() => Date, { nullable: true })
+ endedAt: Date | null;
+
+ @Field(() => String, { nullable: true })
+ modelId: string | null;
+
+ @Field(() => Int, { nullable: true })
+ inputTokens: number | null;
+
+ @Field(() => Int, { nullable: true })
+ outputTokens: number | null;
+
+ @Field(() => Float, { nullable: true })
+ credits: number | null;
+
+ @Field(() => String)
+ creatorSource: string;
+
+ @Field(() => String)
+ creatorName: string;
+
+ @Field(() => String, { nullable: true })
+ input: string | null;
+
+ @Field(() => String, { nullable: true })
+ reply: string | null;
+
+ @Field(() => [String])
+ toolNames: string[];
+}
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/resolvers/agent-runs.resolver.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/resolvers/agent-runs.resolver.ts
new file mode 100644
index 00000000000..ca2b71698e2
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/resolvers/agent-runs.resolver.ts
@@ -0,0 +1,43 @@
+import { UseFilters, UseGuards } from '@nestjs/common';
+import { Args, Int, Query } from '@nestjs/graphql';
+
+import { PermissionFlagType } from 'twenty-shared/constants';
+
+import { MetadataResolver } from 'src/engine/api/graphql/graphql-config/decorators/metadata-resolver.decorator';
+import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
+import { AuthGraphqlApiExceptionFilter } from 'src/engine/core-modules/auth/filters/auth-graphql-api-exception.filter';
+import { type WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
+import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
+import { AuthPrincipalGuard } from 'src/engine/guards/auth-principal.guard';
+import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard';
+import { AgentRunDTO } from 'src/engine/metadata-modules/ai/ai-agent-runs/dtos/agent-run.dto';
+import { AgentRunsService } from 'src/engine/metadata-modules/ai/ai-agent-runs/services/agent-runs.service';
+
+@UseGuards(
+ AuthPrincipalGuard({
+ userSession: {
+ standard: true,
+ impersonated: true,
+ playground: true,
+ workspaceAgnostic: false,
+ },
+ apiKey: true,
+ oauthClient: true,
+ application: true,
+ }),
+ SettingsPermissionGuard(PermissionFlagType.AI_SETTINGS),
+)
+@MetadataResolver(() => AgentRunDTO)
+@UseFilters(AuthGraphqlApiExceptionFilter)
+export class AgentRunsResolver {
+ constructor(private readonly agentRunsService: AgentRunsService) {}
+
+ @Query(() => [AgentRunDTO])
+ async agentRuns(
+ @Args('agentId', { type: () => UUIDScalarType }) agentId: string,
+ @Args('limit', { type: () => Int, defaultValue: 100 }) limit: number,
+ @AuthWorkspace() { id: workspaceId }: WorkspaceEntity,
+ ): Promise<AgentRunDTO[]> {
+ return this.agentRunsService.findAgentRuns({ workspaceId, agentId, limit });
+ }
+}
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/services/__tests__/agent-runs.service.spec.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/services/__tests__/agent-runs.service.spec.ts
new file mode 100644
index 00000000000..95496db8868
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/services/__tests__/agent-runs.service.spec.ts
@@ -0,0 +1,131 @@
+import { FieldActorSource } from 'twenty-shared/types';
+import { In } from 'typeorm';
+
+import { AgentRunsService } from 'src/engine/metadata-modules/ai/ai-agent-runs/services/agent-runs.service';
+import { AgentTurnStatus } from 'src/engine/metadata-modules/ai/ai-history/enums/agent-turn-status.enum';
+
+const buildTurn = (id: string) => ({
+ id,
+ threadId: `thread-of-${id}`,
+ status: AgentTurnStatus.COMPLETED,
+ error: null,
+ createdAt: '2026-10-05T10:00:00.000Z',
+ startedAt: null,
+ endedAt: null,
+ modelId: null,
+ inputTokens: null,
+ outputTokens: null,
+ inputCredits: null,
+ outputCredits: null,
+ createdBy: {
+ source: FieldActorSource.APPLICATION,
+ name: 'App',
+ workspaceMemberId: null,
+ context: {},
+ },
+ thread: { title: null },
+});
+
+const buildService = ({
+ turns,
+ messages,
+ parts,
+}: {
+ turns: unknown[];
+ messages: unknown[];
+ parts: unknown[];
+}) => {
+ const turnRepository = { find: jest.fn().mockResolvedValue(turns) };
+ const messageRepository = { find: jest.fn().mockResolvedValue(messages) };
+ const messagePartRepository = { find: jest.fn().mockResolvedValue(parts) };
+
+ return {
+ service: new AgentRunsService(
+ turnRepository as never,
+ messageRepository as never,
+ messagePartRepository as never,
+ ),
+ turnRepository,
+ messageRepository,
+ messagePartRepository,
+ };
+};
+
+describe('AgentRunsService', () => {
+ it('gives each run the messages and parts of its own turn', async () => {
+ const { service, messageRepository, messagePartRepository } = buildService({
+ turns: [buildTurn('turn-a'), buildTurn('turn-b')],
+ messages: [
+ {
+ id: 'message-a',
+ turnId: 'turn-a',
+ role: 'user',
+ createdAt: '2026-10-05T10:00:00.000Z',
+ },
+ {
+ id: 'message-b',
+ turnId: 'turn-b',
+ role: 'user',
+ createdAt: '2026-10-05T10:00:00.000Z',
+ },
+ ],
+ parts: [
+ {
+ id: 'part-a',
+ messageId: 'message-a',
+ orderIndex: 0,
+ type: 'text',
+ textContent: 'First input',
+ toolName: null,
+ },
+ {
+ id: 'part-b',
+ messageId: 'message-b',
+ orderIndex: 0,
+ type: 'text',
+ textContent: 'Second input',
+ toolName: null,
+ },
+ ],
+ });
+
+ const runs = await service.findAgentRuns({
+ workspaceId: 'workspace-id',
+ agentId: 'agent-id',
+ limit: 10,
+ });
+
+ expect(runs.map((run) => run.input)).toEqual([
+ 'First input',
+ 'Second input',
+ ]);
+ expect(messageRepository.find).toHaveBeenCalledWith(
+ 'workspace-id',
+ expect.objectContaining({ where: { turnId: In(['turn-a', 'turn-b']) } }),
+ );
+ const [partWorkspaceId, partQuery] =
+ messagePartRepository.find.mock.calls[0];
+
+ expect(partWorkspaceId).toBe('workspace-id');
+ expect(partQuery.select).not.toContain('toolInput');
+ expect(partQuery.select).not.toContain('toolOutput');
+ });
+
+ it('reads no messages when the agent has no runs', async () => {
+ const { service, messageRepository, messagePartRepository } = buildService({
+ turns: [],
+ messages: [],
+ parts: [],
+ });
+
+ expect(
+ await service.findAgentRuns({
+ workspaceId: 'workspace-id',
+ agentId: 'agent-id',
+ limit: 10,
+ }),
+ ).toEqual([]);
+ expect(messageRepository.find).not.toHaveBeenCalled();
+ expect(messagePartRepository.find).not.toHaveBeenCalled();
+ });
+});
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/services/agent-runs.service.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/services/agent-runs.service.ts
new file mode 100644
index 00000000000..4bbb46cdce1
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/services/agent-runs.service.ts
@@ -0,0 +1,80 @@
+import { Injectable } from '@nestjs/common';
+
+import groupBy from 'lodash.groupby';
+import { In } from 'typeorm';
+
+import { AGENT_RUNS_MAX_LIMIT } from 'src/engine/metadata-modules/ai/ai-agent-runs/constants/agent-runs-max-limit.constant';
+import { type AgentRunDTO } from 'src/engine/metadata-modules/ai/ai-agent-runs/dtos/agent-run.dto';
+import { mapAgentTurnToAgentRun } from 'src/engine/metadata-modules/ai/ai-agent-runs/utils/map-agent-turn-to-agent-run.util';
+import { AgentHistoryRepository } from 'src/engine/metadata-modules/ai/ai-history/repositories/agent-history-repository';
+import { InjectAgentHistoryRepository } from 'src/engine/metadata-modules/ai/ai-history/repositories/inject-agent-history-repository.decorator';
+import { type AgentMessagePartWorkspaceEntity } from 'src/engine/metadata-modules/ai/ai-history/standard-objects/agent-message-part.workspace-entity';
+import { type AgentMessageWorkspaceEntity } from 'src/engine/metadata-modules/ai/ai-history/standard-objects/agent-message.workspace-entity';
+import { type AgentTurnWorkspaceEntity } from 'src/engine/metadata-modules/ai/ai-history/standard-objects/agent-turn.workspace-entity';
+
+@Injectable()
+export class AgentRunsService {
+ constructor(
+ @InjectAgentHistoryRepository('agentTurn')
+ private readonly turnRepository: AgentHistoryRepository<AgentTurnWorkspaceEntity>,
+ @InjectAgentHistoryRepository('agentMessage')
+ private readonly messageRepository: AgentHistoryRepository<AgentMessageWorkspaceEntity>,
+ @InjectAgentHistoryRepository('agentMessagePart')
+ private readonly messagePartRepository: AgentHistoryRepository<AgentMessagePartWorkspaceEntity>,
+ ) {}
+
+ // tool inputs and outputs can be large, so parts are read without them
+ async findAgentRuns({
+ workspaceId,
+ agentId,
+ limit,
+ }: {
+ workspaceId: string;
+ agentId: string;
+ limit: number;
+ }): Promise<AgentRunDTO[]> {
+ const turns = await this.turnRepository.find(workspaceId, {
+ where: { agentId },
+ order: { createdAt: 'DESC', id: 'DESC' },
+ take: Math.min(Math.max(limit, 1), AGENT_RUNS_MAX_LIMIT),
+ relations: { thread: true },
+ });
+
+ const messages =
+ turns.length > 0
+ ? await this.messageRepository.find(workspaceId, {
+ where: { turnId: In(turns.map((turn) => turn.id)) },
+ select: ['id', 'turnId', 'role', 'agentId', 'createdAt'],
+ order: { createdAt: 'ASC' },
+ })
+ : [];
+
+ const parts =
+ messages.length > 0
+ ? await this.messagePartRepository.find(workspaceId, {
+ where: { messageId: In(messages.map((message) => message.id)) },
+ select: [
+ 'id',
+ 'messageId',
+ 'orderIndex',
+ 'type',
+ 'textContent',
+ 'toolName',
+ ],
+ })
+ : [];
+
+ const partsByMessageId = groupBy(parts, (part) => part.messageId);
+ const messagesByTurnId = groupBy(messages, (message) => message.turnId);
+
+ return turns.map((turn) =>
+ mapAgentTurnToAgentRun({
+ ...turn,
+ messages: (messagesByTurnId[turn.id] ?? []).map((message) => ({
+ ...message,
+ parts: partsByMessageId[message.id] ?? [],
+ })),
+ }),
+ );
+ }
+}
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/utils/__tests__/map-agent-turn-to-agent-run.util.spec.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/utils/__tests__/map-agent-turn-to-agent-run.util.spec.ts
new file mode 100644
index 00000000000..d8af4ce60c7
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/utils/__tests__/map-agent-turn-to-agent-run.util.spec.ts
@@ -0,0 +1,197 @@
+import { FieldActorSource } from 'twenty-shared/types';
+
+import { mapAgentTurnToAgentRun } from 'src/engine/metadata-modules/ai/ai-agent-runs/utils/map-agent-turn-to-agent-run.util';
+import { AgentTurnStatus } from 'src/engine/metadata-modules/ai/ai-history/enums/agent-turn-status.enum';
+
+const baseTurn = {
+ id: 'turn-id',
+ threadId: 'thread-id',
+ status: AgentTurnStatus.COMPLETED,
+ error: null,
+ createdAt: '2026-10-05T10:00:00.000Z',
+ startedAt: '2026-10-05T10:00:00.000Z',
+ endedAt: '2026-10-05T10:00:06.000Z',
+ modelId: 'model-id',
+ inputTokens: 1_200,
+ outputTokens: 80,
+ inputCredits: '1500000',
+ outputCredits: '500000',
+ createdBy: {
+ source: FieldActorSource.WORKFLOW,
+ name: 'Qualify inbound lead',
+ workspaceMemberId: null,
+ context: {},
+ },
+ thread: { title: 'Lead qualification' },
+};
+
+describe('mapAgentTurnToAgentRun', () => {
+ it('reads the input, the last reply and the tools the agent used', () => {
+ const run = mapAgentTurnToAgentRun({
+ ...baseTurn,
+ messages: [
+ {
+ role: 'assistant',
+ agentId: 'agent-id',
+ createdAt: '2026-10-05T10:00:02.000Z',
+ parts: [
+ {
+ orderIndex: 0,
+ type: 'text',
+ textContent: 'Looking the company up.',
+ toolName: null,
+ },
+ ],
+ },
+ {
+ role: 'assistant',
+ agentId: 'agent-id',
+ createdAt: '2026-10-05T10:00:05.000Z',
+ parts: [
+ {
+ orderIndex: 1,
+ type: 'text',
+ textContent: 'Qualified, tier A.',
+ toolName: null,
+ },
+ {
+ orderIndex: 0,
+ type: 'tool-find_companies',
+ textContent: null,
+ toolName: 'find_companies',
+ },
+ ],
+ },
+ {
+ role: 'user',
+ agentId: null,
+ createdAt: '2026-10-05T10:00:00.000Z',
+ parts: [
+ {
+ orderIndex: 0,
+ type: 'text',
+ textContent: 'New signup: Priya Nair',
+ toolName: null,
+ },
+ ],
+ },
+ ],
+ });
+
+ expect(run).toMatchObject({
+ threadTitle: 'Lead qualification',
+ status: AgentTurnStatus.COMPLETED,
+ input: 'New signup: Priya Nair',
+ reply: 'Qualified, tier A.',
+ toolNames: ['find_companies'],
+ creatorSource: FieldActorSource.WORKFLOW,
+ creatorName: 'Qualify inbound lead',
+ inputTokens: 1_200,
+ outputTokens: 80,
+ credits: 2,
+ });
+ expect(run.endedAt).toEqual(new Date('2026-10-05T10:00:06.000Z'));
+ });
+
+ it('reads dates the ORM returns as Date objects and leaves a blank model empty', () => {
+ const run = mapAgentTurnToAgentRun({
+ ...baseTurn,
+ modelId: '',
+ messages: [
+ {
+ role: 'assistant',
+ agentId: 'agent-id',
+ createdAt: new Date('2026-10-05T10:00:05.000Z'),
+ parts: [
+ {
+ orderIndex: 0,
+ type: 'text',
+ textContent: 'Done.',
+ toolName: null,
+ },
+ ],
+ },
+ {
+ role: 'user',
+ agentId: null,
+ createdAt: new Date('2026-10-05T10:00:00.000Z'),
+ parts: [
+ { orderIndex: 0, type: 'text', textContent: 'Go.', toolName: null },
+ ],
+ },
+ ],
+ });
+
+ expect(run).toMatchObject({ input: 'Go.', reply: 'Done.', modelId: null });
+ });
+
+ it('treats replies a caller handed over as input, not as the agent output', () => {
+ const run = mapAgentTurnToAgentRun({
+ ...baseTurn,
+ status: AgentTurnStatus.FAILED,
+ messages: [
+ {
+ role: 'user',
+ agentId: null,
+ createdAt: '2026-10-05T10:00:00.000Z',
+ parts: [
+ {
+ orderIndex: 0,
+ type: 'text',
+ textContent: 'Who?',
+ toolName: null,
+ },
+ ],
+ },
+ {
+ role: 'assistant',
+ agentId: null,
+ createdAt: '2026-10-05T10:00:01.000Z',
+ parts: [
+ {
+ orderIndex: 0,
+ type: 'text',
+ textContent: 'Acme.',
+ toolName: null,
+ },
+ ],
+ },
+ ],
+ });
+
+ expect(run).toMatchObject({ input: 'Who?\n\nAcme.', reply: null });
+ });
+
+ it('leaves usage empty on a turn recorded before usage was counted', () => {
+ const run = mapAgentTurnToAgentRun({
+ ...baseTurn,
+ inputTokens: null,
+ outputTokens: null,
+ inputCredits: null,
+ outputCredits: null,
+ messages: [],
+ });
+
+ expect(run).toMatchObject({
+ inputTokens: null,
+ credits: null,
+ input: null,
+ reply: null,
+ toolNames: [],
+ });
+ });
+
+ it('exposes the error of a failed turn', () => {
+ const run = mapAgentTurnToAgentRun({
+ ...baseTurn,
+ status: AgentTurnStatus.FAILED,
+ error: {
+ code: 'STREAM_INTERRUPTED',
+ message: 'The response was interrupted.',
+ },
+ messages: [],
+ });
+
+ expect(run.errorMessage).toBe('The response was interrupted.');
+ });
+});
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/utils/map-agent-turn-to-agent-run.util.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/utils/map-agent-turn-to-agent-run.util.ts
new file mode 100644
index 00000000000..31984978a0e
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-runs/utils/map-agent-turn-to-agent-run.util.ts
@@ -0,0 +1,115 @@
+import { isNonEmptyString } from '@sniptt/guards';
+import { isDefined } from 'twenty-shared/utils';
+
+import { toDisplayCredits } from 'src/engine/core-modules/usage/utils/to-display-credits.util';
+import { type AgentRunDTO } from 'src/engine/metadata-modules/ai/ai-agent-runs/dtos/agent-run.dto';
+import { AgentMessageRole } from 'src/engine/metadata-modules/ai/ai-history/enums/agent-message-role.enum';
+import { type AgentTurnWorkspaceEntity } from 'src/engine/metadata-modules/ai/ai-history/standard-objects/agent-turn.workspace-entity';
+
+type AgentRunMessagePart = {
+ orderIndex: number;
+ type: string;
+ textContent: string | null;
+ toolName: string | null;
+};
+
+type AgentRunMessage = {
+ role: string;
+ agentId: string | null;
+ createdAt: string | Date;
+ parts?: AgentRunMessagePart[] | null;
+};
+
+type AgentRunSourceTurn = Pick<
+ AgentTurnWorkspaceEntity,
+ | 'id'
+ | 'threadId'
+ | 'status'
+ | 'error'
+ | 'createdAt'
+ | 'startedAt'
+ | 'endedAt'
+ | 'modelId'
+ | 'inputTokens'
+ | 'outputTokens'
+ | 'inputCredits'
+ | 'outputCredits'
+ | 'createdBy'
+> & {
+ thread?: { title: string | null } | null;
+ messages?: AgentRunMessage[] | null;
+};
+
+const sortParts = (parts: AgentRunMessagePart[] | null | undefined) =>
+ [...(parts ?? [])].sort((left, right) => left.orderIndex - right.orderIndex);
+
+const joinText = (messages: AgentRunMessage[]): string | null => {
+ const text = messages
+ .flatMap((message) => sortParts(message.parts))
+ .filter(
+ (part) => part.type === 'text' && isNonEmptyString(part.textContent),
+ )
+ .map((part) => part.textContent)
+ .join('\n\n')
+ .trim();
+
+ return isNonEmptyString(text) ? text : null;
+};
+
+const toDate = (value: string | null): Date | null =>
+ isDefined(value) ? new Date(value) : null;
+
+// usage is empty on turns recorded before it was counted
+const toCredits = (
+ inputCredits: string | null,
+ outputCredits: string | null,
+): number | null =>
+ isDefined(inputCredits) || isDefined(outputCredits)
+ ? toDisplayCredits(Number(inputCredits ?? 0) + Number(outputCredits ?? 0))
+ : null;
+
+export const mapAgentTurnToAgentRun = (
+ turn: AgentRunSourceTurn,
+): AgentRunDTO => {
+ // the ORM returns timestamps as dates although the entity types them as strings
+ const messages = [...(turn.messages ?? [])].sort(
+ (left, right) =>
+ new Date(left.createdAt).getTime() - new Date(right.createdAt).getTime(),
+ );
+ // replies a caller hands over are input too; only messages the agent wrote carry its id
+ const agentMessages = messages.filter(
+ (message) =>
+ message.role === AgentMessageRole.ASSISTANT && isDefined(message.agentId),
+ );
+ const inputMessages = messages.filter(
+ (message) => !isDefined(message.agentId),
+ );
+ const lastAgentMessage = agentMessages.at(-1);
+
+ return {
+ id: turn.id,
+ threadId: turn.threadId,
+ threadTitle: turn.thread?.title ?? null,
+ status: turn.status,
+ errorMessage: turn.error?.message ?? null,
+ createdAt: new Date(turn.createdAt),
+ startedAt: toDate(turn.startedAt),
+ endedAt: toDate(turn.endedAt),
+ modelId: isNonEmptyString(turn.modelId) ? turn.modelId : null,
+ inputTokens: turn.inputTokens,
+ outputTokens: turn.outputTokens,
+ credits: toCredits(turn.inputCredits, turn.outputCredits),
+ creatorSource: turn.createdBy.source,
+ creatorName: turn.createdBy.name,
+ input: joinText(inputMessages),
+ reply: isDefined(lastAgentMessage) ? joinText([lastAgentMessage]) : null,
+ toolNames: [
+ ...new Set(
+ agentMessages
+ .flatMap((message) => sortParts(message.parts))
+ .map((part) => part.toolName)
+ .filter(isNonEmptyString),
+ ),
+ ],
+ };
+};
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-trigger/services/agent-trigger-runner.service.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-trigger/services/agent-trigger-runner.service.ts
index c178437ba63..2b2619b93d4 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-trigger/services/agent-trigger-runner.service.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-agent-trigger/services/agent-trigger-runner.service.ts
@@ -126,9 +126,9 @@ export class AgentTriggerRunnerService {
threadId,
title: agent.label,
agentId: agent.id,
- application,
+ senderUserWorkspaceId: null,
+ senderApplicationId: application.id,
createdBy,
- actor: { type: 'application', applicationId: application.id },
messages,
})
.catch(logRecordFailure);
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-history/enums/agent-turn-status.enum.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-history/enums/agent-turn-status.enum.ts
index b68044fd706..0884cb9ced4 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-history/enums/agent-turn-status.enum.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-history/enums/agent-turn-status.enum.ts
@@ -1,3 +1,5 @@
+import { registerEnumType } from '@nestjs/graphql';
+
export enum AgentTurnStatus {
RUNNING = 'running',
WAITING_FOR_INPUT = 'waiting_for_input',
@@ -5,3 +7,5 @@ export enum AgentTurnStatus {
CANCELLED = 'cancelled',
FAILED = 'failed',
}
+
+registerEnumType(AgentTurnStatus, { name: 'AgentTurnStatus' });
diff --git a/packages/twenty-server/src/engine/metadata-modules/metadata-engine.module.ts b/packages/twenty-server/src/engine/metadata-modules/metadata-engine.module.ts
index 68da45510a8..3c400bc7059 100644
--- a/packages/twenty-server/src/engine/metadata-modules/metadata-engine.module.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/metadata-engine.module.ts
@@ -3,6 +3,7 @@ import { Module } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core';
import { AiAgentModule } from 'src/engine/metadata-modules/ai/ai-agent/ai-agent.module';
+import { AiAgentRunsModule } from 'src/engine/metadata-modules/ai/ai-agent-runs/ai-agent-runs.module';
import { AiChatModule } from 'src/engine/metadata-modules/ai/ai-chat/ai-chat.module';
import { AiGenerateTextModule } from 'src/engine/metadata-modules/ai/ai-generate-text/ai-generate-text.module';
import { AiWorkspaceStatsModule } from 'src/engine/metadata-modules/ai/ai-workspace-stats/ai-workspace-stats.module';
@@ -55,6 +56,7 @@ import { WorkspaceMetadataVersionModule } from 'src/engine/metadata-modules/work
TimelineActivityTypeModule,
ValidationRuleModule,
AiAgentModule,
+ AiAgentRunsModule,
AiChatModule,
AiGenerateTextModule,
AiWorkspaceStatsModule,
diff --git a/packages/twenty-server/test/integration/endpoint-permissions/__snapshots__/endpoint-permission-declarations.integration-spec.ts.snap b/packages/twenty-server/test/integration/endpoint-permissions/__snapshots__/endpoint-permission-declarations.integration-spec.ts.snap
index eb149e86227..e9b9f1630ef 100644
--- a/packages/twenty-server/test/integration/endpoint-permissions/__snapshots__/endpoint-permission-declarations.integration-spec.ts.snap
+++ b/packages/twenty-server/test/integration/endpoint-permissions/__snapshots__/endpoint-permission-declarations.integration-spec.ts.snap
@@ -84,6 +84,7 @@ exports[`endpoint permission declarations should match the AuthPrincipalGuard an
"AgentResolver.findOneAgent {"applicationTarget":{"argName":"input","idKey":"id","kind":"applicationOwnedEntity","metadataName":"agent","requireApplicationRegistrationOwnership":false,"source":"graphqlArg"},"authPrincipalGuards":[{"apiKey":true,"application":true,"oauthClient":true,"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}",
"AgentResolver.updateOneAgent {"applicationTarget":{"argName":"input","idKey":"id","kind":"applicationOwnedEntity","metadataName":"agent","requireApplicationRegistrationOwnership":false,"source":"graphqlArg"},"authPrincipalGuards":[{"apiKey":true,"application":true,"oauthClient":true,"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}",
"AgentRunResolver.runAgent {"applicationTarget":null,"authPrincipalGuards":[{"apiKey":true,"application":true,"oauthClient":true,"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}",
+ "AgentRunsResolver.agentRuns {"applicationTarget":null,"authPrincipalGuards":[{"apiKey":true,"application":true,"oauthClient":true,"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}",
"AiChatUsageResolver.aiChatUsage {"applicationTarget":null,"authPrincipalGuards":[{"apiKey":true,"application":true,"oauthClient":true,"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}",
"AiGenerateTextController.handleGenerateText {"applicationTarget":null,"authPrincipalGuards":[{"apiKey":true,"application":true,"oauthClient":true,"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}",
"AiWorkspaceStatsResolver.findWorkspaceAiStats {"applicationTarget":null,"authPrincipalGuards":[{"apiKey":true,"application":true,"oauthClient":true,"userSession":{"impersonated":true,"playground":true,"standard":true,"workspaceAgnostic":false}}]}",