diff --git a/litellm/proxy/schema.prisma b/litellm/proxy/schema.prisma index 84ce99557e3..6a2e09e1616 100644 --- a/litellm/proxy/schema.prisma +++ b/litellm/proxy/schema.prisma @@ -1374,3 +1374,97 @@ model LiteLLM_WorkflowMessage { @@unique([run_id, sequence_number]) @@index([run_id]) } + + +// =========================================================================== +// Agent Sessions / Runs (Cursor SDK on LiteLLM) +// +// Three-level hierarchy: +// Agent — definition (model, system prompt, default repos, tools) +// Session — VM-backed conversation, owned by an Agent +// Run — single turn within a Session +// RunEvent — append-only event log per run (for resumable SSE) +// =========================================================================== + +model LiteLLM_Agent { + id String @id // "agent_" + name String + user_api_key_hash String + team_id String? + model String + system_prompt String? + default_repos Json? + default_env_vars Json? + tools_config Json? + metadata Json? + created_at DateTime @default(now()) + updated_at DateTime @updatedAt + + sessions LiteLLM_AgentSession[] + + @@index([user_api_key_hash]) + @@index([team_id]) +} + +model LiteLLM_AgentSession { + id String @id // "sess_" + agent_id String + user_api_key_hash String + team_id String? + vm_id String? + vm_provider String? + repos Json + env_vars Json? + status String @default("provisioning") + daemon_token_hash String? + expires_at DateTime + last_heartbeat_at DateTime? + idempotency_key String? + created_at DateTime @default(now()) + updated_at DateTime @updatedAt + terminated_at DateTime? + + agent LiteLLM_Agent @relation(fields: [agent_id], references: [id], onDelete: Cascade) + runs LiteLLM_AgentRun[] + + @@unique([user_api_key_hash, idempotency_key]) + @@index([agent_id]) + @@index([status, expires_at]) + @@index([user_api_key_hash]) +} + +model LiteLLM_AgentRun { + id String @id // "run_" + session_id String + parent_run_id String? + status String @default("queued") + prompt Json + result String? + git_branches Json? + idempotency_key String? + created_at DateTime @default(now()) + updated_at DateTime @updatedAt + started_at DateTime? + terminated_at DateTime? + + session LiteLLM_AgentSession @relation(fields: [session_id], references: [id], onDelete: Cascade) + events LiteLLM_AgentRunEvent[] + + @@unique([session_id, idempotency_key]) + @@index([session_id, status]) + @@index([session_id, created_at]) +} + +model LiteLLM_AgentRunEvent { + id String @id @default(uuid()) + run_id String + seq Int + event_type String + payload Json + created_at DateTime @default(now()) + + run LiteLLM_AgentRun @relation(fields: [run_id], references: [id], onDelete: Cascade) + + @@unique([run_id, seq]) + @@index([run_id, seq]) +}