Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions alembic/versions/e1a2b3c4d5f6_add_agent_session_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""add_agent_session_status

Revision ID: e1a2b3c4d5f6
Revises: a3d7c9e8b4f2
Create Date: 2026-05-26 00:00:00.000000

"""

from collections.abc import Sequence

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "e1a2b3c4d5f6"
down_revision: str | None = "a3d7c9e8b4f2"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
op.add_column(
"agent_session",
sa.Column(
"status",
sa.String(length=32),
server_default="idle",
nullable=False,
),
)
op.create_index(
op.f("ix_agent_session_status"),
"agent_session",
["status"],
unique=False,
)


def downgrade() -> None:
op.drop_index(op.f("ix_agent_session_status"), table_name="agent_session")
op.drop_column("agent_session", "status")
2 changes: 1 addition & 1 deletion deployments/k8s
Submodule k8s updated from d19d66 to d94b52
81 changes: 80 additions & 1 deletion frontend/src/client/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,11 @@ export const $AdminUserRead = {
description: "Admin view of a user.",
} as const

export const $AgentCancelReason = {
type: "string",
enum: ["user_cancel", "worker_drain"],
} as const

export const $AgentCatalogListResponse = {
properties: {
items: {
Expand Down Expand Up @@ -3329,6 +3334,45 @@ export const $AgentPresetVersionReadMinimal = {
description: "Metadata returned when listing immutable preset versions.",
} as const

export const $AgentSessionCancelRequest = {
properties: {
reason: {
$ref: "#/components/schemas/AgentCancelReason",
description: "Reason for requesting cancellation.",
default: "user_cancel",
},
},
type: "object",
title: "AgentSessionCancelRequest",
description: "Request schema for cancelling an active agent session turn.",
} as const

export const $AgentSessionCancelResponse = {
properties: {
session_id: {
type: "string",
format: "uuid",
title: "Session Id",
},
run_id: {
type: "string",
format: "uuid",
title: "Run Id",
},
reason: {
$ref: "#/components/schemas/AgentCancelReason",
},
turn_status: {
$ref: "#/components/schemas/AgentSessionStatus",
},
},
type: "object",
required: ["session_id", "run_id", "reason", "turn_status"],
title: "AgentSessionCancelResponse",
description:
"Response schema for an accepted agent session cancellation request.",
} as const

export const $AgentSessionCreate = {
properties: {
id: {
Expand Down Expand Up @@ -3593,6 +3637,10 @@ export const $AgentSessionRead = {
],
title: "Last Stream Id",
},
turn_status: {
$ref: "#/components/schemas/AgentSessionStatus",
default: "idle",
},
parent_session_id: {
anyOf: [
{
Expand Down Expand Up @@ -3755,6 +3803,10 @@ export const $AgentSessionReadVercel = {
],
title: "Last Stream Id",
},
turn_status: {
$ref: "#/components/schemas/AgentSessionStatus",
default: "idle",
},
parent_session_id: {
anyOf: [
{
Expand Down Expand Up @@ -3925,6 +3977,10 @@ export const $AgentSessionReadWithMessages = {
],
title: "Last Stream Id",
},
turn_status: {
$ref: "#/components/schemas/AgentSessionStatus",
default: "idle",
},
parent_session_id: {
anyOf: [
{
Expand Down Expand Up @@ -3974,6 +4030,13 @@ export const $AgentSessionReadWithMessages = {
description: "Response schema for agent session with message history.",
} as const

export const $AgentSessionStatus = {
type: "string",
enum: ["idle", "running", "waiting_for_approval", "stopped", "failed"],
title: "AgentSessionStatus",
description: "Lifecycle state for an agent session turn.",
} as const

export const $AgentSessionUpdate = {
properties: {
title: {
Expand Down Expand Up @@ -8911,6 +8974,20 @@ export const $ChatMessage = {
description:
"Compaction status data for badge rendering (for kind=COMPACTION)",
},
interrupt: {
anyOf: [
{
additionalProperties: true,
type: "object",
},
{
type: "null",
},
],
title: "Interrupt",
description:
"Interruption status data for badge rendering (for kind=INTERRUPT)",
},
},
type: "object",
required: ["id"],
Expand All @@ -8920,7 +8997,8 @@ export const $ChatMessage = {
This model supports multiple message kinds:
- kind=CHAT_MESSAGE: Contains message field with user/assistant content
- kind=APPROVAL_REQUEST/APPROVAL_DECISION: Contains approval field with approval data
- kind=COMPACTION: Contains compaction field with compaction status data`,
- kind=COMPACTION: Contains compaction field with compaction status data
- kind=INTERRUPT: Contains interrupt field with interruption status data`,
} as const

export const $ChatRead = {
Expand Down Expand Up @@ -15249,6 +15327,7 @@ export const $MessageKind = {
"approval-decision",
"internal",
"compaction",
"interrupt",
],
title: "MessageKind",
description: "The type/kind of message stored in the chat.",
Expand Down
30 changes: 30 additions & 0 deletions frontend/src/client/services.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ import type {
AgentPresetsRestoreAgentPresetVersionResponse,
AgentPresetsUpdateAgentPresetData,
AgentPresetsUpdateAgentPresetResponse,
AgentSessionsCancelSessionData,
AgentSessionsCancelSessionResponse,
AgentSessionsCreateSessionData,
AgentSessionsCreateSessionResponse,
AgentSessionsDeleteSessionData,
Expand Down Expand Up @@ -6611,6 +6613,34 @@ export const agentSessionsGetSessionVercel = (
})
}

/**
* Cancel Session
* Request graceful cancellation for the active agent session turn.
* @param data The data for the request.
* @param data.sessionId
* @param data.workspaceId
* @param data.requestBody
* @returns AgentSessionCancelResponse Successful Response
* @throws ApiError
*/
export const agentSessionsCancelSession = (
data: AgentSessionsCancelSessionData
): CancelablePromise<AgentSessionsCancelSessionResponse> => {
return __request(OpenAPI, {
method: "POST",
url: "/workspaces/{workspace_id}/agent/sessions/{session_id}/cancel",
path: {
session_id: data.sessionId,
workspace_id: data.workspaceId,
},
body: data.requestBody,
mediaType: "application/json",
errors: {
422: "Validation Error",
},
})
}

/**
* Send Message
* Send a message to the agent session with streaming response.
Expand Down
66 changes: 66 additions & 0 deletions frontend/src/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ export type AdminUserRead = {
last_login_at?: string | null
}

export type AgentCancelReason = "user_cancel" | "worker_drain"

/**
* List catalog entries with pagination.
*/
Expand Down Expand Up @@ -766,6 +768,26 @@ export type AgentPresetVersionReadMinimal = {
updated_at: string
}

/**
* Request schema for cancelling an active agent session turn.
*/
export type AgentSessionCancelRequest = {
/**
* Reason for requesting cancellation.
*/
reason?: AgentCancelReason
}

/**
* Response schema for an accepted agent session cancellation request.
*/
export type AgentSessionCancelResponse = {
session_id: string
run_id: string
reason: AgentCancelReason
turn_status: AgentSessionStatus
}

/**
* Request schema for creating an agent session.
*/
Expand Down Expand Up @@ -858,6 +880,7 @@ export type AgentSessionRead = {
agents_binding?: ResolvedAgentsConfig | null
harness_type: string | null
last_stream_id?: string | null
turn_status?: AgentSessionStatus
parent_session_id?: string | null
created_at: string
updated_at: string
Expand All @@ -882,6 +905,7 @@ export type AgentSessionReadVercel = {
agents_binding?: ResolvedAgentsConfig | null
harness_type: string | null
last_stream_id?: string | null
turn_status?: AgentSessionStatus
parent_session_id?: string | null
created_at: string
updated_at: string
Expand Down Expand Up @@ -910,6 +934,7 @@ export type AgentSessionReadWithMessages = {
agents_binding?: ResolvedAgentsConfig | null
harness_type: string | null
last_stream_id?: string | null
turn_status?: AgentSessionStatus
parent_session_id?: string | null
created_at: string
updated_at: string
Expand All @@ -919,6 +944,16 @@ export type AgentSessionReadWithMessages = {
messages?: Array<unknown>
}

/**
* Lifecycle state for an agent session turn.
*/
export type AgentSessionStatus =
| "idle"
| "running"
| "waiting_for_approval"
| "stopped"
| "failed"

/**
* Request schema for updating an agent session.
*/
Expand Down Expand Up @@ -2343,6 +2378,7 @@ export type ChannelType = "slack"
* - kind=CHAT_MESSAGE: Contains message field with user/assistant content
* - kind=APPROVAL_REQUEST/APPROVAL_DECISION: Contains approval field with approval data
* - kind=COMPACTION: Contains compaction field with compaction status data
* - kind=INTERRUPT: Contains interrupt field with interruption status data
*/
export type ChatMessage = {
/**
Expand Down Expand Up @@ -2375,6 +2411,12 @@ export type ChatMessage = {
compaction?: {
[key: string]: unknown
} | null
/**
* Interruption status data for badge rendering (for kind=INTERRUPT)
*/
interrupt?: {
[key: string]: unknown
} | null
}

/**
Expand Down Expand Up @@ -4693,6 +4735,7 @@ export type MessageKind =
| "approval-decision"
| "internal"
| "compaction"
| "interrupt"

export type ModelConfig = {
/**
Expand Down Expand Up @@ -10738,6 +10781,14 @@ export type AgentSessionsGetSessionVercelResponse =
| AgentSessionReadVercel
| ChatReadVercel

export type AgentSessionsCancelSessionData = {
requestBody?: AgentSessionCancelRequest | null
sessionId: string
workspaceId: string
}

export type AgentSessionsCancelSessionResponse = AgentSessionCancelResponse

export type AgentSessionsSendMessageData = {
requestBody: VercelChatRequest | ContinueRunRequest
sessionId: string
Expand Down Expand Up @@ -15729,6 +15780,21 @@ export type $OpenApiTs = {
}
}
}
"/workspaces/{workspace_id}/agent/sessions/{session_id}/cancel": {
post: {
req: AgentSessionsCancelSessionData
res: {
/**
* Successful Response
*/
200: AgentSessionCancelResponse
/**
* Validation Error
*/
422: HTTPValidationError
}
}
}
"/workspaces/{workspace_id}/agent/sessions/{session_id}/messages": {
post: {
req: AgentSessionsSendMessageData
Expand Down
Loading