diff --git a/README.md b/README.md index c081e77..a12d92e 100644 --- a/README.md +++ b/README.md @@ -242,6 +242,8 @@ sequenceDiagram ``` +### Example X-Ray diagram from live test + ## Contributing See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. diff --git a/openbrain/tools/obtool.py b/openbrain/tools/obtool.py index 746ca4f..1378409 100644 --- a/openbrain/tools/obtool.py +++ b/openbrain/tools/obtool.py @@ -10,6 +10,8 @@ from openbrain.tools.protocols import OBCallbackHandlerFunctionProtocol from openbrain.util import logger, Defaults, config +INFRA_STACK_NAME = config.INFRA_STACK_NAME + class OBTool: """ A tool for GptAgents. Tools consist of the main langchain extended BaseTool and any callbacks needed to supplement @@ -79,11 +81,11 @@ def record_action(cls, tool_name, event, response, agent_config, session_id="no- @classmethod - def send_event(cls, event_detail: str, event_source: str = Defaults.OB_TOOL_EVENT_SOURCE.value) -> Any: + def send_event(cls, event_detail: str, tool_name: str) -> Any: """ Send a tool event to the Event Bus. :param event_detail: contains the event details including the context and ai_input - :param event_source: used to target event bus rules, indicates the source of the event, usually the name of the tool + :param tool_name: name of the tool, used to construct an event source :return: """ logger.info(f"Sending event: {event_detail}") @@ -92,13 +94,12 @@ def send_event(cls, event_detail: str, event_source: str = Defaults.OB_TOOL_EVEN event_bus_friendly_name = config.EVENTBUS_NAME event_bus_client = boto3.client("events") - response = None entries = [ { "EventBusName": event_bus_friendly_name, - "Source": event_source, - "DetailType": Defaults.OB_TOOL_EVENT_DETAIL_TYPE.value, + "Source": tool_name, + "DetailType": config.OB_TOOL_EVENT_DETAIL_TYPE, "Detail": event_detail, "Time": datetime.datetime.now().isoformat(), } diff --git a/openbrain/tools/tool_event_mesh_tester.py b/openbrain/tools/tool_event_mesh_tester.py index d4e1545..2f5f1d1 100644 --- a/openbrain/tools/tool_event_mesh_tester.py +++ b/openbrain/tools/tool_event_mesh_tester.py @@ -46,7 +46,7 @@ def _run(self, *args, **kwargs) -> str: event_detail = json.dumps({"context": context, "ai_input": kwargs}) - response = OBTool.send_event(event_source=TOOL_NAME, event_detail=event_detail) + response = OBTool.send_event(tool_name=TOOL_NAME, event_detail=event_detail) if agent_config.get("record_tool_actions"): wrapped_response = { diff --git a/openbrain/tools/tool_leadmo_create_appointment.py b/openbrain/tools/tool_leadmo_create_appointment.py index 51ecb29..bab5177 100644 --- a/openbrain/tools/tool_leadmo_create_appointment.py +++ b/openbrain/tools/tool_leadmo_create_appointment.py @@ -46,7 +46,7 @@ def _run(self, *args, **kwargs) -> str: event_detail_string = json.dumps(event_detail) logger.info(f"event_detail_string: {event_detail_string}") - response = OBTool.send_event(event_source=TOOL_NAME, event_detail=event_detail_string) + response = OBTool.send_event(tool_name=TOOL_NAME, event_detail=event_detail_string) if agent_config.get("record_tool_actions"): diff --git a/openbrain/tools/tool_leadmo_create_contact.py b/openbrain/tools/tool_leadmo_create_contact.py index 4ae8990..5d4e80b 100644 --- a/openbrain/tools/tool_leadmo_create_contact.py +++ b/openbrain/tools/tool_leadmo_create_contact.py @@ -49,7 +49,7 @@ def _run(self, *args, **kwargs) -> str: event_detail_string = json.dumps(event_detail) logger.info(f"event_detail_string: {event_detail_string}") - response = OBTool.send_event(event_source=TOOL_NAME, event_detail=event_detail_string) + response = OBTool.send_event(tool_name=TOOL_NAME, event_detail=event_detail_string) event = { 'context': context, diff --git a/openbrain/tools/tool_leadmo_stop_conversation.py b/openbrain/tools/tool_leadmo_stop_conversation.py index d11441e..2620534 100644 --- a/openbrain/tools/tool_leadmo_stop_conversation.py +++ b/openbrain/tools/tool_leadmo_stop_conversation.py @@ -56,7 +56,7 @@ def _run(self, *args, **kwargs) -> str: event_detail_string = json.dumps(event_detail) logger.info(f"event_detail_string: {event_detail_string}") - response = OBTool.send_event(event_source=TOOL_NAME, event_detail=event_detail_string) + response = OBTool.send_event(tool_name=TOOL_NAME, event_detail=event_detail_string) event = { 'context': context, diff --git a/openbrain/tools/tool_leadmo_update_contact.py b/openbrain/tools/tool_leadmo_update_contact.py index 75c3992..cb451c7 100644 --- a/openbrain/tools/tool_leadmo_update_contact.py +++ b/openbrain/tools/tool_leadmo_update_contact.py @@ -45,7 +45,7 @@ def _run(self, *args, **kwargs) -> str: event_detail_string = json.dumps(event_detail) logger.info(f"event_detail_string: {event_detail_string}") - response = OBTool.send_event(event_source=TOOL_NAME, event_detail=event_detail_string) + response = OBTool.send_event(tool_name=TOOL_NAME, event_detail=event_detail_string) if agent_config.get("record_tool_actions"): event = { diff --git a/openbrain/util.py b/openbrain/util.py index 6b36801..c7c143d 100644 --- a/openbrain/util.py +++ b/openbrain/util.py @@ -168,6 +168,14 @@ class Config: default_factory=lambda: [x.value for x in Defaults if x.name.startswith("OB_MODE_")] ) + OB_TOOL_EVENT_DETAIL_TYPE: str = field( + default=os.environ.get( + Defaults.OB_TOOL_EVENT_DETAIL_TYPE.name, + Defaults.OB_TOOL_EVENT_DETAIL_TYPE.value + ' - ' + os.environ.get(Defaults.INFRA_STACK_NAME.name, Defaults.INFRA_STACK_NAME.value) + ) #TODO: ugly shit + ) + + def __post_init__(self): if self.OB_MODE not in self.RECOGNIZED_OB_MODES: # raise ValueError(f"Environment variable OB_MODE={self.OB_MODE} must be one of {self.RECOGNIZED_OB_MODES}")