Module tinytroupe.tools.tiny_calendar
Expand source code
import textwrap
import json
from tinytroupe.tools import logger, TinyTool
import tinytroupe.utils as utils
# TODO under development
class TinyCalendar(TinyTool):
def __init__(self, owner=None):
super().__init__("calendar", "A basic calendar tool that allows agents to keep track meetings and appointments.", owner=owner, real_world_side_effects=False)
# maps date to list of events. Each event itself is a dictionary with keys "title", "description", "owner", "mandatory_attendees", "optional_attendees", "start_time", "end_time"
self.calenar = {}
def add_event(self, date, title, description=None, owner=None, mandatory_attendees=None, optional_attendees=None, start_time=None, end_time=None):
if date not in self.calendar:
self.calendar[date] = []
self.calendar[date].append({"title": title, "description": description, "owner": owner, "mandatory_attendees": mandatory_attendees, "optional_attendees": optional_attendees, "start_time": start_time, "end_time": end_time})
def find_events(self, year, month, day, hour=None, minute=None):
# TODO
pass
def _process_action(self, agent, action) -> bool:
if action['type'] == "CREATE_EVENT" and action['content'] is not None:
# parse content json
event_content = json.loads(action['content'])
# checks whether there are any kwargs that are not valid
valid_keys = ["title", "description", "mandatory_attendees", "optional_attendees", "start_time", "end_time"]
utils.check_valid_fields(event_content, valid_keys)
# uses the kwargs to create a new event
self.add_event(event_content)
return True
else:
return False
def actions_definitions_prompt(self) -> str:
prompt = \
"""
- CREATE_EVENT: You can create a new event in your calendar. The content of the event has many fields, and you should use a JSON format to specify them. Here are the possible fields:
* title: The title of the event. Mandatory.
* description: A brief description of the event. Optional.
* mandatory_attendees: A list of agent names who must attend the event. Optional.
* optional_attendees: A list of agent names who are invited to the event, but are not required to attend. Optional.
* start_time: The start time of the event. Optional.
* end_time: The end time of the event. Optional.
"""
# TODO how the atendee list will be handled? How will they be notified of the invitation? I guess they must also have a calendar themselves. <-------------------------------------
return utils.dedent(prompt)
def actions_constraints_prompt(self) -> str:
prompt = \
"""
"""
# TODO
return textwrap.dedent(prompt)
Classes
class TinyCalendar (owner=None)
-
A mixin class that provides JSON serialization, deserialization, and subclass registration.
Initialize a new tool.
Args
name
:str
- The name of the tool.
description
:str
- A brief description of the tool.
owner
:str
- The agent that owns the tool. If None, the tool can be used by anyone.
real_world_side_effects
:bool
- Whether the tool has real-world side effects. That is to say, if it has the potential to change the state of the world outside of the simulation. If it does, it should be used with caution.
exporter
:ArtifactExporter
- An exporter that can be used to export the results of the tool's actions. If None, the tool will not be able to export results.
enricher
:Enricher
- An enricher that can be used to enrich the results of the tool's actions. If None, the tool will not be able to enrich results.
Expand source code
class TinyCalendar(TinyTool): def __init__(self, owner=None): super().__init__("calendar", "A basic calendar tool that allows agents to keep track meetings and appointments.", owner=owner, real_world_side_effects=False) # maps date to list of events. Each event itself is a dictionary with keys "title", "description", "owner", "mandatory_attendees", "optional_attendees", "start_time", "end_time" self.calenar = {} def add_event(self, date, title, description=None, owner=None, mandatory_attendees=None, optional_attendees=None, start_time=None, end_time=None): if date not in self.calendar: self.calendar[date] = [] self.calendar[date].append({"title": title, "description": description, "owner": owner, "mandatory_attendees": mandatory_attendees, "optional_attendees": optional_attendees, "start_time": start_time, "end_time": end_time}) def find_events(self, year, month, day, hour=None, minute=None): # TODO pass def _process_action(self, agent, action) -> bool: if action['type'] == "CREATE_EVENT" and action['content'] is not None: # parse content json event_content = json.loads(action['content']) # checks whether there are any kwargs that are not valid valid_keys = ["title", "description", "mandatory_attendees", "optional_attendees", "start_time", "end_time"] utils.check_valid_fields(event_content, valid_keys) # uses the kwargs to create a new event self.add_event(event_content) return True else: return False def actions_definitions_prompt(self) -> str: prompt = \ """ - CREATE_EVENT: You can create a new event in your calendar. The content of the event has many fields, and you should use a JSON format to specify them. Here are the possible fields: * title: The title of the event. Mandatory. * description: A brief description of the event. Optional. * mandatory_attendees: A list of agent names who must attend the event. Optional. * optional_attendees: A list of agent names who are invited to the event, but are not required to attend. Optional. * start_time: The start time of the event. Optional. * end_time: The end time of the event. Optional. """ # TODO how the atendee list will be handled? How will they be notified of the invitation? I guess they must also have a calendar themselves. <------------------------------------- return utils.dedent(prompt) def actions_constraints_prompt(self) -> str: prompt = \ """ """ # TODO return textwrap.dedent(prompt)
Ancestors
Class variables
var serializable_attributes
Methods
def actions_constraints_prompt(self) ‑> str
-
Expand source code
def actions_constraints_prompt(self) -> str: prompt = \ """ """ # TODO return textwrap.dedent(prompt)
def actions_definitions_prompt(self) ‑> str
-
Expand source code
def actions_definitions_prompt(self) -> str: prompt = \ """ - CREATE_EVENT: You can create a new event in your calendar. The content of the event has many fields, and you should use a JSON format to specify them. Here are the possible fields: * title: The title of the event. Mandatory. * description: A brief description of the event. Optional. * mandatory_attendees: A list of agent names who must attend the event. Optional. * optional_attendees: A list of agent names who are invited to the event, but are not required to attend. Optional. * start_time: The start time of the event. Optional. * end_time: The end time of the event. Optional. """ # TODO how the atendee list will be handled? How will they be notified of the invitation? I guess they must also have a calendar themselves. <------------------------------------- return utils.dedent(prompt)
def add_event(self, date, title, description=None, owner=None, mandatory_attendees=None, optional_attendees=None, start_time=None, end_time=None)
-
Expand source code
def add_event(self, date, title, description=None, owner=None, mandatory_attendees=None, optional_attendees=None, start_time=None, end_time=None): if date not in self.calendar: self.calendar[date] = [] self.calendar[date].append({"title": title, "description": description, "owner": owner, "mandatory_attendees": mandatory_attendees, "optional_attendees": optional_attendees, "start_time": start_time, "end_time": end_time})
def find_events(self, year, month, day, hour=None, minute=None)
-
Expand source code
def find_events(self, year, month, day, hour=None, minute=None): # TODO pass
Inherited members