From 1f278d0c1a2372925b2427457262d9af301b504e Mon Sep 17 00:00:00 2001 From: "Joel Z. Leibo" Date: Mon, 22 Jul 2024 04:08:53 -0700 Subject: [PATCH] improve prompts and logs for the entity agent and its components. PiperOrigin-RevId: 654688746 Change-Id: I48c3b249656e49f33cfcc047a88f2a1687533972 --- .../agent/v2/all_similar_memories.py | 2 +- .../agent/v2/concat_act_component.py | 2 +- concordia/components/agent/v2/constant.py | 3 +++ .../agent/v2/person_by_situation.py | 1 - concordia/components/agent/v2/plan.py | 6 +----- .../temporary_entity_agent__main_role.py | 21 ++++++++++--------- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/concordia/components/agent/v2/all_similar_memories.py b/concordia/components/agent/v2/all_similar_memories.py index 74362cec..d63aed5f 100644 --- a/concordia/components/agent/v2/all_similar_memories.py +++ b/concordia/components/agent/v2/all_similar_memories.py @@ -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({ diff --git a/concordia/components/agent/v2/concat_act_component.py b/concordia/components/agent/v2/concat_act_component.py index 00ee2e8e..70cb56c1 100644 --- a/concordia/components/agent/v2/concat_act_component.py +++ b/concordia/components/agent/v2/concat_act_component.py @@ -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, diff --git a/concordia/components/agent/v2/constant.py b/concordia/components/agent/v2/constant.py index 1467a9b4..a73bce4c 100644 --- a/concordia/components/agent/v2/constant.py +++ b/concordia/components/agent/v2/constant.py @@ -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 diff --git a/concordia/components/agent/v2/person_by_situation.py b/concordia/components/agent/v2/person_by_situation.py index 8cd4fcd9..26365cff 100644 --- a/concordia/components/agent/v2/person_by_situation.py +++ b/concordia/components/agent/v2/person_by_situation.py @@ -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(), diff --git a/concordia/components/agent/v2/plan.py b/concordia/components/agent/v2/plan.py index 83a27759..3304b373 100644 --- a/concordia/components/agent/v2/plan.py +++ b/concordia/components/agent/v2/plan.py @@ -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') @@ -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(), diff --git a/concordia/factory/agent/temporary_entity_agent__main_role.py b/concordia/factory/agent/temporary_entity_agent__main_role.py index 37992830..166044ed 100644 --- a/concordia/factory/agent/temporary_entity_agent__main_role.py +++ b/concordia/factory/agent/temporary_entity_agent__main_role.py @@ -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, ) @@ -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') @@ -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={ @@ -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 @@ -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, ) @@ -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,