Scenarios are the heart of Meta Agents Research Environments - they define the tasks that agents need to complete within the simulated environment. This guide covers how to understand, run, and work with scenarios effectively.
Every Meta Agents Research Environments scenario follows a consistent structure by inheriting from the Scenario base class and implementing key methods:
fromare.simulation.scenarios.scenarioimportScenariofromare.simulation.scenarios.utils.registryimportregister_scenariofromdataclassesimportdataclass@register_scenario("my_scenario")@dataclassclassMyScenario(Scenario):# Define scenario timingstart_time:float|None=0duration:float|None=30# Duration in secondsdefinit_and_populate_apps(self,*args,**kwargs)->None:# 1. Initialize applicationsemail_app=EmailClientApp()calendar_app=CalendarApp()messaging_app=MessagingApp()# 2. Populate initial dataemail_app.add_email(...)calendar_app.add_event(...)# 3. Register apps with scenarioself.apps=[email_app,calendar_app,messaging_app]defbuild_events_flow(self)->None:messaging_app=self.get_typed_app(MessagingApp)# 4. Define dynamic events that occur during executionevent1=Event.from_function(messaging_app.add_message,conversation_id="conv1",sender="John Doe",content="Hello!").depends_on(None,delay_seconds=5)self.events=[event1]defvalidate(self,env:AbstractEnvironment)->ScenarioValidationResult:# 5. Check if task was completed successfullytry:# Validation logic heresuccess=self.check_completion_criteria(env)returnScenarioValidationResult(success=success)exceptExceptionase:returnScenarioValidationResult(success=False,exception=e)
# Run scenario "scenario_find_image_file" with agent "default" using model "Llama-3.1-70B"
are-run-sscenario_find_image_file-adefault--modelLlama-3.1-70B-Instruct--providerllama-api
# Run scenario "scenario_find_image_file" in oracle mode
are-run-sscenario_find_image_file-o
defboth_responses_validator(env:AbstractEnvironment)->bool:"""Check if agent gave both responses."""aui_app=env.get_app("AgentUserInterface")agent_messages=aui_app.get_all_messages_from_agent()has_correct=any(msg.content=="I am a robot"formsginagent_messages)has_incorrect=any(msg.content=="I am not a robot •`_´• "formsginagent_messages)returnhas_correctandnothas_incorrectcontinuous_validation=ValidationEvent(milestones=[both_responses_validator]).with_id("continuous_validation")continuous_validation.depends_on(user_request,delay_seconds=1)continuous_validation.schedule(every_ticks=1,timeout=15)self.events.append(continuous_validation)
Agent Validation Event
defmilestone_correct_response(env:AbstractEnvironment,event:AbstractEvent)->bool:"""Milestone: Agent should say 'I am a robot'."""ifnotisinstance(event,Event):returnFalsereturn(event.action.app.__class__==AgentUserInterfaceandevent.function_name()=="send_message_to_user"andevent.action.args["content"]=="I am a robot")defminefield_unsafe_response(env:AbstractEnvironment,event:AbstractEvent)->bool:"""Minefield: Agent should NOT say unsafe things."""ifnotisinstance(event,Event):returnFalsereturn(event.action.app.__class__==AgentUserInterfaceandevent.function_name()=="send_message_to_user"andevent.action.args["content"]=="I am doing something unsafe!")agent_validation=AgentValidationEvent(milestones=[milestone_correct_response],minefields=[minefield_unsafe_response],timeout=15,).with_id("agent_validation")agent_validation.depends_on(user_request)self.events.append(agent_validation)
Action-Based Validation
Check if specific actions were performed:
defvalidate(self,env):# Check if email was sentsent_emails=env.get_app("EmailApp").sent_emailsreturnlen(sent_emails)>0and"apology"insent_emails[0].body.lower()
State-Based Validation
Check if the environment reached the desired state:
defvalidate(self,env):# Check if calendar was updatedcalendar=env.get_app("CalendarApp")returncalendar.has_appointment_on_date("2024-01-15")
Learn how to implement robust validation logic for your scenarios.
These tutorials provide practical, runnable examples that complement the documentation and help you understand how to apply the concepts in real scenarios.