from typing import Literal
from agency_swarm import MasterContext, RunContextWrapper, function_tool
from pydantic import BaseModel, EmailStr, Field
class RunCommandArgs(BaseModel):
command: Literal["start", "stop"] = Field(..., description="Command to execute: 'start' or 'stop'.")
@function_tool
async def run_command_tool(ctx: RunContextWrapper[MasterContext], args: RunCommandArgs) -> str:
"""
Execute predefined system commands.
"""
if args.command == "start":
# Start command logic
return "System started"
elif args.command == "stop":
# Stop command logic
return "System stopped"
else:
raise ValueError("Invalid command")
# Example with EmailStr
class EmailSenderArgs(BaseModel):
recipient: EmailStr = Field(..., description="Email recipient's address.")
subject: str = Field(..., description="Email subject")
body: str = Field(..., description="Email body")
@function_tool
async def email_sender_tool(ctx: RunContextWrapper[MasterContext], args: EmailSenderArgs) -> str:
"""
Send email to specified recipient.
"""
# Email sending logic here
return f"Email sent to {args.recipient}"