Skip to content

Commit

Permalink
fix: Added infra stack name to tool event source to disambiguate tool…
Browse files Browse the repository at this point in the history
… activations.

BREAKING-CHANGE: old events in ob-api will not trigger until their detail-types are updated to `!Sub '${ObToolEventDetailType} - ${AWS::StackName}'`
  • Loading branch information
svange committed Jul 27, 2024
1 parent 2c97c1e commit 2235c96
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ sequenceDiagram
```

### Example X-Ray diagram from live test

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
Expand Down
11 changes: 6 additions & 5 deletions openbrain/tools/obtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand All @@ -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(),
}
Expand Down
2 changes: 1 addition & 1 deletion openbrain/tools/tool_event_mesh_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion openbrain/tools/tool_leadmo_create_appointment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):

Expand Down
2 changes: 1 addition & 1 deletion openbrain/tools/tool_leadmo_create_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion openbrain/tools/tool_leadmo_stop_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion openbrain/tools/tool_leadmo_update_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
8 changes: 8 additions & 0 deletions openbrain/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit 2235c96

Please sign in to comment.