fix: override validation for group for agentfile import (#9248)

* override validation for group for agentfile import

* fix the rest of groupcreate

* add api changes
This commit is contained in:
Kian Jones
2026-02-03 11:11:58 -08:00
committed by Caren Thomas
parent 3fdf2b6c79
commit 025eeaa363
2 changed files with 198 additions and 26 deletions

View File

@@ -31940,6 +31940,50 @@
"required": ["manager_agent_id"], "required": ["manager_agent_id"],
"title": "DynamicManager" "title": "DynamicManager"
}, },
"DynamicManagerSchema": {
"properties": {
"manager_type": {
"type": "string",
"const": "dynamic",
"title": "Manager Type",
"description": "",
"default": "dynamic"
},
"manager_agent_id": {
"type": "string",
"title": "Manager Agent Id",
"description": ""
},
"termination_token": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Termination Token",
"description": "",
"default": "DONE!"
},
"max_turns": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"title": "Max Turns",
"description": ""
}
},
"type": "object",
"required": ["manager_agent_id"],
"title": "DynamicManagerSchema"
},
"DynamicManagerUpdate": { "DynamicManagerUpdate": {
"properties": { "properties": {
"manager_type": { "manager_type": {
@@ -33993,16 +34037,11 @@
"properties": { "properties": {
"agent_ids": { "agent_ids": {
"items": { "items": {
"type": "string", "type": "string"
"maxLength": 42,
"minLength": 42,
"pattern": "^agent-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",
"description": "The ID of the agent in the format 'agent-<uuid4>'",
"examples": ["agent-123e4567-e89b-42d3-8456-426614174000"]
}, },
"type": "array", "type": "array",
"title": "Agent Ids", "title": "Agent Ids",
"description": "" "description": "List of agent IDs in this group"
}, },
"description": { "description": {
"type": "string", "type": "string",
@@ -34015,16 +34054,16 @@
"$ref": "#/components/schemas/RoundRobinManager" "$ref": "#/components/schemas/RoundRobinManager"
}, },
{ {
"$ref": "#/components/schemas/SupervisorManager" "$ref": "#/components/schemas/SupervisorManagerSchema"
}, },
{ {
"$ref": "#/components/schemas/DynamicManager" "$ref": "#/components/schemas/DynamicManagerSchema"
}, },
{ {
"$ref": "#/components/schemas/SleeptimeManager" "$ref": "#/components/schemas/SleeptimeManagerSchema"
}, },
{ {
"$ref": "#/components/schemas/VoiceSleeptimeManager" "$ref": "#/components/schemas/VoiceSleeptimeManagerSchema"
} }
], ],
"title": "Manager Config", "title": "Manager Config",
@@ -34035,11 +34074,11 @@
"discriminator": { "discriminator": {
"propertyName": "manager_type", "propertyName": "manager_type",
"mapping": { "mapping": {
"dynamic": "#/components/schemas/DynamicManager", "dynamic": "#/components/schemas/DynamicManagerSchema",
"round_robin": "#/components/schemas/RoundRobinManager", "round_robin": "#/components/schemas/RoundRobinManager",
"sleeptime": "#/components/schemas/SleeptimeManager", "sleeptime": "#/components/schemas/SleeptimeManagerSchema",
"supervisor": "#/components/schemas/SupervisorManager", "supervisor": "#/components/schemas/SupervisorManagerSchema",
"voice_sleeptime": "#/components/schemas/VoiceSleeptimeManager" "voice_sleeptime": "#/components/schemas/VoiceSleeptimeManagerSchema"
} }
} }
}, },
@@ -34057,18 +34096,12 @@
}, },
"shared_block_ids": { "shared_block_ids": {
"items": { "items": {
"type": "string", "type": "string"
"maxLength": 42,
"minLength": 42,
"pattern": "^block-[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",
"description": "The ID of the block in the format 'block-<uuid4>'",
"examples": ["block-123e4567-e89b-42d3-8456-426614174000"]
}, },
"type": "array", "type": "array",
"title": "Shared Block Ids", "title": "Shared Block Ids",
"description": "", "description": "List of shared block IDs",
"default": [], "default": []
"deprecated": true
}, },
"hidden": { "hidden": {
"anyOf": [ "anyOf": [
@@ -41711,6 +41744,37 @@
"required": ["manager_agent_id"], "required": ["manager_agent_id"],
"title": "SleeptimeManager" "title": "SleeptimeManager"
}, },
"SleeptimeManagerSchema": {
"properties": {
"manager_type": {
"type": "string",
"const": "sleeptime",
"title": "Manager Type",
"description": "",
"default": "sleeptime"
},
"manager_agent_id": {
"type": "string",
"title": "Manager Agent Id",
"description": ""
},
"sleeptime_agent_frequency": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"title": "Sleeptime Agent Frequency",
"description": ""
}
},
"type": "object",
"required": ["manager_agent_id"],
"title": "SleeptimeManagerSchema"
},
"SleeptimeManagerUpdate": { "SleeptimeManagerUpdate": {
"properties": { "properties": {
"manager_type": { "manager_type": {
@@ -43054,6 +43118,25 @@
"required": ["manager_agent_id"], "required": ["manager_agent_id"],
"title": "SupervisorManager" "title": "SupervisorManager"
}, },
"SupervisorManagerSchema": {
"properties": {
"manager_type": {
"type": "string",
"const": "supervisor",
"title": "Manager Type",
"description": "",
"default": "supervisor"
},
"manager_agent_id": {
"type": "string",
"title": "Manager Agent Id",
"description": ""
}
},
"type": "object",
"required": ["manager_agent_id"],
"title": "SupervisorManagerSchema"
},
"SupervisorManagerUpdate": { "SupervisorManagerUpdate": {
"properties": { "properties": {
"manager_type": { "manager_type": {
@@ -46071,6 +46154,49 @@
"required": ["manager_agent_id"], "required": ["manager_agent_id"],
"title": "VoiceSleeptimeManager" "title": "VoiceSleeptimeManager"
}, },
"VoiceSleeptimeManagerSchema": {
"properties": {
"manager_type": {
"type": "string",
"const": "voice_sleeptime",
"title": "Manager Type",
"description": "",
"default": "voice_sleeptime"
},
"manager_agent_id": {
"type": "string",
"title": "Manager Agent Id",
"description": ""
},
"max_message_buffer_length": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"title": "Max Message Buffer Length",
"description": ""
},
"min_message_buffer_length": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"title": "Min Message Buffer Length",
"description": ""
}
},
"type": "object",
"required": ["manager_agent_id"],
"title": "VoiceSleeptimeManagerSchema"
},
"VoiceSleeptimeManagerUpdate": { "VoiceSleeptimeManagerUpdate": {
"properties": { "properties": {
"manager_type": { "manager_type": {

View File

@@ -1,5 +1,5 @@
from datetime import datetime from datetime import datetime
from typing import Any, Dict, List, Optional from typing import Annotated, Any, Dict, List, Literal, Optional, Union
from openai.types.chat.chat_completion_message_tool_call import ChatCompletionMessageToolCall as OpenAIToolCall from openai.types.chat.chat_completion_message_tool_call import ChatCompletionMessageToolCall as OpenAIToolCall
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
@@ -9,7 +9,13 @@ from letta.schemas.agent import AgentState, CreateAgent
from letta.schemas.block import Block, CreateBlock from letta.schemas.block import Block, CreateBlock
from letta.schemas.enums import MessageRole, PrimitiveType from letta.schemas.enums import MessageRole, PrimitiveType
from letta.schemas.file import FileAgent, FileAgentBase, FileMetadata, FileMetadataBase from letta.schemas.file import FileAgent, FileAgentBase, FileMetadata, FileMetadataBase
from letta.schemas.group import Group, GroupCreate from letta.schemas.group import (
Group,
GroupCreate,
ManagerConfig,
ManagerType,
RoundRobinManager,
)
from letta.schemas.letta_message import ApprovalReturn from letta.schemas.letta_message import ApprovalReturn
from letta.schemas.mcp import MCPServer from letta.schemas.mcp import MCPServer
from letta.schemas.message import Message, MessageCreate, ToolReturn from letta.schemas.message import Message, MessageCreate, ToolReturn
@@ -195,12 +201,52 @@ class AgentSchema(CreateAgent):
) )
# Agentfile-specific manager configs that use plain str instead of validated AgentId
# These allow importing agentfiles with simple IDs like "agent-0"
class SupervisorManagerSchema(ManagerConfig):
manager_type: Literal[ManagerType.supervisor] = Field(ManagerType.supervisor, description="")
manager_agent_id: str = Field(..., description="")
class DynamicManagerSchema(ManagerConfig):
manager_type: Literal[ManagerType.dynamic] = Field(ManagerType.dynamic, description="")
manager_agent_id: str = Field(..., description="")
termination_token: Optional[str] = Field("DONE!", description="")
max_turns: Optional[int] = Field(None, description="")
class SleeptimeManagerSchema(ManagerConfig):
manager_type: Literal[ManagerType.sleeptime] = Field(ManagerType.sleeptime, description="")
manager_agent_id: str = Field(..., description="")
sleeptime_agent_frequency: Optional[int] = Field(None, description="")
class VoiceSleeptimeManagerSchema(ManagerConfig):
manager_type: Literal[ManagerType.voice_sleeptime] = Field(ManagerType.voice_sleeptime, description="")
manager_agent_id: str = Field(..., description="")
max_message_buffer_length: Optional[int] = Field(None, description="")
min_message_buffer_length: Optional[int] = Field(None, description="")
ManagerConfigSchemaUnion = Annotated[
Union[RoundRobinManager, SupervisorManagerSchema, DynamicManagerSchema, SleeptimeManagerSchema, VoiceSleeptimeManagerSchema],
Field(discriminator="manager_type"),
]
class GroupSchema(GroupCreate): class GroupSchema(GroupCreate):
"""Group with human-readable ID for agent file""" """Group with human-readable ID for agent file"""
__id_prefix__ = PrimitiveType.GROUP.value __id_prefix__ = PrimitiveType.GROUP.value
id: str = Field(..., description="Human-readable identifier for this group in the file") id: str = Field(..., description="Human-readable identifier for this group in the file")
# Override validated ID fields from GroupCreate to accept simple IDs like "agent-0"
agent_ids: List[str] = Field(..., description="List of agent IDs in this group")
shared_block_ids: List[str] = Field([], description="List of shared block IDs")
manager_config: ManagerConfigSchemaUnion = Field(RoundRobinManager(), description="")
@classmethod @classmethod
def from_group(cls, group: Group) -> "GroupSchema": def from_group(cls, group: Group) -> "GroupSchema":
"""Convert Group to GroupSchema""" """Convert Group to GroupSchema"""