Types - Data Structures
Overview
The Types component defines the core data structures and models used throughout the TKM AI Agency Platform. It provides standardized types for message handling, agent responses, and state management using Pydantic models and enums.
Directory Structure
Backend/Core_Components/
└── types.py # Core type definitions
Main Components
Enums
Core enumeration types:
- BlockingState
- MessageType
- Response states
- Message formats
Data Models
Pydantic models for:
- Agent responses
- Folder structures
- Request formats
- Response formats
Type Definitions
-
State Management
- Blocking states
- Process states
- Error states
- Response states
-
Message Handling
- Message types
- Content formats
- Metadata structures
- Response formats
Data Structures
BlockingState Enum
class BlockingState(str, Enum):
ACTIVE = "ACTIVE"
WAITING_CONFIRMATION = "WAITING_CONFIRMATION"
WAITING_INPUT = "WAITING_INPUT"
DONE = "DONE"
FAILED = "FAILED"
ERROR = "ERROR"
WAITING = "WAITING"
MessageType Enum
class MessageType(str, Enum):
AUDIO = "audio"
TEXT = "text"
IMAGE = "image"
DOCUMENT = "document"
AgentResponse Model
class AgentResponse(BaseModel):
success: bool
message: str
source_agent: str
conversation_id: str
metadata: Dict[str, Any] = {}
tokens: Optional[int] = None
folder_structure: Optional[Dict[str, Any]] = None
FolderStructure Model
class FolderStructure(BaseModel):
folder_name: str
file_name: str
category: str
subcategory: Optional[str] = None
state: BlockingState = BlockingState.ACTIVE
confidence: float
Key Features
-
Type Safety
- Pydantic validation
- Type checking
- Default values
- Optional fields
-
State Management
- Process states
- Blocking states
- Error states
- Response states
-
Message Formats
- Content types
- Response formats
- Metadata structures
- Validation rules
Usage Examples
Agent Response
response = AgentResponse(
success=True,
message="Operation completed",
source_agent="prometheus",
conversation_id="conv_123",
metadata={"process_time": "0.5s"}
)
Folder Structure
structure = FolderStructure(
folder_name="documents",
file_name="report.pdf",
category="reports",
subcategory="financial",
state=BlockingState.ACTIVE,
confidence=0.95
)
Integration
Model Usage
- Request validation
- Response formatting
- State tracking
- Error handling
Type Applications
- Data validation
- State management
- Message processing
- Response handling
Error Handling
-
Validation Errors
- Type mismatches
- Missing fields
- Invalid states
- Format errors
-
State Errors
- Invalid transitions
- Undefined states
- State conflicts
- Recovery handling
Best Practices
-
Type Usage
- Always use type hints
- Validate inputs
- Handle optionals
- Check states
-
Model Validation
- Use Pydantic models
- Define constraints
- Handle defaults
- Document fields