Skip to content

Commit

Permalink
an updated tutorial, with automatically filled pre_act_key and clear …
Browse files Browse the repository at this point in the history
…measurement channel names

PiperOrigin-RevId: 662859999
Change-Id: I79d3195c14ee37841e355e74d272d7407b130abe
  • Loading branch information
vezhnick authored and copybara-github committed Aug 14, 2024
1 parent d6a228a commit 96f05d0
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions examples/tutorials/agent_development.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
"\n",
" def __init__(\n",
" self,\n",
" agent_name:str,\n",
" **kwargs,\n",
" ):\n",
" #@markdown {agent_name} will be automatically replaced with the name of the specific agent\n",
Expand All @@ -276,7 +277,9 @@
" add_to_memory = True # @param {\"type\":\"boolean\"}\n",
" #@markdown If yes, the memory will start with this tag\n",
" memory_tag = '[self reflection]' # @param {\"type\":\"string\"}\n",
" question_with_name = question.format(agent_name=agent_name)\n",
" super().__init__(\n",
" pre_act_key=f'\\nQuestion: {question_with_name}\\nAnswer',\n",
" question=question,\n",
" answer_prefix=answer_prefix,\n",
" add_to_memory=add_to_memory,\n",
Expand All @@ -300,14 +303,17 @@
"\n",
" def __init__(\n",
" self,\n",
" agent_name:str,\n",
" **kwargs,\n",
" ):\n",
" question = 'Given the statements above, what kind of situation is {agent_name} in right now?' #@param {\"type\":\"string\"}\n",
" answer_prefix = '{agent_name} is currently ' #@param {\"type\":\"string\"}\n",
" add_to_memory = False # @param {\"type\":\"boolean\"}\n",
" memory_tag = '[situation reflection]' # @param {\"type\":\"string\"}\n",
" question_with_name = question.format(agent_name=agent_name)\n",
"\n",
" super().__init__(\n",
" pre_act_key=f'\\nQuestion: {question_with_name}\\nAnswer',\n",
" question=question,\n",
" answer_prefix=answer_prefix,\n",
" add_to_memory=add_to_memory,\n",
Expand All @@ -331,12 +337,19 @@
"class Question3(question_of_recent_memories.QuestionOfRecentMemories):\n",
" \"\"\"What would a person like the agent do in a situation like this?\"\"\"\n",
"\n",
" def __init__(self, **kwargs):\n",
" def __init__(\n",
" self,\n",
" agent_name:str,\n",
" **kwargs):\n",
" question = 'What would a person like {agent_name} do in a situation like this?' #@param {\"type\":\"string\"}\n",
" answer_prefix = '{agent_name} would ' #@param {\"type\":\"string\"}\n",
" add_to_memory = True # @param {\"type\":\"boolean\"}\n",
" memory_tag = '[intent reflection]' # @param {\"type\":\"string\"}\n",
"\n",
" question_with_name = question.format(agent_name=agent_name)\n",
"\n",
" super().__init__(\n",
" pre_act_key=f'\\nQuestion: {question_with_name}\\nAnswer',\n",
" question=question,\n",
" answer_prefix=answer_prefix,\n",
" add_to_memory=add_to_memory,\n",
Expand All @@ -362,33 +375,23 @@
" model: language_model.LanguageModel,\n",
" clock: game_clock.MultiIntervalClock,\n",
") -\u003e Sequence[question_of_recent_memories.QuestionOfRecentMemories]:\n",
" question_1_label = (\n",
" f'\\nQuestion: What kind of person is {agent_name}?\\nAnswer'\n",
" )\n",
"\n",
" question_1 = Question1(\n",
" agent_name=agent_name,\n",
" model=model,\n",
" pre_act_key=question_1_label,\n",
" logging_channel=measurements.get_channel('SelfPerception').on_next,\n",
" )\n",
" question_2_label = (\n",
" f'\\nQuestion: What kind of situation is {agent_name} in '\n",
" 'right now?\\nAnswer'\n",
" logging_channel=measurements.get_channel('Question_1').on_next,\n",
" )\n",
" question_2 = Question2(\n",
" agent_name=agent_name,\n",
" model=model,\n",
" clock_now=clock.now,\n",
" pre_act_key=question_2_label,\n",
" logging_channel=measurements.get_channel('SituationPerception').on_next,\n",
" )\n",
" question_3_label = (\n",
" f'\\nQuestion: What would a person like {agent_name} do in '\n",
" 'a situation like this?\\nAnswer'\n",
" logging_channel=measurements.get_channel('Question_2').on_next,\n",
" )\n",
" question_3 = Question3(\n",
" agent_name=agent_name,\n",
" model=model,\n",
" clock_now=clock.now,\n",
" pre_act_key=question_3_label,\n",
" logging_channel=measurements.get_channel('PersonBySituation').on_next,\n",
" logging_channel=measurements.get_channel('Question_3').on_next,\n",
" )\n",
"\n",
" return (question_1, question_2, question_3)"
Expand Down Expand Up @@ -489,7 +492,7 @@
"\n",
"\n",
" question_components = _make_question_components(\n",
" agent_name=agent_name, model=model, clock=clock, measurements=measurements\n",
" model=model, clock=clock, measurements=measurements\n",
" )\n",
"\n",
" core_components = (\n",
Expand Down Expand Up @@ -662,10 +665,6 @@
],
"metadata": {
"colab": {
"last_runtime": {
"build_target": "",
"kind": "private"
},
"private_outputs": true,
"provenance": [],
"toc_visible": true
Expand Down

0 comments on commit 96f05d0

Please sign in to comment.