Implementation:Microsoft Autogen Studio Datamodel Pydantic Types
| Sources | python/packages/autogen-studio/autogenstudio/datamodel/types.py |
|---|---|
| Domains | Data_Modeling, Configuration, UI, Agent_Systems |
| Last Updated | 2026-02-11 |
Overview
Description
The Studio Datamodel Pydantic Types module provides comprehensive Pydantic models that define the data structures used throughout AutoGen Studio's UI, messaging, configuration, and component management systems. This module encompasses models for chat messaging, team results, gallery components, environment settings, and API communication.
The module includes several categories of models:
- Messaging Models - MessageConfig, LLMCallEventMessage, MessageMeta for chat and agent communication
- Result Models - TeamResult for capturing agent team execution outcomes
- Gallery Models - GalleryMetadata, GalleryComponents, GalleryConfig for component library management
- Configuration Models - EnvironmentVariable, UISettings, SettingsConfig for application configuration
- API Models - Response, SocketMessage for HTTP and WebSocket communication
Usage
These types are used throughout AutoGen Studio to ensure type safety, validation, and consistent serialization/deserialization of data structures. The models support the UI layer, backend API, configuration management, and component gallery features. They leverage Pydantic's validation capabilities and provide JSON encoding rules for complex types like datetime and SecretStr.
Code Reference
Source Location
python/packages/autogen-studio/autogenstudio/datamodel/types.py
Signature
# Messaging Models
class MessageConfig(BaseModel):
source: str
content: str | ChatMessage | Sequence[ChatMessage] | None
message_type: Optional[str] = "text"
class LLMCallEventMessage(TextMessage):
source: str = "llm_call_event"
def to_text(self) -> str
def to_model_text(self) -> str
def to_model_message(self) -> UserMessage
class MessageMeta(BaseModel):
task: Optional[str] = None
task_result: Optional[TaskResult] = None
summary_method: Optional[str] = "last"
files: Optional[List[dict]] = None
time: Optional[datetime] = None
log: Optional[List[dict]] = None
usage: Optional[List[dict]] = None
# Team Results
class TeamResult(BaseModel):
task_result: TaskResult
usage: str
duration: float
# Gallery Models
class GalleryMetadata(BaseModel):
author: str
version: str
description: Optional[str] = None
tags: Optional[List[str]] = None
license: Optional[str] = None
homepage: Optional[str] = None
category: Optional[str] = None
last_synced: Optional[datetime] = None
class GalleryComponents(BaseModel):
agents: List[ComponentModel]
models: List[ComponentModel]
tools: List[ComponentModel]
terminations: List[ComponentModel]
teams: List[ComponentModel]
workbenches: List[ComponentModel]
class GalleryConfig(BaseModel):
id: str
name: str
url: Optional[str] = None
metadata: GalleryMetadata
components: GalleryComponents
# Configuration Models
class EnvironmentVariable(BaseModel):
name: str
value: str
type: Literal["string", "number", "boolean", "secret"] = "string"
description: Optional[str] = None
required: bool = False
class UISettings(BaseModel):
show_llm_call_events: bool = False
expanded_messages_by_default: bool = True
show_agent_flow_by_default: bool = True
human_input_timeout_minutes: int = Field(
default=3, ge=1, le=30, description="Human input timeout in minutes (1-30)"
)
class SettingsConfig(BaseModel):
environment: List[EnvironmentVariable] = []
default_model_client: Optional[ComponentModel] = OpenAIChatCompletionClient(
model="gpt-4o-mini", api_key="your-api-key"
).dump_component()
ui: UISettings = UISettings()
# API Models
class Response(BaseModel):
message: str
status: bool
data: Optional[Any] = None
class SocketMessage(BaseModel):
connection_id: str
data: Dict[str, Any]
type: str
Import
from autogenstudio.datamodel.types import (
MessageConfig,
TeamResult,
LLMCallEventMessage,
MessageMeta,
GalleryMetadata,
GalleryComponents,
GalleryConfig,
EnvironmentVariable,
UISettings,
SettingsConfig,
Response,
SocketMessage
)
I/O Contract
Inputs
| Model | Field | Type | Description |
|---|---|---|---|
| MessageConfig | source | str | Source identifier for the message |
| content | ChatMessage | Sequence[ChatMessage] | None | Message content in various formats | |
| message_type | Optional[str] | Type of message (default: "text") | |
| GalleryMetadata | author | str | Author of the gallery component |
| version | str | Version string of the component | |
| description | Optional[str] | Component description | |
| tags | Optional[List[str]] | Categorization tags | |
| license | Optional[str] | License information | |
| homepage | Optional[str] | Homepage URL | |
| category | Optional[str] | Component category | |
| EnvironmentVariable | name | str | Variable name |
| value | str | Variable value | |
| type | Literal["string", "number", "boolean", "secret"] | Variable type (default: "string") | |
| description | Optional[str] | Variable description | |
| required | bool | Whether the variable is required (default: False) | |
| UISettings | show_llm_call_events | bool | Whether to show LLM call events (default: False) |
| expanded_messages_by_default | bool | Whether messages are expanded by default (default: True) | |
| show_agent_flow_by_default | bool | Whether to show agent flow by default (default: True) | |
| human_input_timeout_minutes | int | Timeout for human input in minutes (1-30, default: 3) |
Outputs
| Model | Field | Type | Description |
|---|---|---|---|
| TeamResult | task_result | TaskResult | Result from the agent team execution |
| usage | str | Resource usage information | |
| duration | float | Execution duration in seconds | |
| GalleryConfig | id | str | Unique identifier for the gallery item |
| name | str | Display name for the gallery item | |
| url | Optional[str] | Source URL for the gallery item | |
| metadata | GalleryMetadata | Metadata about the gallery item | |
| components | GalleryComponents | Component definitions included in the gallery item | |
| Response | message | str | Response message text |
| status | bool | Success/failure status | |
| data | Optional[Any] | Optional response data payload | |
| SocketMessage | connection_id | str | WebSocket connection identifier |
| data | Dict[str, Any] | Message data payload | |
| type | str | Message type identifier |
Usage Examples
Working with Message Configuration
from autogenstudio.datamodel.types import MessageConfig
from autogen_agentchat.messages import TextMessage
# Simple text message
msg_config = MessageConfig(
source="user",
content="Hello, how can you help me?",
message_type="text"
)
# Using ChatMessage objects
chat_msg = TextMessage(source="assistant", content="I can help with various tasks!")
msg_config = MessageConfig(
source="assistant",
content=chat_msg,
message_type="chat"
)
Creating Gallery Components
from autogenstudio.datamodel.types import GalleryConfig, GalleryMetadata, GalleryComponents
from datetime import datetime
# Define metadata
metadata = GalleryMetadata(
author="AutoGen Team",
version="1.0.0",
description="A collection of useful agents and tools",
tags=["automation", "agents", "productivity"],
license="MIT",
homepage="https://github.com/microsoft/autogen",
category="productivity",
last_synced=datetime.now()
)
# Define components
components = GalleryComponents(
agents=[], # List of agent ComponentModels
models=[], # List of model ComponentModels
tools=[], # List of tool ComponentModels
terminations=[],
teams=[],
workbenches=[]
)
# Create gallery config
gallery = GalleryConfig(
id="my-gallery-001",
name="My AutoGen Gallery",
url="https://example.com/gallery",
metadata=metadata,
components=components
)
Managing Environment Variables
from autogenstudio.datamodel.types import EnvironmentVariable, SettingsConfig
# Define environment variables
env_vars = [
EnvironmentVariable(
name="OPENAI_API_KEY",
value="sk-...",
type="secret",
description="OpenAI API key for model access",
required=True
),
EnvironmentVariable(
name="MAX_RETRIES",
value="3",
type="number",
description="Maximum number of retry attempts",
required=False
),
EnvironmentVariable(
name="DEBUG_MODE",
value="false",
type="boolean",
description="Enable debug logging",
required=False
)
]
# Create settings with environment variables
settings = SettingsConfig(environment=env_vars)
Configuring UI Settings
from autogenstudio.datamodel.types import UISettings, SettingsConfig
# Customize UI behavior
ui_settings = UISettings(
show_llm_call_events=True,
expanded_messages_by_default=False,
show_agent_flow_by_default=True,
human_input_timeout_minutes=5
)
# Apply to settings
settings = SettingsConfig(ui=ui_settings)
Working with API Responses
from autogenstudio.datamodel.types import Response, SocketMessage
# HTTP API response
api_response = Response(
message="Task completed successfully",
status=True,
data={
"task_id": "task-123",
"result": "Paris",
"duration": 1.23
}
)
# WebSocket message
ws_message = SocketMessage(
connection_id="conn-abc-123",
data={
"event": "agent_message",
"content": "Processing your request...",
"timestamp": "2026-02-11T10:30:00"
},
type="status_update"
)
Working with Team Results
from autogenstudio.datamodel.types import TeamResult
from autogen_agentchat.base import TaskResult
# Capture team execution result
team_result = TeamResult(
task_result=task_result, # TaskResult from team execution
usage="1234 tokens",
duration=5.67
)
# Access result details
print(f"Task completed in {team_result.duration} seconds")
print(f"Token usage: {team_result.usage}")
Using LLMCallEventMessage
from autogenstudio.datamodel.types import LLMCallEventMessage
# Create LLM call event message
llm_event = LLMCallEventMessage(
content="Calling OpenAI GPT-4 with prompt: 'What is the capital of France?'"
)
# Convert to text for display
event_text = llm_event.to_text()
print(f"Event: {event_text}")
Related Pages
- Studio Eval Datamodel - Evaluation-specific data models
- Studio Eval Judges - Uses TeamResult and MessageConfig
- Studio Eval Runners - Produces TeamResult objects
- Data Modeling Domain - All data structure implementations
- Configuration Domain - Configuration-related implementations
- UI Domain - User interface components and models