Models
TL;DR
The Model class selects AI model tiers for /agent commands β from Model.cheap()
to Model.premium() with optional vision and code capabilities. Data models include
Pydantic-based User, Message, Command, and Permission classes. Exception hierarchy
provides IntegrationError, ChannelError, PermissionDeniedError, and RateLimitError
with error codes and suggestions.
What AI model tiers are available?
Choose AI model tier for /agent commands. Models are resolved server-side by SDKRouter β the actual LLM is selected dynamically.
from cmdop_bot import Model
# Available tiers (cheapest to most capable)
# Each tier returns a model string that SDKRouter resolves to an actual LLM
Model.cheap() # "@cheap+agents" β Most economical
Model.budget() # "@budget+agents" β Budget-friendly
Model.fast() # "@fast+agents" β Fastest response
Model.standard() # "@standard+agents" β Standard performance
Model.balanced() # "@balanced+agents" β Best value (default)
Model.smart() # "@smart+agents" β Highest quality
Model.premium() # "@premium+agents" β Premium tierHow do I add capabilities?
# Pass vision=True or code=True to enable extra capabilities on any tier
Model.smart(vision=True) # "@smart+agents+vision" β image understanding
Model.balanced(code=True) # "@balanced+agents+code" β code generation
Model.fast(vision=True, code=True) # "@fast+agents+vision+code" β both capabilitiesHow do I use models with bots?
from cmdop_bot import Model
from cmdop_bot.channels.telegram import TelegramBot
# Pass the model tier to the bot constructor via the model parameter
bot = TelegramBot(
token="...",
cmdop_api_key="...",
model=Model.cheap(), # Use cheapest model for all /agent commands
)What data models are available?
All models are Pydantic BaseModel instances.
User
from cmdop_bot.models import User
# Create a User with channel-specific ID and optional profile fields
user = User(
id="123456789",
channel="telegram",
username="john_doe",
display_name="John Doe",
is_admin=False, # Set to True for admin privileges
)
user.unique_id # "telegram:123456789" β combines channel + id
user.name # "John Doe" (best available: display_name > username > id)| Field | Type | Description |
|---|---|---|
id | str | User ID within the channel |
channel | str | "telegram", "discord", "slack" |
username | str | None | Username/handle |
display_name | str | None | Display name |
is_admin | bool | Admin privileges (default: False) |
Message
from cmdop_bot.models import Message, User
# Create a Message linking a User to their text input in a specific chat
msg = Message(
id="msg_123",
channel="telegram",
chat_id="456", # Chat/conversation ID
user=User(id="789", channel="telegram"), # Author of the message
text="/shell ls -la", # Raw message text
)| Field | Type | Description |
|---|---|---|
id | str | Message ID |
channel | str | Channel name |
chat_id | str | Chat/conversation ID |
user | User | Message author |
text | str | Message text |
reply_to | str | None | ID of message being replied to |
raw | Any | Raw platform event (excluded from serialization) |
Command
from cmdop_bot.models import Command
# Parse a slash-command string into a structured Command object
cmd = Command.parse("/shell ls -la")
# cmd.name = "shell" β command name without the "/" prefix
# cmd.args = ["ls", "-la"] β parsed argument list
# cmd.args_text = "ls -la" β arguments as a single string
# cmd.raw_text = "/shell ls -la" β original full text
# Returns None when the text is not a command (no "/" prefix)
cmd = Command.parse("just a message") # None| Field | Type | Description |
|---|---|---|
name | str | Command name without / prefix |
args | list[str] | Parsed arguments list |
raw_text | str | Original full message text |
message | Message | None | Source message |
Permission
from cmdop_bot.models import Permission, PermissionLevel
# Define a per-user, per-machine permission with an optional command whitelist
perm = Permission(
user_id="telegram:123456789",
machine="prod-server",
level=PermissionLevel.EXECUTE,
allowed_commands=["shell", "ls"], # Only these commands are permitted
denied_commands=None, # No explicit denials
)
perm.can_execute("shell") # True β in the allowed list
perm.can_execute("agent") # False β not in the allowed listPermissionLevel
from cmdop_bot.models import PermissionLevel
# Enum values β higher value means more access
PermissionLevel.NONE # 0 β no access
PermissionLevel.READ # 10 β view status and read files
PermissionLevel.EXECUTE # 20 β run shell commands
PermissionLevel.FILES # 30 β write and delete files
PermissionLevel.ADMIN # 100 β full unrestricted accessWhat exceptions are available?
# Top-level imports β common errors you'll catch in bot code
from cmdop_bot import (
IntegrationError, # Base class for all cmdop-bot errors
ChannelError, # Channel-specific error (Telegram, Discord, etc.)
PermissionDeniedError, # Raised when a user lacks required permissions
ConfigurationError, # Raised for invalid bot configuration
)
# Additional exceptions available from the exceptions module
from cmdop_bot.exceptions import (
RateLimitError, # Raised when API rate limit is exceeded
ConnectionError, # Raised when gRPC connection to agent fails
)| Exception | Error Code | Description |
|---|---|---|
IntegrationError | INTEGRATION_ERROR | Base class |
ChannelError | CHANNEL_ERROR_{CHANNEL} | Channel-specific |
PermissionDeniedError | PERMISSION_DENIED | Access denied |
ConfigurationError | CONFIGURATION_ERROR | Invalid config |
RateLimitError | RATE_LIMIT | Rate limit exceeded |
ConnectionError | CONNECTION_ERROR | Connection failed |
All exceptions have .message, .error_code, .suggestion, .details attributes.
Last updated on