Skip to content

Commit

Permalink
Add ResetMessage to clear the agent state (microsoft#3988)
Browse files Browse the repository at this point in the history
* Reset message to clear agent state

* format and lint
  • Loading branch information
ekzhu authored Oct 29, 2024
1 parent 93733db commit bd9c371
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ..messages import (
ChatMessage,
HandoffMessage,
ResetMessage,
StopMessage,
TextMessage,
)
Expand Down Expand Up @@ -209,7 +210,10 @@ def __init__(
async def on_messages(self, messages: Sequence[ChatMessage], cancellation_token: CancellationToken) -> ChatMessage:
# Add messages to the model context.
for msg in messages:
self._model_context.append(UserMessage(content=msg.content, source=msg.source))
if isinstance(msg, ResetMessage):
self._model_context.clear()
else:
self._model_context.append(UserMessage(content=msg.content, source=msg.source))

# Generate an inference result based on the current model context.
llm_messages = self._system_messages + self._model_context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ class HandoffMessage(BaseMessage):
"""The handoff message to the target agent."""


ChatMessage = TextMessage | MultiModalMessage | StopMessage | HandoffMessage
class ResetMessage(BaseMessage):
"""A message requesting reset of the recipient's state in the current conversation."""

content: str
"""The content for the reset message."""


ChatMessage = TextMessage | MultiModalMessage | StopMessage | HandoffMessage | ResetMessage
"""A message used by agents in a team."""


Expand All @@ -52,5 +59,6 @@ class HandoffMessage(BaseMessage):
"MultiModalMessage",
"StopMessage",
"HandoffMessage",
"ResetMessage",
"ChatMessage",
]

0 comments on commit bd9c371

Please sign in to comment.