Skip to content

Commit

Permalink
Fix bug in the case where the user produces a conversation by repeate…
Browse files Browse the repository at this point in the history
…dly calling `agent.say`. Previously the agent would not observe the conversation in that case since the usual way of observing the conversation happens in the conversation scene, which this approach bypasses. The method that uses the conversation scene bypasses 'say', so this won't observe twice. This change just makes the behavior of 'say' closer to the behavior of the conversation scene.

PiperOrigin-RevId: 636322219
Change-Id: I90bc997e29b795e40604483caf9070a8df034393
  • Loading branch information
jzleibo authored and copybara-github committed May 22, 2024
1 parent a55d7a3 commit 09f3a47
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions concordia/agents/basic_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def __init__(
self._user_controlled = user_controlled
self._update_interval = update_interval

self._conversation_prefix = ''
self._under_interrogation = False
self._state_lock = threading.Lock()

Expand Down Expand Up @@ -287,7 +288,22 @@ def get_externality(externality):

return output

def observe_latest(self, conversation: str):
# If the prefix is not found then `find` returns -1.
prefix_start_index = conversation.find(self._conversation_prefix)
if prefix_start_index >= 0:
# Get the part of the conversation the agent heard since their last turn.
start_index = prefix_start_index + len(self._conversation_prefix)
conversation_suffix = conversation[start_index:]
# Replace newline characters with commas.
conversation_suffix = conversation_suffix.replace('\n', ', ')
# Observe the new part of the conversation.
self.observe(conversation_suffix)
# Store the whole conversation thus far as the new prefix.
self._conversation_prefix = conversation

def say(self, conversation: str) -> str:
self.observe_latest(conversation)
convo_context = (
f'{self._agent_name} is in the following'
f' conversation:\n{conversation}\n'
Expand Down

0 comments on commit 09f3a47

Please sign in to comment.