Skip to content

Commit 3a19619

Browse files
committed
feat(agent): agent interruptions
1 parent c83fa9d commit 3a19619

38 files changed

Lines changed: 1603 additions & 68 deletions
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""add_agent_session_status
2+
3+
Revision ID: e1a2b3c4d5f6
4+
Revises: a3d7c9e8b4f2
5+
Create Date: 2026-05-26 00:00:00.000000
6+
7+
"""
8+
9+
from collections.abc import Sequence
10+
11+
import sqlalchemy as sa
12+
13+
from alembic import op
14+
15+
# revision identifiers, used by Alembic.
16+
revision: str = "e1a2b3c4d5f6"
17+
down_revision: str | None = "a3d7c9e8b4f2"
18+
branch_labels: str | Sequence[str] | None = None
19+
depends_on: str | Sequence[str] | None = None
20+
21+
22+
def upgrade() -> None:
23+
op.add_column(
24+
"agent_session",
25+
sa.Column(
26+
"status",
27+
sa.String(length=32),
28+
server_default="idle",
29+
nullable=False,
30+
),
31+
)
32+
op.create_index(
33+
op.f("ix_agent_session_status"),
34+
"agent_session",
35+
["status"],
36+
unique=False,
37+
)
38+
39+
40+
def downgrade() -> None:
41+
op.drop_index(op.f("ix_agent_session_status"), table_name="agent_session")
42+
op.drop_column("agent_session", "status")

deployments/k8s

Submodule k8s updated from d19d666 to d94b52b

frontend/src/client/schemas.gen.ts

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,11 @@ export const $AdminUserRead = {
12121212
description: "Admin view of a user.",
12131213
} as const
12141214

1215+
export const $AgentCancelReason = {
1216+
type: "string",
1217+
enum: ["user_cancel", "worker_drain"],
1218+
} as const
1219+
12151220
export const $AgentCatalogListResponse = {
12161221
properties: {
12171222
items: {
@@ -3329,6 +3334,45 @@ export const $AgentPresetVersionReadMinimal = {
33293334
description: "Metadata returned when listing immutable preset versions.",
33303335
} as const
33313336

3337+
export const $AgentSessionCancelRequest = {
3338+
properties: {
3339+
reason: {
3340+
$ref: "#/components/schemas/AgentCancelReason",
3341+
description: "Reason for requesting cancellation.",
3342+
default: "user_cancel",
3343+
},
3344+
},
3345+
type: "object",
3346+
title: "AgentSessionCancelRequest",
3347+
description: "Request schema for cancelling an active agent session turn.",
3348+
} as const
3349+
3350+
export const $AgentSessionCancelResponse = {
3351+
properties: {
3352+
session_id: {
3353+
type: "string",
3354+
format: "uuid",
3355+
title: "Session Id",
3356+
},
3357+
run_id: {
3358+
type: "string",
3359+
format: "uuid",
3360+
title: "Run Id",
3361+
},
3362+
reason: {
3363+
$ref: "#/components/schemas/AgentCancelReason",
3364+
},
3365+
turn_status: {
3366+
$ref: "#/components/schemas/AgentSessionStatus",
3367+
},
3368+
},
3369+
type: "object",
3370+
required: ["session_id", "run_id", "reason", "turn_status"],
3371+
title: "AgentSessionCancelResponse",
3372+
description:
3373+
"Response schema for an accepted agent session cancellation request.",
3374+
} as const
3375+
33323376
export const $AgentSessionCreate = {
33333377
properties: {
33343378
id: {
@@ -3593,6 +3637,10 @@ export const $AgentSessionRead = {
35933637
],
35943638
title: "Last Stream Id",
35953639
},
3640+
turn_status: {
3641+
$ref: "#/components/schemas/AgentSessionStatus",
3642+
default: "idle",
3643+
},
35963644
parent_session_id: {
35973645
anyOf: [
35983646
{
@@ -3755,6 +3803,10 @@ export const $AgentSessionReadVercel = {
37553803
],
37563804
title: "Last Stream Id",
37573805
},
3806+
turn_status: {
3807+
$ref: "#/components/schemas/AgentSessionStatus",
3808+
default: "idle",
3809+
},
37583810
parent_session_id: {
37593811
anyOf: [
37603812
{
@@ -3925,6 +3977,10 @@ export const $AgentSessionReadWithMessages = {
39253977
],
39263978
title: "Last Stream Id",
39273979
},
3980+
turn_status: {
3981+
$ref: "#/components/schemas/AgentSessionStatus",
3982+
default: "idle",
3983+
},
39283984
parent_session_id: {
39293985
anyOf: [
39303986
{
@@ -3974,6 +4030,13 @@ export const $AgentSessionReadWithMessages = {
39744030
description: "Response schema for agent session with message history.",
39754031
} as const
39764032

4033+
export const $AgentSessionStatus = {
4034+
type: "string",
4035+
enum: ["idle", "running", "waiting_for_approval", "stopped", "failed"],
4036+
title: "AgentSessionStatus",
4037+
description: "Lifecycle state for an agent session turn.",
4038+
} as const
4039+
39774040
export const $AgentSessionUpdate = {
39784041
properties: {
39794042
title: {
@@ -8911,6 +8974,20 @@ export const $ChatMessage = {
89118974
description:
89128975
"Compaction status data for badge rendering (for kind=COMPACTION)",
89138976
},
8977+
interrupt: {
8978+
anyOf: [
8979+
{
8980+
additionalProperties: true,
8981+
type: "object",
8982+
},
8983+
{
8984+
type: "null",
8985+
},
8986+
],
8987+
title: "Interrupt",
8988+
description:
8989+
"Interruption status data for badge rendering (for kind=INTERRUPT)",
8990+
},
89148991
},
89158992
type: "object",
89168993
required: ["id"],
@@ -8920,7 +8997,8 @@ export const $ChatMessage = {
89208997
This model supports multiple message kinds:
89218998
- kind=CHAT_MESSAGE: Contains message field with user/assistant content
89228999
- kind=APPROVAL_REQUEST/APPROVAL_DECISION: Contains approval field with approval data
8923-
- kind=COMPACTION: Contains compaction field with compaction status data`,
9000+
- kind=COMPACTION: Contains compaction field with compaction status data
9001+
- kind=INTERRUPT: Contains interrupt field with interruption status data`,
89249002
} as const
89259003

89269004
export const $ChatRead = {
@@ -15249,6 +15327,7 @@ export const $MessageKind = {
1524915327
"approval-decision",
1525015328
"internal",
1525115329
"compaction",
15330+
"interrupt",
1525215331
],
1525315332
title: "MessageKind",
1525415333
description: "The type/kind of message stored in the chat.",

frontend/src/client/services.gen.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ import type {
161161
AgentPresetsRestoreAgentPresetVersionResponse,
162162
AgentPresetsUpdateAgentPresetData,
163163
AgentPresetsUpdateAgentPresetResponse,
164+
AgentSessionsCancelSessionData,
165+
AgentSessionsCancelSessionResponse,
164166
AgentSessionsCreateSessionData,
165167
AgentSessionsCreateSessionResponse,
166168
AgentSessionsDeleteSessionData,
@@ -6611,6 +6613,34 @@ export const agentSessionsGetSessionVercel = (
66116613
})
66126614
}
66136615

6616+
/**
6617+
* Cancel Session
6618+
* Request graceful cancellation for the active agent session turn.
6619+
* @param data The data for the request.
6620+
* @param data.sessionId
6621+
* @param data.workspaceId
6622+
* @param data.requestBody
6623+
* @returns AgentSessionCancelResponse Successful Response
6624+
* @throws ApiError
6625+
*/
6626+
export const agentSessionsCancelSession = (
6627+
data: AgentSessionsCancelSessionData
6628+
): CancelablePromise<AgentSessionsCancelSessionResponse> => {
6629+
return __request(OpenAPI, {
6630+
method: "POST",
6631+
url: "/workspaces/{workspace_id}/agent/sessions/{session_id}/cancel",
6632+
path: {
6633+
session_id: data.sessionId,
6634+
workspace_id: data.workspaceId,
6635+
},
6636+
body: data.requestBody,
6637+
mediaType: "application/json",
6638+
errors: {
6639+
422: "Validation Error",
6640+
},
6641+
})
6642+
}
6643+
66146644
/**
66156645
* Send Message
66166646
* Send a message to the agent session with streaming response.

frontend/src/client/types.gen.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ export type AdminUserRead = {
319319
last_login_at?: string | null
320320
}
321321

322+
export type AgentCancelReason = "user_cancel" | "worker_drain"
323+
322324
/**
323325
* List catalog entries with pagination.
324326
*/
@@ -766,6 +768,26 @@ export type AgentPresetVersionReadMinimal = {
766768
updated_at: string
767769
}
768770

771+
/**
772+
* Request schema for cancelling an active agent session turn.
773+
*/
774+
export type AgentSessionCancelRequest = {
775+
/**
776+
* Reason for requesting cancellation.
777+
*/
778+
reason?: AgentCancelReason
779+
}
780+
781+
/**
782+
* Response schema for an accepted agent session cancellation request.
783+
*/
784+
export type AgentSessionCancelResponse = {
785+
session_id: string
786+
run_id: string
787+
reason: AgentCancelReason
788+
turn_status: AgentSessionStatus
789+
}
790+
769791
/**
770792
* Request schema for creating an agent session.
771793
*/
@@ -858,6 +880,7 @@ export type AgentSessionRead = {
858880
agents_binding?: ResolvedAgentsConfig | null
859881
harness_type: string | null
860882
last_stream_id?: string | null
883+
turn_status?: AgentSessionStatus
861884
parent_session_id?: string | null
862885
created_at: string
863886
updated_at: string
@@ -882,6 +905,7 @@ export type AgentSessionReadVercel = {
882905
agents_binding?: ResolvedAgentsConfig | null
883906
harness_type: string | null
884907
last_stream_id?: string | null
908+
turn_status?: AgentSessionStatus
885909
parent_session_id?: string | null
886910
created_at: string
887911
updated_at: string
@@ -910,6 +934,7 @@ export type AgentSessionReadWithMessages = {
910934
agents_binding?: ResolvedAgentsConfig | null
911935
harness_type: string | null
912936
last_stream_id?: string | null
937+
turn_status?: AgentSessionStatus
913938
parent_session_id?: string | null
914939
created_at: string
915940
updated_at: string
@@ -919,6 +944,16 @@ export type AgentSessionReadWithMessages = {
919944
messages?: Array<unknown>
920945
}
921946

947+
/**
948+
* Lifecycle state for an agent session turn.
949+
*/
950+
export type AgentSessionStatus =
951+
| "idle"
952+
| "running"
953+
| "waiting_for_approval"
954+
| "stopped"
955+
| "failed"
956+
922957
/**
923958
* Request schema for updating an agent session.
924959
*/
@@ -2343,6 +2378,7 @@ export type ChannelType = "slack"
23432378
* - kind=CHAT_MESSAGE: Contains message field with user/assistant content
23442379
* - kind=APPROVAL_REQUEST/APPROVAL_DECISION: Contains approval field with approval data
23452380
* - kind=COMPACTION: Contains compaction field with compaction status data
2381+
* - kind=INTERRUPT: Contains interrupt field with interruption status data
23462382
*/
23472383
export type ChatMessage = {
23482384
/**
@@ -2375,6 +2411,12 @@ export type ChatMessage = {
23752411
compaction?: {
23762412
[key: string]: unknown
23772413
} | null
2414+
/**
2415+
* Interruption status data for badge rendering (for kind=INTERRUPT)
2416+
*/
2417+
interrupt?: {
2418+
[key: string]: unknown
2419+
} | null
23782420
}
23792421

23802422
/**
@@ -4693,6 +4735,7 @@ export type MessageKind =
46934735
| "approval-decision"
46944736
| "internal"
46954737
| "compaction"
4738+
| "interrupt"
46964739

46974740
export type ModelConfig = {
46984741
/**
@@ -10738,6 +10781,14 @@ export type AgentSessionsGetSessionVercelResponse =
1073810781
| AgentSessionReadVercel
1073910782
| ChatReadVercel
1074010783

10784+
export type AgentSessionsCancelSessionData = {
10785+
requestBody?: AgentSessionCancelRequest | null
10786+
sessionId: string
10787+
workspaceId: string
10788+
}
10789+
10790+
export type AgentSessionsCancelSessionResponse = AgentSessionCancelResponse
10791+
1074110792
export type AgentSessionsSendMessageData = {
1074210793
requestBody: VercelChatRequest | ContinueRunRequest
1074310794
sessionId: string
@@ -15725,6 +15776,21 @@ export type $OpenApiTs = {
1572515776
}
1572615777
}
1572715778
}
15779+
"/workspaces/{workspace_id}/agent/sessions/{session_id}/cancel": {
15780+
post: {
15781+
req: AgentSessionsCancelSessionData
15782+
res: {
15783+
/**
15784+
* Successful Response
15785+
*/
15786+
200: AgentSessionCancelResponse
15787+
/**
15788+
* Validation Error
15789+
*/
15790+
422: HTTPValidationError
15791+
}
15792+
}
15793+
}
1572815794
"/workspaces/{workspace_id}/agent/sessions/{session_id}/messages": {
1572915795
post: {
1573015796
req: AgentSessionsSendMessageData

0 commit comments

Comments
 (0)