Handle the agent calling a function
(
self,
msg: str,
msg_obj: Optional[Message] = None,
include_ran_messages: bool = False,
)
| 499 | self._queue_push(message_api=new_message, message_obj=msg_obj) |
| 500 | |
| 501 | def function_message( |
| 502 | self, |
| 503 | msg: str, |
| 504 | msg_obj: Optional[Message] = None, |
| 505 | include_ran_messages: bool = False, |
| 506 | ) -> None: |
| 507 | """Handle the agent calling a function""" |
| 508 | # TODO handle 'function' messages that indicate the start of a function call |
| 509 | assert msg_obj is not None, "QueuingInterface requires msg_obj references for metadata" |
| 510 | |
| 511 | if self.debug: |
| 512 | print(msg) |
| 513 | print(vars(msg_obj)) |
| 514 | print(msg_obj.created_at.isoformat()) |
| 515 | |
| 516 | if msg.startswith("Running "): |
| 517 | msg = msg.replace("Running ", "") |
| 518 | new_message = {"function_call": msg} |
| 519 | |
| 520 | elif msg.startswith("Ran "): |
| 521 | if not include_ran_messages: |
| 522 | return |
| 523 | msg = msg.replace("Ran ", "Function call returned: ") |
| 524 | new_message = {"function_call": msg} |
| 525 | |
| 526 | elif msg.startswith("Success: "): |
| 527 | msg = msg.replace("Success: ", "") |
| 528 | new_message = {"function_return": msg, "status": "success"} |
| 529 | |
| 530 | elif msg.startswith("Error: "): |
| 531 | msg = msg.replace("Error: ", "", 1) |
| 532 | new_message = {"function_return": msg, "status": "error"} |
| 533 | |
| 534 | else: |
| 535 | # NOTE: generic, should not happen |
| 536 | new_message = {"function_message": msg} |
| 537 | |
| 538 | # add extra metadata |
| 539 | if msg_obj is not None: |
| 540 | new_message["id"] = str(msg_obj.id) |
| 541 | assert is_utc_datetime(msg_obj.created_at), msg_obj.created_at |
| 542 | new_message["date"] = msg_obj.created_at.isoformat() |
| 543 | |
| 544 | self._queue_push(message_api=new_message, message_obj=msg_obj) |
nothing calls this directly
no test coverage detected