Apps are the building blocks of Meta Agents Research Environments simulations. They provide interactive functionality that agents can use as tools to accomplish tasks. This section documents the core App API and how to create custom applications.
fromare.simulation.apps.appimportAppfromare.simulation.tool_utilsimportapp_toolclassMyCustomApp(App):def__init__(self,name:str=None):super().__init__(name)# Initialize app-specific stateself.data={}@app_tooldefmy_action(self,param:str)->str:""" Perform a custom action. Args: param: Input parameter Returns: Result of the action """# Implement your logic hereresult=f"Processed: {param}"self.data[param]=resultreturnresultdefget_state(self)->dict:"""Return the current state of the app."""return{"data":self.data}defload_state(self,state:dict)->None:"""Load state into the app."""self.data=state.get("data",{})
Meta Agents Research Environments provides several decorators for registering methods as tools:
fromare.simulation.tool_utilsimportapp_tool,user_tool,env_tool,data_toolclassMyApp(App):@app_tool# Available to agents as a tooldefagent_action(self,param:str)->str:"""Available to agents as a tool."""pass@user_tool# Only available to the userdefuser_action(self,param:str)->str:"""Available for user interactions."""pass@env_tool# To be used for environment eventsdefenv_action(self,param:str)->str:"""Available for environment events."""pass@data_tool# To populate datadefdata_action(self,param:str)->str:"""Available for data operations."""pass
Apps can generate events that affect the simulation:
fromare.simulation.core.eventsimportEvent,ActionclassEventGeneratingApp(App):@app_tool@event_registered(operation_type=OperationType.WRITE)# Register the event as a write actiondefsend_message(self,message:str)->str:"""Action that sends a message."""self.elf._send_message(message,sender=self.name)
Apps can implement protocols to interact with other apps:
fromare.simulation.apps.appimportProtocolclassFileSystemApp(App):defget_implemented_protocols(self)->list[Protocol]:"""Declare which protocols this app implements."""return[Protocol.FILE_SYSTEM]@app_tooldefread_file(self,path:str)->str:"""Read a file from the file system."""# Implementation herepassclassDocumentApp(App):defconnect_to_protocols(self,protocols:dict[Protocol,Any])->None:"""Connect to other apps via protocols."""ifProtocol.FILE_SYSTEMinprotocols:self.file_system=protocols[Protocol.FILE_SYSTEM]@app_tooldefopen_document(self,path:str)->str:"""Open a document using the file system."""content=self.file_system.read_file(path)returnf"Opened document: {content}"
Convert the tool to OpenAI function calling format.
Example:
{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}
llm_formatter (Optional[Callable]) – a function to format the result of the tool before returning it to the LLM Agent,
THIS IS ONLY USED WHEN the function is called as a tool (i.e. from AppTool call), not when called as a normal function
attribute_name (ToolAttributeName) – the attribute name to set on the function as a ToolAttributeName enum value
Convert the tool to OpenAI function calling format.
Example:
{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather in a given location","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and state, e.g. San Francisco, CA"},"unit":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location"]}}}
An email client application that manages email operations and folder organization. This class provides comprehensive
functionality for handling emails including sending, receiving, organizing, and managing email attachments.
The app maintains emails in different folders (INBOX, SENT, DRAFT, TRASH) and provides various operations
for email manipulation and searching.
Key Features:
- Email Management: Send, reply, move, and delete emails
- Folder Organization: Maintains separate folders for different email categories
- Attachment Support: Handle email attachments (upload and download)
- Search Functionality: Search emails across folders with text-based queries
- State Management: Save and load application state
Key Components:
- Folders: Each EmailFolder instance (INBOX, SENT, DRAFT, TRASH) maintains its own collection of emails
- Email Validation: Validates email addresses using regex pattern matching
- View Limits: Configurable limit for email viewing and pagination
- Event Registration: All operations are tracked through event registration
Notes:
- Email IDs are automatically generated when creating new emails
- Attachments are handled using base64 encoding
- Search operations are case-insensitive
- All email operations maintain folder integrity
- Supports CC recipients and multiple attachments
Adds an email to the specified folder.
:type email: Email
:param email: The email to add.
:type folder_name: EmailFolderName
:param folder_name: The folder to add the email to.
Creates an email with the user as sole recipient and adds it to the user’s INBOX folder.
:type sender: str
:param sender: The sender of the email.
:type subject: str
:param subject: The subject of the email.
:type content: str
:param content: The content of the email.
:rtype: str
:returns: The id of the email just created.
Creates a reply to an email from the user and adds it to the user’s INBOX folder.
:type sender: str
:param sender: The sender of the email.
:type email_id: str
:param email_id: The id of the email to reply to, the Id is specified in the email details.
:type content: str
:param content: The content of the reply.
:type attachment_paths: Optional[list[str]]
:param attachment_paths: The paths of the attachments to add to the reply.
:rtype: str
:returns: The id of the email just created and sent.
Example:
reply_to_email_from_user(”other_user@meta.com”, “1234567890abcdef”, “Hello, this is a reply to your email.”)
Create and add an email to the specified folder.
:type sender: str
:param sender: The sender of the email.
:type recipients: Optional[list[str]]
:param recipients: The recipients of the email.
:type subject: str
:param subject: The subject of the email.
:type content: str
:param content: The content of the email.
:type folder_name: str
:param folder_name: The folder to add the email to. Can only be one of INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:rtype: str
:returns: The id of the email just created.
Create and add an email to the specified folder.
:type sender: str
:param sender: The sender of the email.
:type recipients: Optional[list[str]]
:param recipients: The recipients of the email.
:type subject: str
:param subject: The subject of the email.
:type content: str
:param content: The content of the email.
:type folder_name: str
:param folder_name: The folder to add the email to. Can only be one of INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:type email_time: str
:param email_time: The time of the email. Defaults to the current time.
:rtype: str
:returns: The id of the email just created.
Lists emails in the specified folder with a specified offset.
:type folder_name: str
:param folder_name: The folder to list emails from: INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:type offset: int
:param offset: The offset of the first email to return.
:type limit: int
:param limit: The maximum number of emails to return.
:rtype: ReturnedEmails
:returns: Emails with additional metadata about the range of emails retrieved and total number of emails
Reads an email from the specified folder, marking it as read.
:type email_id: str
:param email_id: The id of the email to read, the Id is specified in the email.
:type folder_name: str
:param folder_name: The folder to read the email from: INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:rtype: Email
:returns: Email details if successful, otherwise raise IndexError.
Reads an email from the specified folder, marking it as read.
:type idx: int
:param idx: The index of the email to read among the list of emails in the folder.
:type folder_name: str
:param folder_name: The folder to read the email from: INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:rtype: Email
:returns: Email details if successful, otherwise raise IndexError.
Sends an email to the specified recipients.
:type recipients: Optional[list[str]]
:param recipients: The recipients of the email.
:type subject: str
:param subject: The subject of the email.
:type content: str
:param content: The content of the email.
:type cc: Optional[list[str]]
:param cc: The cc of the email.
:type attachment_paths: Optional[list[str]]
:param attachment_paths: The paths of the attachments to add to the email.
:rtype: str
:returns: The id of the email just created.
Forwards an email to the specified recipients.
:type email_id: str
:param email_id: The id of the email to forward.
:type recipients: Optional[list[str]]
:param recipients: The recipients of the email.
:type folder_name: str
:param folder_name: The folder to forward the email from: INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:rtype: str
:returns: The id of the email just created and sent.
Downloads attachments from an email.
:type email_id: str
:param email_id: The id of the email to download.
:type folder_name: str
:param folder_name: The folder to download the email from: INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:type path_to_save: str
:param path_to_save: The path to save the attachments to.
:rtype: list[str]
:returns: The list of full path to the downloaded attachments.
Replies to an email.
:type email_id: str
:param email_id: The id of the email to reply to, the Id is specified in the email details.
:type folder_name: str
:param folder_name: The folder to reply to the email from: INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:type content: str
:param content: The content of the reply.
:type attachment_paths: Optional[list[str]]
:param attachment_paths: The paths of the attachments to add to the reply.
:rtype: str
:returns: The id of the email just created and sent.
Moves an email from one folder to another.
:type email_id: str
:param email_id: The id of the email to move.
:type source_folder_name: str
:param source_folder_name: The folder to move the email from: INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:type dest_folder_name: str
:param dest_folder_name: The folder to move the email to: INBOX, SENT, DRAFT, TRASH. Defaults to DRAFT.
:rtype: str
:returns: The id of the email just moved, if successful, otherwise raise ValueError.
Deletes an email from the specified folder.
:type email_id: str
:param email_id: The id of the email to delete.
:type folder_name: str
:param folder_name: The folder to delete the email from: INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:rtype: str
:returns: The id of the email just deleted, if successful, otherwise raise ValueError.
Searches for emails across all folders based on a query string.
The search looks for partial matches in sender, recipients, subject, and content.
:type query: str
:param query: The search query string
:type folder_name: str
:param folder_name: The folder to search in: INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:rtype: list[Email]
:returns: A list of emails that match the query.
An email client application that manages email operations and folder organization. This class provides comprehensive
functionality for handling emails including sending, receiving, organizing, and managing email attachments.
The app maintains emails in different folders (INBOX, SENT, DRAFT, TRASH) and provides various operations
for email manipulation and searching.
Key Features:
- Email Management: Send, reply, move, and delete emails
- Folder Organization: Maintains separate folders for different email categories
- Attachment Support: Handle email attachments (upload and download)
- Search Functionality: Search emails across folders with text-based queries
- State Management: Save and load application state
Key Components:
- Folders: Each EmailFolder instance (INBOX, SENT, DRAFT, TRASH) maintains its own collection of emails
- Email Validation: Validates email addresses using regex pattern matching
- View Limits: Configurable limit for email viewing and pagination
- Event Registration: All operations are tracked through event registration
Notes:
- Email IDs are automatically generated when creating new emails
- Attachments are handled using base64 encoding
- Search operations are case-insensitive
- All email operations maintain folder integrity
- Supports CC recipients and multiple attachments
Adds an attachment to an email.
:type email: Email
:param email: The email to add the attachment to.
:type attachment_path: str
:param attachment_path: The path to the attachment to add.
:param folder_name: The folder to add the attachment to: INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:rtype: None
:returns: None
Sends an email to the specified recipients.
:type recipients: Optional[list[str]]
:param recipients: The recipients of the email.
:type subject: str
:param subject: The subject of the email.
:type content: str
:param content: The content of the email.
:type cc: Optional[list[str]]
:param cc: The cc of the email.
:type attachment_paths: Optional[list[str]]
:param attachment_paths: The paths of the attachments to add to the email.
:rtype: str
:returns: The id of the email just created.
Downloads attachments from an email.
:type email_id: str
:param email_id: The id of the email to download.
:type folder_name: str
:param folder_name: The folder to download the email from: INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:type path_to_save: str
:param path_to_save: The path to save the attachments to.
:rtype: list[str]
:returns: The list of full path to the downloaded attachments.
Replies to an email.
:type email_id: str
:param email_id: The id of the email to reply to, the Id is specified in the email details.
:type folder_name: str
:param folder_name: The folder to reply to the email from: INBOX, SENT, DRAFT, TRASH. Defaults to INBOX.
:type content: str
:param content: The content of the reply.
:type attachment_paths: Optional[list[str]]
:param attachment_paths: The paths of the attachments to add to the reply.
:rtype: str
:returns: The id of the email just created and sent.
Creates a reply to an email from the user and adds it to the user’s INBOX folder.
:type sender: str
:param sender: The sender of the email.
:type email_id: str
:param email_id: The id of the email to reply to, the Id is specified in the email details.
:type content: str
:param content: The content of the reply.
:type attachment_paths: Optional[list[str]]
:param attachment_paths: The paths of the attachments to add to the reply.
:rtype: str
:returns: The id of the email just created and sent.
Example:
reply_to_email_from_user(”other_user@meta.com”, “1234567890abcdef”, “Hello, this is a reply to your email.”)
A messaging application that provides comprehensive functionality for managing conversations,
messages, and file attachments. This class implements a chat system with support for
individual and group conversations, message history, and file sharing capabilities.
The MessagingApp maintains conversations as a dictionary of Conversation objects, where each
conversation has unique identifiers, participants, messages, and metadata. The system supports
both text messages and file attachments with configurable view limits.
Key Features:
- Conversation Management: Create, list, and search conversations
- Messaging: Send text messages and file attachments
- Participant Management: Add/remove participants to conversations
- File Handling: Send and download file attachments
- Search Functionality: Search across conversations, participants, and messages
- View Limits: Configurable limits for messages and conversation listings
- State Management: Save and load application state
Conversation Features:
- Unique conversation IDs
- Optional conversation titles
- Participant management
- Message history with timestamps
- Last updated tracking
- File attachment support
Notes:
- The current user is automatically added as “Me” to all conversations
- Messages are sorted by timestamp, most recent first
- File attachments are handled using base64 encoding
- Search operations are case-insensitive
- Conversations maintain participant lists and message history
- All operations are tracked through event registration
- Messages can be paginated using offset and limit parameters
Create a new conversation with the given participants.
If title is not provided, it will be set to the participants.
:type participants: list[str]
:param participants: List of participants in the conversation, these are the full names of the contacts. The current user is “Me” and will be added automatically.
:type title: Optional[str]
:param title: Optional title for the conversation
:rtype: str
:returns: Id of the created conversation
Example:
create_conversation([“John Doe”, “Jane Doe”, “Bob Roberts”], “My group chat”)
List conversations ordered by the most recent modification, considering an offset and view limit.
e.g. list_recent_conversations(0, 5) will list the 5 most recent conversations.
:type offset: int
:param offset: The starting index from which to list conversations
:type limit: int
:param limit: The number of conversations to list, this number needs to be small otherwise an error will be raised
:type offset_recent_messages_per_conversation: int
:param offset_recent_messages_per_conversation: The starting index from which to list messages in each conversation
:type limit_recent_messages_per_conversation: int
:param limit_recent_messages_per_conversation: The number of messages to list in each conversation, this number needs to
:rtype: list[Conversation]
:returns: List of Conversation details
List all the conversations with the given participant.
:type participant: str
:param participant: Participant name in the conversation
:type offset: int
:param offset: The starting index from which to list conversations
:type limit: int
:param limit: The number of conversations to list, this number needs to be small otherwise an error will be raised
:type offset_recent_messages_per_conversation: int
:param offset_recent_messages_per_conversation: The starting index from which to list messages in each conversation
:type limit_recent_messages_per_conversation: int
:param limit_recent_messages_per_conversation: The number of messages to list in each conversation, this number needs to be small otherwise an error will be raised
:rtype: list[Conversation]
:returns: List of Conversation details
Send a message to the conversation with the given conversation_id.
:type conversation_id: str
:param conversation_id: Conversation id to send the message to
:type content: str
:param content: Message content
:rtype: str
:returns: Id of the sent message
Send an attachment to the conversation with the given conversation_id.
:type conversation_id: str
:param conversation_id: Conversation id
:type filepath: str
:param filepath: Path to the attachment to send
:rtype: str
:returns: Message id of the sent attachment
Download an attachment from the conversation with the given conversation_id.
:type conversation_id: str
:param conversation_id: Conversation id
:type message_id: str
:param message_id: Message id
:type download_path: str
:param download_path: Path to download the attachment to
:rtype: str
:returns: Full path to the downloaded attachment if successful, otherwise raise Exception
Send a message to the conversation with the given conversation_id.
:type conversation_id: str
:param conversation_id: Conversation id
:type content: str
:param content: Message content
:rtype: None
:returns: None
Send a message to the conversation with the given conversation_id.
:type conversation_id: str
:param conversation_id: Conversation id
:type sender: str
:param sender: Sender of the message. If the sender is the user, it should be “Me”
:type content: str
:param content: Message content
:rtype: str
:return: conversation id if successful, otherwise raise Exception.
Send a message to the conversation with the given conversation_id.
:type conversation_id: str
:param conversation_id: Conversation id
:type sender: str
:param sender: Sender of the message
:type content: str
:param content: Message content
:type message_time: str
:param message_time: Time of the message in YYYY-MM-DD HH:MM:SS format
:rtype: str
:return: conversation id if successful, otherwise raise Exception.
Read the conversation with the given conversation_id.
Shows the last ‘limit’ messages after offset. Which means messages between offset and offset + limit will be shown.
Messages are sorted by timestamp, most recent first.
:type conversation_id: str
:param conversation_id: Conversation id
:type offset: int
:param offset: Offset to shift the view window
:type limit: int
:param limit: Number of messages to show
:rtype: dict
:returns: Dict with messages and additional info
Add a participant to the conversation with the given conversation_id.
:type conversation_id: str
:param conversation_id: Conversation id to be updated
:type participant: str
:param participant: Full name of the participant to be added
:rtype: str
:returns: conversation_id of the conversation just updated, if successful, otherwise raise Exception.
Remove a participant from the conversation with the given conversation_id.
:type conversation_id: str
:param conversation_id: Conversation id
:type participant: str
:param participant: Full name of the participant to be removed
:rtype: str
:returns: conversation_id of the conversation just updated, if successful, otherwise raise Exception.
Search for conversations that match the given query.
The search is performed on conversation participants, titles, and message content.
Returns the Ids of the matching conversations.
:type query: str
:param query: The search query string
:type min_date: Optional[str]
:param min_date: Minimum date of the messages to be searched (YYYY-MM-DD %H:%M:%S format). Defaults to None (no minimum date).
:type max_date: Optional[str]
:param max_date: Maximum date of the messages to be searched (YYYY-MM-DD %H:%M:%S format). Defaults to None (no maximum date).
:rtype: list[str]
:returns: List of matching Conversation Ids
Search for conversations that match the given regex query (case insensitive).
The search is performed on conversation participants, titles, and message content.
Returns the Ids of the matching conversations.
:type query: str
:param query: The search query string
:type min_date: Optional[str]
:param min_date: Minimum date of the messages to be searched (YYYY-MM-DD %H:%M:%S format). Defaults to None (no minimum date).
:type max_date: Optional[str]
:param max_date: Maximum date of the messages to be searched (YYYY-MM-DD %H:%M:%S format). Defaults to None (no maximum date).
:rtype: list[str]
:returns: List of matching Conversation Ids
A messaging application that provides comprehensive functionality for managing conversations,
messages, and file attachments. This class implements a chat system with support for
individual and group conversations, message history, and file sharing capabilities.
The MessagingApp maintains conversations as a dictionary of Conversation objects, where each
conversation has unique identifiers, participants, messages, and metadata. The system supports
both text messages and file attachments with configurable view limits.
Key Features:
- Conversation Management: Create, list, and search conversations
- Messaging: Send text messages and file attachments
- Participant Management: Add/remove participants to conversations
- File Handling: Send and download file attachments
- Search Functionality: Search across conversations, participants, and messages
- View Limits: Configurable limits for messages and conversation listings
- State Management: Save and load application state
Conversation Features:
- Unique conversation IDs
- Optional conversation titles
- Participant management
- Message history with timestamps
- Last updated tracking
- File attachment support
Notes:
- The current user is automatically added as “Me” to all conversations
- Messages are sorted by timestamp, most recent first
- File attachments are handled using base64 encoding
- Search operations are case-insensitive
- Conversations maintain participant lists and message history
- All operations are tracked through event registration
- Messages can be paginated using offset and limit parameters
Get the user id for a given user name, the name must match EXACTLY, otherwise this returns None.
:type user_name: str
:param user_name: user name
:rtype: str | None
:returns: user id
Get the user name for a given user id, the id must match EXACTLY, otherwise returns None.
:type user_id: str
:param user_id: user id
:rtype: str | None
:returns: user name
Lookup the user id for a given user name, this is an fuzzy string based search so what is returned might not be exactly the query
returns Dictionary of user name to user id, for people names that are close enough to the query user_name.
dictionary will be empty if no matches are found
:type user_name: str
:param user_name: user name to lookup
:rtype: dict[str, str]
:returns: Dictionary of user name to user id, for people names that are close enough to the query user_name
Send a message to the specified recipient, if an existing conversation with the same recipient exists,
the message will be added to that conversation, otherwise a new conversation will be created.
This is the only way to send a message to a single person.
Parameters:
user_id (str) – The recipient id to send the message to
Create a new group conversation with the given participants.
There must be at least two participants participants other than the current user.
If title is not provided, it will be set to the participant names.
:type user_ids: list[str]
:param user_ids: List of Ids of the participants in the conversation. The current user is automatically added.
:type title: Optional[str]
:param title: Optional title for the conversation
:rtype: str
:returns: Id of the created conversation
Get the list of conversation ids for the given participants.
:type user_ids: list[str]
:param user_ids: List of Ids of the participants in the conversation. The current user is automatically added.
:rtype: list[str]
:returns: List of Ids of the conversations
List conversations ordered by the most recent modification, considering an offset and view limit.
e.g. list_recent_conversations(0, 5) will list the 5 most recent conversations.
:type offset: int
:param offset: The starting index from which to list conversations
:type limit: int
:param limit: The number of conversations to list, this number needs to be small otherwise an error will be raised
:type offset_recent_messages_per_conversation: int
:param offset_recent_messages_per_conversation: The starting index from which to list messages per conversation
:type limit_recent_messages_per_conversation: int
:param limit_recent_messages_per_conversation: The number of messages to list per conversation, this number needs to be small otherwise an error will be raised
:rtype: list[ConversationV2]
:returns: List of Conversation details
List all the conversations with the given participant.
:type user_id: str
:param user_id: User Id of the participant in the conversation
:type offset: int
:param offset: The starting index from which to list conversations
:type limit: int
:param limit: The number of conversations to list, this number needs to be small otherwise an error will be raised
:type offset_recent_messages_per_conversation: int
:param offset_recent_messages_per_conversation: The starting index from which to list messages per conversation
:type limit_recent_messages_per_conversation: int
:param limit_recent_messages_per_conversation: The number of messages to list per conversation, this number needs to be small otherwise an error will be raised
:rtype: list[ConversationV2]
:returns: List of Conversation details
Download an attachment from the conversation with the given conversation_id.
:type conversation_id: str
:param conversation_id: Conversation id
:type message_id: str
:param message_id: Message id
:type download_path: str
:param download_path: Path to download the attachment to
:rtype: str
:returns: Full path to the downloaded attachment if successful, otherwise raise Exception
Send a message to the conversation with the given conversation_id.
:type conversation_id: str
:param conversation_id: Conversation id
:type sender_id: str
:param sender_id: Sender id
:type content: str
:param content: Message content
:type timestamp: Optional[float]
:param timestamp: Timestamp of the message, if not provided, will be set to current time
:rtype: None
:returns: None
Send a message to the conversation with the given conversation_id.
:type conversation_id: str
:param conversation_id: Conversation id
:type sender_id: str
:param sender_id: Sender id
:type content: str
:param content: Message content
:rtype: None
:returns: None
Read the conversation with the given conversation_id.
Shows the last ‘limit’ messages after offset. Which means messages between offset and offset + limit will be shown.
Messages are sorted by timestamp, most recent first.
:type conversation_id: str
:param conversation_id: Conversation id
:type offset: int
:param offset: Offset to shift the view window
:type limit: int
:param limit: Number of messages to show
:type min_date: Optional[str]
:param min_date: Minimum date of the messages to be shown (YYYY-MM-DD %H:%M:%S format). Default is None, which means no minimum date.
:type max_date: Optional[str]
:param max_date: Maximum date of the messages to be shown (YYYY-MM-DD %H:%M:%S format). Default is None, which means no maximum date.
:rtype: dict
:returns: Dict with messages and additional info
Add a user to the conversation with the given conversation_id and updates the title if title is list of participants.
:type conversation_id: str
:param conversation_id: Conversation id to be updated
:type user_id: str
:param user_id: Id of the Participant to be added
:rtype: str
:returns: conversation_id of the conversation just updated, if successful, otherwise raise Exception.
Remove a participant from the conversation with the given conversation_id and updates the title if title is list of participants.
:type conversation_id: str
:param conversation_id: Conversation id
:type user_id: str
:param user_id: Id of the Participant to be removed
:rtype: str
:returns: conversation_id of the conversation just updated, if successful, otherwise raise Exception.
Change the title of the conversation with the given conversation_id.
:type conversation_id: str
:param conversation_id: Conversation id
:type title: str
:param title: New title for the conversation
:rtype: str
:returns: conversation_id of the conversation just updated, if successful, otherwise raise Exception.
Example:
change_conversation_title(“1234567890abcdef”, “My new title”)
Get the default title for a conversation with the given participants.
:type user_ids: list[str]
:param user_ids: List of Ids of the participants in the conversation, these are the names of the contacts, current user is automatically added
:rtype: str
:returns: Default title for the conversation
Search for conversations that match the given query.
The search is performed on conversation participants, titles, and message content.
Returns the Ids of the matching conversations.
:type query: str
:param query: The search query string
:type min_date: Optional[str]
:param min_date: Minimum date of the messages to be searched (YYYY-MM-DD %H:%M:%S format). Defaults to None (no minimum date).
:type max_date: Optional[str]
:param max_date: Maximum date of the messages to be searched (YYYY-MM-DD %H:%M:%S format). Defaults to None (no maximum date).
:rtype: list[str]
:returns: List of matching Conversation Ids
Search for conversations that match the given regex query (case insensitive).
The search is performed on conversation participants, titles, and message content.
Returns the Ids of the matching conversations.
:type query: str
:param query: The search query string
:type min_date: Optional[str]
:param min_date: Minimum date of the messages to be searched (YYYY-MM-DD %H:%M:%S format). Defaults to None (no minimum date).
:type max_date: Optional[str]
:param max_date: Maximum date of the messages to be searched (YYYY-MM-DD %H:%M:%S format). Defaults to None (no maximum date).
:rtype: list[str]
:returns: List of matching Conversation Ids
The Agent User Interface (AUI) is a tool for facilitating interactions between a user and an agent.
This interface provides methods to exchange messages, retrieve conversation history, and manage
the flow of communication, including support for simulated user responses through a proxy.
The AgentUserInterface manages message exchanges in a list structure, storing messages from both the user and
the agent, which can be accessed and filtered by various criteria. It allows for message persistence, tracking
unread messages, and retrieving conversation history, along with environment control for CLI or GUI-based
interactions.
Key Features:
Message Exchange: Send and retrieve messages from user and agent
User Proxy Support: Simulate user responses using an optional proxy for testing or automation
Unread Message Tracking: Retrieve unread messages from conversation history
Environment Control: Pause and resume environment during user-agent interactions
State Management: Access conversation state with methods to fetch and filter messages
Notes:
Messages are stored in a list and ordered chronologically
Supports CLI or GUI-based environments for real-time user input handling
The user proxy allows simulated responses for automated testing without real user input
Methods provide options to retrieve last messages or all messages by sender (user or agent)
State can be retrieved as a dictionary, preserving message history and interaction details
Initializes the Agent User Interface.
:type user_proxy: Optional[UserProxy]
:param user_proxy: The user proxy to use for simulating user responses.
Adds a message to be displayed to the user. This function does not
generate an event, it just modifies the app state. This function is
intended to be invoked from other app functions to display results from
those events as user messages.
:type content: str
:param content: The message content to send to the user.
Sends a message to the User. This will end the Agent’s turn.
:type content: str
:param content: the content to send to the user
:rtype: str | None
:returns: The response from the user
Sends a message to the Agent.
:type content: str
:param content: the content to send to the agent
:type attachments: Optional[list[str]]
:param attachments: optional; a list of attachments to send to the agent, each of them is a URL to a file
:type base64_utf8_encoded_attachment_contents: Optional[list[dict[str, Any]]]
:param base64_utf8_encoded_attachment_contents: optional; attachment contents corresponding to the attachments parameter. An entry may be an empty dict if an empty file was passed in.
:rtype: str
:return: The message ID that was generated for this message, can be used for tracking
Retrieves the last message that was sent from the User to the Agent.
:rtype: AUIMessage | None
:returns: the last message from the user or None if no messages have been sent
Retrieves all unread messages from the User and Agent conversation.
:rtype: list[AUIMessage]
:returns: a list of all unread messages or an empty list if all messages have been read
Retrieves the last message that was sent from the Agent to the User.
:rtype: AUIMessage | None
:returns: the last message from the agent or None if no messages have been sent
Send a user response to the agent.
:type content: str
:param content: the message content to be sent from the user to the agent
:param environment_type: the environment type
:type pause_func: Callable
:param pause_func: the function to pause the environment
:type wait_for_user_input_timeout: Optional[float]
:param wait_for_user_input_timeout: optional; the maximum time in seconds to wait for user input. Specify 0 to not wait, or None to wait indefinitely
:returns: None
A sandboxed local file system that restricts operations to a temporary directory, providing an isolated
and controlled environment for file and directory manipulations. This class offers functionality for
creating, reading, updating, and deleting files and directories, as well as methods for saving and
restoring file system states.
The Files ensures that all operations are confined to a designated temporary directory,
preventing access outside the sandbox. It maintains compatibility with standard file system operations
and integrates support for event logging and tool registration for enhanced tracking.
Key Features:
File and Directory Management: Create, open, list, move, and remove files and directories
Path Validation: Ensures operations remain within the designated sandbox directory
State Management: Save and load file system state for repeatability and restoration
Random Sampling: Retrieve random samples of files or folders within the sandbox
Permissions Management: Set permissions for files and directories
Event Logging: Integrated event tracking for operations
Notes:
The file system is non-cacheable to ensure isolated instances across parallel executions
Temporary directory paths are converted to absolute paths if necessary
Directories can be populated programmatically using specified population methods
Operations attempting to access paths outside the sandbox will raise a PermissionError
File system state can be saved and reloaded for scenario-based testing or persistence
A sandboxed local file system that restricts operations to a temporary directory, providing an isolated
and controlled environment for file and directory manipulations. This class offers functionality for
creating, reading, updating, and deleting files and directories, as well as methods for saving and
restoring file system states.
The SandboxLocalFileSystem ensures that all operations are confined to a designated temporary directory,
preventing access outside the sandbox. It maintains compatibility with standard file system operations
and integrates support for event logging and tool registration for enhanced tracking.
Key Features:
File and Directory Management: Create, open, list, move, and remove files and directories
Path Validation: Ensures operations remain within the designated sandbox directory
State Management: Save and load file system state for repeatability and restoration
Random Sampling: Retrieve random samples of files or folders within the sandbox
Permissions Management: Set permissions for files and directories
Event Logging: Integrated event tracking for operations
Notes:
The file system is non-cacheable to ensure isolated instances across parallel executions
Temporary directory paths are converted to absolute paths if necessary
Directories can be populated programmatically using specified population methods
Operations attempting to access paths outside the sandbox will raise a PermissionError
File system state can be saved and reloaded for scenario-based testing or persistence
Read the contents of a file.
:type path: str
:param path: path to the file to read
:type recursive: bool
:param recursive: If True, recursively read files in directories
:type on_error: str
:param on_error: What to do on error (‘raise’ or ‘omit’)
:type kwargs: dict[str, Any]
:param kwargs: additional arguments to pass to the file system
:rtype: str | bytes
:returns: contents of the file, read from with mode ‘rb’
Displays the file at the given path in the UI, but it will not be added to the agent context.
:type path: str
:param path: path to the file to display
:rtype: bool
:returns: True if the file exists, False if the file does not exist
Check if a file or directory exists.
:type path: str
:param path: path to the file or directory to check
:type kwargs: dict[str, Any]
:param kwargs: additional arguments to pass to the file system
:returns: True if the file or directory exists, False otherwise
Example:
exists(“/path/to/file.txt”)
get_file_content(path)
Read the contents of a file.
:type path: str
:param path: path to the file to read
:rtype: bytes
:returns: contents of the file
This function returns a list of randomly selected files.
:type k: int
:param k: number of files to return
:type seed: int
:param seed: seed for random number generation
:rtype: list[str]
:returns: list of file paths (relative to sandbox root)
This function returns a list of randomly selected folders.
:type k: int
:param k: number of folders to return
:type seed: int
:param seed: seed for random number generation
:rtype: list[str]
:returns: list of folder paths
Get information about a file or directory.
:type path: str
:param path: path to the file or directory to get information about
:type kwargs: dict[str, Any]
:param kwargs: additional arguments to pass to the file system
:rtype: dict[str, Any]
:returns: information about the file or directory
This function restores the file system from a given path.
:param path: path to the directory containing the file system.
:param target_dir: target directory to load the files to.
load_file_system_from_path(path)
This function restores the file system from a given path.
:type path: str
:param path: path to the directory containing the file system.
load_file_system_state(state_name)
This function restores the file system to the state saved
with the save_file_system_state function.
Uses lazy loading to avoid copying all files immediately.
:type state_name: str
:param state_name: name of the state to restore.
load_state(state_dict)
ls(path='.', detail=False, **kwargs)
List the contents of a directory.
:type path: str
:param path: path to list, defaults to ‘.’
:type detail: bool
:param detail: if True, return detailed information about each file
:type kwargs: dict[str, Any]
:param kwargs: additional arguments to pass to the file system
:rtype: list[str | dict[str, Any]]
:returns: list of files and directories in the directory
Create a directory and any parent directories if they do not exist.
:type path: str
:param path: path to the directory to create
:type exist_ok: bool
:param exist_ok: if True, do not raise an exception if the directory already exists
:rtype: None
:returns: None
Create a directory.
:type path: str
:param path: path to the directory to create
:type create_parents: bool
:param create_parents: if True, create parent directories if they do not exist
:type kwargs: dict[str, Any]
:param kwargs: additional arguments to pass to the file system
:rtype: None
:returns: None
Move a file or directory.
:type path1: str
:param path1: path to the file or directory to move
:type path2: str
:param path2: path to the destination
:type recursive: bool
:param recursive: If True, move directories recursively
:type maxdepth: Optional[int]
:param maxdepth: Maximum depth to recurse when recursive=True
:type kwargs: dict[str, Any]
:param kwargs: additional arguments to pass to the file system
:rtype: None
:returns: None
Open a file for reading or writing.
:type path: str
:param path: path to the file to open
:type mode: str
:param mode: mode to open the file in
:type block_size: Optional[int]
:param block_size: Size of blocks to read/write
:type cache_options: Optional[dict]
:param cache_options: Cache options
:type compression: Optional[str]
:param compression: Compression format
:type kwargs: dict[str, Any]
:param kwargs: additional arguments to pass to the file system
:returns: file handle to the opened file
Example:
open(“/path/to/file.txt”, “r”)
populate(pop_method)
read_document(file_path, max_lines=20)
Read and extract text content from various document types including PDFs, Word documents,
Excel spreadsheets, PowerPoint presentations, HTML files, and more. Returns the content
as structured text.
Setting max_lines is highly recommended to avoid long documents and filling up your memory.
Parameters:
file_path (str) – The path to the document file to read
max_lines (int | None) – Maximum number of lines to return. If set to None/null, returns the entire document, default is 20.
Remove a file or directory.
:type path: str
:param path: path to the file or directory to remove
:type recursive: bool
:param recursive: if True, remove the directory and all its contents
:type maxdepth: Optional[int]
:param maxdepth: Maximum depth to recurse when recursive=True
:rtype: None
:returns: None
This function saves the current state of the file system as is
to the shared data storage.
:type state_name: str
:param state_name: name under which the state will be saved.
Reuse this state_name to restore the state.
set_permissions(path, permission)
tree(path='.')
Generate a string representing the directory and file structure in a tree format.
:type path: str
:param path: Path to start the tree view from, defaults to the root of the sandbox
:rtype: str
:returns: A string representing the directory tree
A proxy class that delegates file system operations to SandboxLocalFileSystem.
This class maintains backward compatibility with the original VirtualFileSystem API
while using the more comprehensive SandboxLocalFileSystem implementation.
Open a file for reading or writing.
:type path: str
:param path: path to the file to open
:type mode: str
:param mode: mode to open the file in
:returns: file handle to the opened file
Create a directory.
:type path: str
:param path: path to the directory to create
:type create_recursive: bool
:param create_recursive: if True, create parent directories if they do not exist
:returns: None
Move a file or directory.
:type path1: str
:param path1: path to the file or directory to move
:type path2: str
:param path2: path to the destination
:returns: None
List the contents of a directory.
:type path: str
:param path: path to list, defaults to ‘.’
:type detail: bool
:param detail: if True, return detailed information about each file
:returns: list of files and directories in the directory
Remove a file or directory.
:type path: str
:param path: path to the file or directory to remove
:type recursive: bool
:param recursive: if True, remove the directory and all its contents
:returns: None
Check if a file or directory exists.
:type path: str
:param path: path to the file or directory to check
:returns: True if the file or directory exists, False otherwise
Get information about a file or directory.
:type path: str
:param path: path to the file or directory to get information about
:type kwargs: dict[str, Any]
:param kwargs: additional arguments to pass to the file system
:returns: information about the file or directory
Generate a string representing the directory and file structure in a tree format.
:type path: str
:param path: Path to start the tree view from, defaults to the root of the sandbox
:rtype: str
:returns: A string representing the directory tree
Get the current state of the file system in the original VirtualFileSystem format.
This maintains backward compatibility with previously stored states.
:rtype: dict[str, Any]
:returns: dictionary representing the current state
Get the temporary directory path used by the sandbox file system. For backward compatibility with the SandboxLocalFileSystem API.
:returns: path to the temporary directory
A calendar application that manages and manipulates calendar events. This class provides functionality
for creating, reading, updating, and deleting calendar events, as well as various utility methods
for searching and filtering events.
The CalendarApp maintains events in a dictionary where each event is identified by a unique event_id.
All datetime inputs should be in the format “YYYY-MM-DD HH:MM:SS” and are handled in UTC timezone.
Key Features:
Event Management: Add, update, delete, and retrieve calendar events
Time-based Queries: Get events within specific time ranges
Tag Support: Organize and filter events using tags
Search Functionality: Search events across multiple fields
State Management: Save and load calendar state
Notes:
All datetime operations are performed in UTC timezone
Event IDs are automatically generated when creating new events
The class supports state persistence through save/load operations
Add a calendar event to the calendar. Unless specified otherwise in the task, the default week starts on Monday and ends on Sunday.
:type title: str
:param title: Title of the event.
:type start_datetime: Optional[str]
:param start_datetime: Start datetime of the event in the format of YYYY-MM-DD HH:MM:SS.
:type end_datetime: Optional[str]
:param end_datetime: End datetime of the event in the format of YYYY-MM-DD HH:MM:SS.
:type tag: Optional[str]
:param tag: Tag of the event. Defaults to None.
:type description: Optional[str]
:param description: Description of the event. Defaults to None.
:type location: Optional[str]
:param location: Location of the event. Defaults to None.
:type attendees: Optional[list[str]]
:param attendees: List of attendees full names. Defaults to empty list.
:rtype: str
:returns: event_id: Id of the created event if successful.
Add a calendar event to the calendar. Unless specified otherwise in the task, the default week starts on Monday and ends on Sunday.
:type who_add: str
:param who_add: Name of the attendee who is adding the event.
:type title: str
:param title: Title of the event.
:type start_datetime: Optional[str]
:param start_datetime: Start datetime of the event in the format of YYYY-MM-DD HH:MM:SS.
:type end_datetime: Optional[str]
:param end_datetime: End datetime of the event in the format of YYYY-MM-DD HH:MM:SS.
:type tag: Optional[str]
:param tag: Tag of the event. Defaults to None.
:type description: Optional[str]
:param description: Description of the event. Defaults to None.
:type location: Optional[str]
:param location: Location of the event. Defaults to None.
:type attendees: Optional[list[str]]
:param attendees: List of attendees full names. who_add is automatically added to the list if not already present.
:rtype: str
:returns: event_id: Id of the created event if successful.
Read a calendar event from the calendar.
:type event_id: str
:param event_id: Id of the event to read.
:rtype: CalendarEvent
:returns: Calendar event details if successful, of type CalendarEvent, otherwise raise ValueError.
Delete a calendar event from the calendar.
:type event_id: str
:param event_id: Id of the event to delete.
:type who_delete: str
:param who_delete: Name of the attendee who is deleting the event.
:rtype: str
:returns: Message if successful, otherwise raise ValueError.
Delete a calendar event from the calendar.
:type event_id: str
:param event_id: Id of the event to delete.
:rtype: str
:returns: Message if successful, otherwise raise ValueError.
Get calendar events that have any time overlap with the specified date range (excludes events that only touch at boundaries).
Unless specified otherwise in the task, the default week starts on Monday and ends on Sunday.
:type start_datetime: str
:param start_datetime: Start datetime of the query range in the format of YYYY-MM-DD HH:MM:SS.
:type end_datetime: str
:param end_datetime: End datetime of the query range in the format of YYYY-MM-DD HH:MM:SS.
:type offset: int
:param offset: offset to start listing from, default is 0.
:type limit: int
:param limit: number of events to list, default is 10.
:rtype: CalendarEventsResult
:returns: List of calendar events details that overlap with the specified time range, limited to the specified offset and limit, with additional metadata about the range of events retrieved and total number of events.
Get calendar events from the calendar by tag.
:type tag: str
:param tag: Tag for which to get the events.
:rtype: list[CalendarEvent]
:returns: List of calendar events details.
Searches for calendar events based on a query string.
The search looks for partial matches in title, description, location, and attendees.
:type query: str
:param query: The search query string
:rtype: list[CalendarEvent]
:returns: A list of matching calendar details
A calendar application that manages and manipulates calendar events. This class provides functionality
for creating, reading, updating, and deleting calendar events, as well as various utility methods
for searching and filtering events.
The CalendarApp maintains events in a dictionary where each event is identified by a unique event_id.
All datetime inputs should be in the format “YYYY-MM-DD HH:MM:SS” and are handled in UTC timezone.
Key Features:
Event Management: Add, update, delete, and retrieve calendar events
Time-based Queries: Get events within specific time ranges
Tag Support: Organize and filter events using tags
Search Functionality: Search events across multiple fields
State Management: Save and load calendar state
Notes:
All datetime operations are performed in UTC timezone
Event IDs are automatically generated when creating new events
The class supports state persistence through save/load operations
A contacts management application that handles storage, retrieval, and manipulation of contact information.
This class provides comprehensive functionality for managing a contact database with pagination support
and search capabilities.
The ContactsApp stores contacts in a dictionary where each contact is identified by a unique contact_id.
The application implements a view limit mechanism for paginated access to contacts.
Key Features:
Contact Management: Add, edit, delete, and retrieve contact information
Pagination: View contacts with offset and limit support
Search Functionality: Search contacts by name, phone, or email
Current User: Special handling for current user’s contact information
State Management: Save and load application state
Batch Operations: Support for adding multiple contacts at once
Notes:
Contact fields include: first/last name, gender, age, nationality, city, status, job, address etc.
Gets the list of contacts starting from a specified offset. There is a view limit. Use offset to scroll through the contacts.
:type offset: int
:param offset: starting point to retrieve contacts from, default is 0.
:rtype: dict[str, Any]
:returns: list of contacts, limited to the specified offset and limit view, with additional metadata about the range of contacts retrieved and total number of contacts
Gets a specific contact by contact_id.
:type contact_id: str
:param contact_id: ID of the contact to retrieve
:rtype: Contact
:returns: contact details, if contact_id exists, otherwise raise KeyError
Gets the current user’s details including name, phone number, email address, nationality, country living.
:rtype: Contact
:returns: Contact details of the current user, if current user details exist in App, otherwise raise KeyError
Adds a new contact to the contacts app.
:type first_name: str
:param first_name: first name of the contact, required
:type last_name: str
:param last_name: last name of the contact, required
:type gender: Optional[str]
:param gender: gender of the contact (Male, Female, Other, Unknown), optional default is Unknown
:type age: Optional[int]
:param age: age of the contact, optional
:type nationality: Optional[str]
:param nationality: nationality of the contact, optional
:type city_living: Optional[str]
:param city_living: city where the contact is living, optional
:type country: Optional[str]
:param country: country where the contact is living, optional
:type status: Optional[str]
:param status: status of the contact (Student, Employed, Unemployed, Retired, Unknown), optional default is Unknown
:type job: Optional[str]
:param job: job of the contact, optional
:type description: Optional[str]
:param description: description of the contact, optional
:type phone: Optional[str]
:param phone: phone number of the contact, optional
:type email: Optional[str]
:param email: email address of the contact, optional
:type address: Optional[str]
:param address: address of the contact, optional
:rtype: str
:returns: contact_id of the newly added contact
Edits specific fields of a contact by contact_id.
:type contact_id: str
:param contact_id: ID of the contact to edit
:type updates: dict[str, Any]
:param updates: dictionary of updates to apply to the contact
:rtype: str | None
:returns: Success message if contact is edited successfully, otherwise raise KeyError or AttributeError
Deletes a specific contact by contact_id.
:type contact_id: str
:param contact_id: ID of the contact to delete
:rtype: str
:returns: Success message if contact is deleted successfully, otherwise raise KeyError
Searches for contacts based on a query string.
The search looks for partial matches in first name, last name, phone number, and email.
:type query: str
:param query: The search query string
:rtype: list[Contact]
:returns: A list of matching Contact objects
A contacts management application that handles storage, retrieval, and manipulation of contact information.
This class provides comprehensive functionality for managing a contact database with pagination support
and search capabilities.
The ContactsApp stores contacts in a dictionary where each contact is identified by a unique contact_id.
The application implements a view limit mechanism for paginated access to contacts.
Key Features:
Contact Management: Add, edit, delete, and retrieve contact information
Pagination: View contacts with offset and limit support
Search Functionality: Search contacts by name, phone, or email
Current User: Special handling for current user’s contact information
State Management: Save and load application state
Batch Operations: Support for adding multiple contacts at once
Notes:
Contact fields include: first/last name, gender, age, nationality, city, status, job, address etc.
This is where the full set of personas of the universe and their contact information is stored.
This is not visible to anntators but is part of the universe definition
A shopping application that facilitates the management of a product catalog, user cart, and orders.
This class provides core functionality for browsing products, adding items to a cart, applying discount
codes, and managing orders. It also includes utility methods for loading data from files, saving
application state, and restoring state as needed.
The ShoppingApp maintains a catalog of products, where each product can have multiple variants,
and tracks each user’s cart and orders individually. Products and variants are identified by unique
product IDs and item IDs, respectively.
Key Features:
Product Management: Load, browse, and retrieve detailed product information
Cart Management: Add, update, and remove items from the cart
Order Processing: Create, list, retrieve, and manage orders
Discount Codes: Apply discount codes to items in the cart and track their usage
State Management: Save and load application state from files and dictionaries
Notes:
All datetime operations are in UTC and managed by a global time manager
Unique IDs for products, items, and orders are generated automatically
Discount codes apply on a per-item basis and are checked for validity before use
Products in the cart are automatically removed upon successful checkout
Orders cannot be canceled if marked as “delivered” or “cancelled”
Add a product to the catalog. The created product currently doesn’t have any items. Please add items to the product using the add_item_to_product tool.
:type name: str
:param name: name of the product
:rtype: str
:return: product id if successful, otherwise raise ValueError.
Add an item variant to a product.
:type product_id: str
:param product_id: product id
:type price: float
:param price: price of the item
:type options: dict[str, Any]
:param options: characteristics of the item. Example: {“color”: “red”, “size”: “large”}.
:type available: bool
:param available: whether the item is available
:rtype: str
:return: item id if successful, otherwise raise ValueError.
Update an item in the catalog with new price and/or new availability
:type item_id: str
:param item_id: item id
:type new_price: Optional[float]
:param new_price: new price of the item
:type new_availability: Optional[bool]
:param new_availability: new availability of the item
:rtype: str
:return: item id if successful, otherwise raise ValueError.
Add a discount code to the inventory.
:type item_id: str
:param item_id: item id of the item for which this discount code works
:type discount_code: dict[str, float]
:param discount_code: discount code is the dictionary with key being the code and value the discount percentage.
:rtype: str
:return: success message if successful, otherwise raise ValueError.
Add an order to the orders.
:type order_id: str
:param order_id: order id to add to orders
:type order_status: str
:param order_status: order status to add to orders
:type order_date: float
:param order_date: date of the order
:type order_total: float
:param order_total: total price of the order
:type item_id: str
:param item_id: item id ordered
:type quantity: int
:param quantity: quantity of the item ordered
:rtype: str
:return: order id if successful, otherwise raise ValueError.
List all products in the catalog.
:type offset: int
:param offset: offset to start listing from, default is 0.
:type limit: int
:param limit: number of products to list, default is 10.
:rtype: ProductListResult
:returns: product details, dictionary of name to product_id, limited to the specified offset and limit, with additional metadata about the range of products retrieved and total number of products.
Get product details for a given product id.
:type product_id: str
:param product_id: product id to get details for
:rtype: Product
:returns: product details
Search for a product in the inventory by its name.
:type product_name: str
:param product_name: Name of the product to search for.
:type offset: int
:param offset: offset to start listing from, default is 0.
:type limit: int
:param limit: number of products to list, default is 10.
:rtype: list[Product]
:returns: List of products with the given name, limited to the specified offset and limit.
Add item to cart.
:type item_id: str
:param item_id: item id to add to cart
:type quantity: int
:param quantity: quantity to add to cart, default is 1
:rtype: str
:returns: item id of the added item if successful, otherwise raise Exception.
Remove item from cart.
:type item_id: str
:param item_id: item id to remove from cart
:type quantity: int
:param quantity: quantity to remove from cart
:rtype: str
:returns: item id of the removed item if successful, otherwise raise Exception.
Checkout the order and create a new order from the current cart contents.
IMPORTANT: If a discount code is provided, it MUST be valid for ALL items in the cart.
The checkout will fail with a ValueError if ANY item in the cart does not support
the provided discount code. This is a strict all-or-nothing discount policy.
Parameters:
discount_code (Optional[str]) – Optional discount code to apply to the entire order.
If provided, this discount code must be available for every
single item in the cart, otherwise the entire checkout will
fail with an error. If you want to use a discount code,
ensure all items in your cart support that specific code.
Takes the discount code and returns the applicable items with their discount percentages.
:type discount_code: str
:param discount_code: discount code to check
:rtype: dict[str, float]
:returns: Dictionary mapping item_id to discount_percentage for items that support this discount code
Returns all the discount codes that are available with the items they apply to.
:rtype: dict[str, list[str]]
:returns: Dictionary mapping discount codes to list of item IDs they apply to
Get order details.
:type order_id: str
:param order_id: order id to get details for
:rtype: Order
:returns: order details if successful, otherwise raise Exception.
Update order status.
:type order_id: str
:param order_id: order id to update status for
:type status: str
:param status: status to update to, default is “shipped”. Valid values are “processed”, “shipped”, “delivered”, “cancelled”.
:rtype: None
:returns: None if successful, otherwise raise Exception.
Cancel an order that is not yet delivered.
:type order_id: str
:param order_id: order id to cancel
:rtype: str
:returns: order id if successful, otherwise raise Exception.
A shopping application that facilitates the management of a product catalog, user cart, and orders.
This class provides core functionality for browsing products, adding items to a cart, applying discount
codes, and managing orders. It also includes utility methods for loading data from files, saving
application state, and restoring state as needed.
The ShoppingApp maintains a catalog of products, where each product can have multiple variants,
and tracks each user’s cart and orders individually. Products and variants are identified by unique
product IDs and item IDs, respectively.
Key Features:
Product Management: Load, browse, and retrieve detailed product information
Cart Management: Add, update, and remove items from the cart
Order Processing: Create, list, retrieve, and manage orders
Discount Codes: Apply discount codes to items in the cart and track their usage
State Management: Save and load application state from files and dictionaries
Notes:
All datetime operations are in UTC and managed by a global time manager
Unique IDs for products, items, and orders are generated automatically
Discount codes apply on a per-item basis and are checked for validity before use
Products in the cart are automatically removed upon successful checkout
Orders cannot be canceled if marked as “delivered” or “cancelled”
A cab service application that manages and facilitates ride requests and bookings. This class provides
functionality for creating, reading, updating, and canceling rides, as well as calculating fares and
handling ride history.
The CabApp maintains rides in a structured format, allowing users to book rides, view current ride status,
and retrieve ride history. Each ride is represented by a unique Ride object, containing relevant details
about the journey.
Key Features:
Ride Management: Create, book, cancel, and retrieve ride details
Quotation System: Calculate fare estimates based on distance, service type, and historical data
Ride History: Track past rides and access details for each ride
Delay Management: Update and record delays for ongoing rides
State Persistence: Save and load application state to retain ride and quotation history
Notes:
All ride attributes are expected to conform to specific data types (e.g., price as float, distance
as float)
Ride IDs are automatically generated upon creation
The class allows for the cancellation of rides by both users and drivers
Fare calculations consider historical pricing trends and maximum service distances
The distance calculation is currently a mock function; integration with a real mapping API is
recommended for accurate distance measurements
Add a new ride to the ride history.
:type service_type: str
:param service_type: type of service (Default, Premium, Van)
:type start_location: str
:param start_location: starting point of the ride
:type end_location: str
:param end_location: ending point of the ride
:type price: float
:param price: price of the ride
:type duration: float
:param duration: duration in minutes of the ride
:type time_stamp: float
:param time_stamp: time stamp of the ride
:type distance_km: float
:param distance_km: distance in kilometers of the ride
:rtype: str
:return: ride id of the added ride if successful, otherwise raise Exception.
Calculates the price and estimated delay for a ride.
:type start_location: str
:param start_location: starting point of the ride
:type end_location: str
:param end_location: ending point of the ride
:type service_type: str
:param service_type: type of service (Default, Premium, Van)
:type ride_time: Optional[str]
:param ride_time: the time of the ride in the format ‘YYYY-MM-DD HH:MM:SS’. If None, the current time is used.
:rtype: Ride
:returns: Ride with all the information: start_location, end_location, service_type, price, delay, distance, duration, the time_stamp.
Lists all rides available between two locations.
:type start_location: str
:param start_location: starting point of the ride
:type end_location: str
:param end_location: ending point of the ride
:type ride_time: Optional[str]
:param ride_time: the time of the ride. If None, the current time is used.
:rtype: list[Ride]
:returns: list of Ride objects
Orders a ride and returns the ride details.
:type start_location: str
:param start_location: starting point of the ride
:type end_location: str
:param end_location: ending point of the ride
:type service_type: str
:param service_type: type of service (Default, Premium, Van)
:type ride_time: Optional[str]
:param ride_time: the time of the ride
:rtype: Ride
:returns: booked ride, represented by a Ride object
The current ride is cancelled (by user or by driver).
:type who_cancel: str
:param who_cancel: who cancel the ride, either ‘driver’ or ‘user’
:type message: Optional[str]
:param message: optional message to send to the user
:rtype: str
:returns: message
Update the status of the current ride.
:type status: str
:param status: new status of the ride. Must be one of “DELAYED”, “IN_PROGRESS”, “ARRIVED_AT_PICKUP”.
:type message: Optional[str]
:param message: optional message from the driver.
:returns: new status of the ride
Gets a list of rides from the ride history starting from a specified offset.
:type offset: int
:param offset: starting point to retrieve rides from, default is 0.
:type limit: int
:param limit: maximum number of rides to retrieve, default is 10.
:rtype: dict[str, Any]
:returns: dictionary of ride details, where the key is the index of the ride in the ride history and the value is the ride details, with additional metadata about the range of rides retrieved and total number of rides.
Mock function to calculate the distance between two locations.
:type start_location: str
:param start_location: starting point of the ride
:type end_location: str
:param end_location: ending point of the ride
:rtype: float
:returns: distance in kilometers
A real estate application that manages and manipulates apartment listings. This class provides functionality
for creating, reading, updating, and deleting apartment listings, as well as various utility methods for
searching and filtering apartments based on multiple criteria.
The app maintains apartments in a dictionary where each apartment is identified by a unique
apartment_id. All price-related inputs should be in float format, and the number of bedrooms and bathrooms
should be integers.
Key Features:
Apartment Management: Add, update, delete, and retrieve apartment listings
Search Functionality: Filter apartments based on various criteria including location, price, size, and
amenities
Favorites Management: Save and remove favorite apartments for quick access
State Management: Save and load application state to retain apartment listings and favorites
Notes:
All apartment attributes are expected to adhere to specific data types (e.g., price as float, bedrooms
and bathrooms as integers)
Apartment IDs are automatically generated when creating new apartments
The class supports state persistence through save/load operations from a file
Search operations are case-insensitive for string comparisons
Amenities filtering checks if all specified amenities are present in the apartment’s amenities list
Adds a new apartment to the apartment listing.
:type name: str
:param name: name of the apartment
:type location: str
:param location: desired location
:type zip_code: str
:param zip_code: zip code of the apartment location
:type price: float
:param price: price of the apartment
:type number_of_bedrooms: int
:param number_of_bedrooms: number of bedrooms
:type number_of_bathrooms: int
:param number_of_bathrooms: number of bathrooms
:type property_type: str
:param property_type: type of property (Apartment, Condo, etc.)
:type square_footage: int
:param square_footage: minimum square footage
:type furnished_status: str
:param furnished_status: Furnished, Unfurnished, or Semi-furnished
:type floor_level: str
:param floor_level: Ground floor, Upper floors, Penthouse, Basement
:type pet_policy: str
:param pet_policy: Pets allowed, No pets, Cats allowed, Dogs allowed
:type lease_term: str
:param lease_term: Month-to-month, 6 months, 1 year, Long term lease
:type amenities: Optional[list[str]]
:param amenities: list of desired amenities
:rtype: str
:returns: apartment_id of the apartment just added, if successful, otherwise raise Exception.
Updates an existing apartment in the apartment listing.
:type apartment_id: str
:param apartment_id: apartment id to update
:type new_price: float
:param new_price: new price of the apartment
:rtype: str
:returns: apartment_id of the apartment just updated, if successful, otherwise raise Exception.
Deletes a specific apartment by apartment_id.
:type apartment_id: str
:param apartment_id: apartment id to delete
:rtype: None
:returns: apartment_id of the apartment just deleted, if successful, otherwise raise Exception.
Get apartment details for a given apartment id.
:type apartment_id: str
:param apartment_id: apartment id to get details for
:rtype: Apartment
:returns: apartment details
A real estate application that manages and manipulates apartment listings. This class provides functionality
for creating, reading, updating, and deleting apartment listings, as well as various utility methods for
searching and filtering apartments based on multiple criteria.
The app maintains apartments in a dictionary where each apartment is identified by a unique
apartment_id. All price-related inputs should be in float format, and the number of bedrooms and bathrooms
should be integers.
Key Features:
Apartment Management: Add, update, delete, and retrieve apartment listings
Search Functionality: Filter apartments based on various criteria including location, price, size, and
amenities
Favorites Management: Save and remove favorite apartments for quick access
State Management: Save and load application state to retain apartment listings and favorites
Notes:
All apartment attributes are expected to adhere to specific data types (e.g., price as float, bedrooms
and bathrooms as integers)
Apartment IDs are automatically generated when creating new apartments
The class supports state persistence through save/load operations from a file
Search operations are case-insensitive for string comparisons
Amenities filtering checks if all specified amenities are present in the apartment’s amenities list
A real estate application that manages and manipulates apartment listings. This class provides functionality
for creating, reading, updating, and deleting apartment listings, as well as various utility methods for
searching and filtering apartments based on multiple criteria.
The app maintains apartments in a dictionary where each apartment is identified by a unique
apartment_id. All price-related inputs should be in float format, and the number of bedrooms and bathrooms
should be integers.
Key Features:
Apartment Management: Add, update, delete, and retrieve apartment listings
Search Functionality: Filter apartments based on various criteria including location, price, size, and
amenities
Favorites Management: Save and remove favorite apartments for quick access
State Management: Save and load application state to retain apartment listings and favorites
Notes:
All apartment attributes are expected to adhere to specific data types (e.g., price as float, bedrooms
and bathrooms as integers)
Apartment IDs are automatically generated when creating new apartments
The class supports state persistence through save/load operations from a file
Search operations are case-insensitive for string comparisons
Amenities filtering checks if all specified amenities are present in the apartment’s amenities list
A city information application that provides access to crime rate data for different zip codes.
This class implements a rate-limited API service for retrieving crime statistics, with built-in
tracking of API usage and enforcement of call limits.
The CityApp maintains crime data in a dictionary where each zip code is mapped to its corresponding
crime statistics. The free version of the API has usage limitations that are strictly enforced.
Key Features:
Crime Data Access: Retrieve crime statistics for specific zip codes
Rate Limiting: Implements usage restrictions with 30-minute cooldown
API Usage Tracking: Monitors and manages API call counts
State Management: Save and load application state
Data Loading: Support for loading crime data from files or dictionaries
Notes:
Free version is limited to 100 API calls per 30-minute period
Rate limit reset requires a 30-minute waiting period
API calls are tracked and persist until manually reset
Attempting to exceed rate limits raises an exception
Get crime rate for a given zip code. This is a free version of the API, so it has a limit.
This limit can be obtained by calling get_api_call_limit() method.
If you exceed this limit, you have to wait for 30 minutes to make more calls.
:type zip_code: str
:param zip_code: zip code to get crime rate for
:rtype: CrimeDataPoint
:returns: crime rate details
The Model Context Protocol (MCP) and Meta Agents Research Environments Apps represent two different but complementary approaches to providing functionality to AI agents.
Understanding their differences and similarities helps in choosing the right approach for your use case.
Meta Agents Research Environments provides bidirectional integration with MCP:
Using MCP Tools in Meta Agents Research Environments
The MCPApp - Model Context Protocol discusses connecting to external MCP servers and use their tools within Meta Agents Research Environments simulations.
This allows you to leverage the growing ecosystem of MCP servers while maintaining Meta Agents Research Environments’s application-centric approach.
Exposing Meta Agents Research Environments as MCP Server
The MCP Server - Expose Scenarios allows you to expose Meta Agents Research Environments apps and scenarios as MCP servers, making them accessible to external agentic tools like Claude Desktop, Cursor, and other MCP-compatible clients.
Benefits of MCP Integration
Ecosystem Access: Leverage the growing ecosystem of MCP servers
Rapid Integration: Connect to external services without custom app development
Protocol Standardization: Benefit from MCP’s standardized communication protocol
Community Tools: Access community-developed MCP servers
Multi-Agent Testing: Test scenarios with different AI agents and tools
Meta Agents Research Environments App Advantages
Simulation Fidelity: Apps model real-world applications more accurately
State Consistency: Explicit state management ensures simulation reproducibility
Inter-App Communication: Apps can interact through protocols
Domain Modeling: Natural grouping of related functionality