Skip to content

Commit

Permalink
improve prompts and logs for the entity agent and its components.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 654688746
Change-Id: I48c3b249656e49f33cfcc047a88f2a1687533972
  • Loading branch information
jzleibo authored and copybara-github committed Jul 22, 2024
1 parent 3741a12 commit 1f278d0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion concordia/components/agent/v2/all_similar_memories.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _make_pre_act_value(self) -> str:
result = new_prompt.open_question(
f'{question}\nStatements:\n{mems}',
max_tokens=2000,
terminators=(),
terminators=('\n\n',),
)

self._logging_channel({
Expand Down
2 changes: 1 addition & 1 deletion concordia/components/agent/v2/concat_act_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get_action_attempt(
) -> str:
prompt = interactive_document.InteractiveDocument(self._model)
context = self._context_for_action(contexts)
prompt.statement(context)
prompt.statement(context + '\n')

call_to_action = action_spec.call_to_action.format(
name=self.get_entity().name,
Expand Down
3 changes: 3 additions & 0 deletions concordia/components/agent/v2/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def __init__(
"""
super().__init__(pre_act_key)
self._state = state
self._logging_channel = logging_channel

def _make_pre_act_value(self) -> str:
self._logging_channel(
{'Key': self.get_pre_act_key(), 'Value': self._state})
return self._state
1 change: 0 additions & 1 deletion concordia/components/agent/v2/person_by_situation.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def _make_pre_act_value(self) -> str:
memory.add(f'[intent reflection] {result}', metadata={})

self._logging_channel({
'Summary': question,
'Key': self.get_pre_act_key(),
'Value': result,
'Chain of thought': prompt.view().text().splitlines(),
Expand Down
6 changes: 1 addition & 5 deletions concordia/components/agent/v2/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _make_pre_act_value(self) -> str:
prompt.statement(
f'Current goal: {goal_component.get_pre_act_value()}.') # pylint: disable=undefined-variable
prompt.statement(f'Current plan: {self._current_plan}')
prompt.statement(f'Current situation: {observation}')
prompt.statement(f'Current situation: {latest_observations}')

time_now = self._clock_now().strftime('[%d %b %Y %H:%M:%S]')
prompt.statement(f'The current time is: {time_now}\n')
Expand All @@ -155,10 +155,6 @@ def _make_pre_act_value(self) -> str:
result = self._current_plan

self._logging_channel({
'Summary': (
f'detailed plan of {agent_name} '
+ f'for {self._horizon}'
),
'Key': self.get_pre_act_key(),
'Value': result,
'Chain of thought': prompt.view().text().splitlines(),
Expand Down
21 changes: 11 additions & 10 deletions concordia/factory/agent/temporary_entity_agent__main_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def build_agent(
observation = agent_components.observation.Observation(
clock_now=clock.now,
timeframe=clock.get_step_size(),
pre_act_key='Observation',
pre_act_key='\nObservation',
logging_channel=measurements.get_channel('Observation').on_next,
)

Expand All @@ -83,12 +83,12 @@ def build_agent(
)
time_display = agent_components.report_function.ReportFunction(
function=clock.current_time_interval_str,
pre_act_key='Current time',
pre_act_key='\nCurrent time',
logging_channel=measurements.get_channel('TimeDisplay').on_next,
)
identity_characteristics = agent_components.identity.IdentityWithoutPreAct(
model=model,
logging_channel=measurements.get_channel('Identity').on_next,
logging_channel=measurements.get_channel('IdentityWithoutPreAct').on_next,
)
self_perception_label = (
f'\nQuestion: What kind of person is {agent_name}?\nAnswer')
Expand Down Expand Up @@ -129,7 +129,7 @@ def build_agent(
pre_act_key=person_by_situation_label,
logging_channel=measurements.get_channel('PersonBySituation').on_next,
)
relevant_memories_label = 'Recalled memories and observations'
relevant_memories_label = '\nRecalled memories and observations'
relevant_memories = agent_components.all_similar_memories.AllSimilarMemories(
model=model,
components={
Expand All @@ -143,11 +143,12 @@ def build_agent(

plan_components = {}
if config.goal:
goal_label = 'Overarching goal'
goal_label = '\nOverarching goal'
overarching_goal = agent_components.constant.Constant(
state=config.goal,
pre_act_key=goal_label)
plan_components[_get_class_name(overarching_goal)] = goal_label
pre_act_key=goal_label,
logging_channel=measurements.get_channel(goal_label).on_next)
plan_components[goal_label] = goal_label
else:
goal_label = None
overarching_goal = None
Expand All @@ -165,7 +166,7 @@ def build_agent(
clock_now=clock.now,
goal_component_name=_get_class_name(person_by_situation),
horizon=DEFAULT_PLANNING_HORIZON,
pre_act_key='Plan',
pre_act_key='\nPlan',
logging_channel=measurements.get_channel('Plan').on_next,
)

Expand All @@ -174,12 +175,12 @@ def build_agent(
instructions,
observation,
observation_summary,
self_perception,
relevant_memories,
self_perception,
situation_perception,
person_by_situation,
time_display,
plan,
time_display,

# Components that do not provide pre_act context.
identity_characteristics,
Expand Down

0 comments on commit 1f278d0

Please sign in to comment.