Skip to content

Commit

Permalink
Simplifies GCResource
Browse files Browse the repository at this point in the history
  • Loading branch information
payneio committed Dec 16, 2024
1 parent bb56214 commit c2bf71f
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ requires-python = ">=3.11"
dependencies = [
"assistant-drive>=0.1.0",
"assistant-extensions[attachments]>=0.1.0",
"context>=0.1.0",
"datamodel-code-generator>=0.26.3",
"events>=0.1.0",
"openai-client>=0.1.0",
"skill-library>=0.1.0",
Expand All @@ -30,7 +28,6 @@ package = true
[tool.uv.sources]
assistant-drive = { path = "../../../assistant-drive", editable = true }
assistant-extensions = { path = "../../../assistant-extensions", editable = true }
context = { path = "../../../context", editable = true }
events = { path = "../../../events", editable = true }
openai-client = { path = "../../../openai-client", editable = true }
skill-library = { path = "../../skill-library", editable= true }
Expand Down
109 changes: 0 additions & 109 deletions libraries/python/skills/skills/form-filler-skill/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,81 @@ def _get_termination_instructions(resource: GCResource):
return ""


def get_resource_instructions(resource: GCResource) -> str:
"""
Get the resource instructions for the conversation.
Note: Assumes we're always using turns as the resource unit.
Returns:
str: the resource instructions
"""
if resource.resource_constraint is None:
return ""

formatted_elapsed_resource = format_resource(resource.elapsed_units, ResourceConstraintUnit.TURNS)
formatted_remaining_resource = format_resource(resource.remaining_units, ResourceConstraintUnit.TURNS)

# If the resource quantity is anything other than 1, the resource unit
# should be plural (e.g. "minutes" instead of "minute").
is_plural_elapsed = resource.elapsed_units != 1
is_plural_remaining = resource.remaining_units != 1

if resource.elapsed_units > 0:
resource_instructions = (
f"So far, {formatted_elapsed_resource} {'have' if is_plural_elapsed else 'has'} "
"elapsed since the conversation began. "
)
else:
resource_instructions = ""

if resource.resource_constraint.mode == ResourceConstraintMode.EXACT:
exact_mode_instructions = (
f"There {'are' if is_plural_remaining else 'is'} {formatted_remaining_resource} "
"remaining (including this one) - the conversation will automatically terminate "
"when 0 turns are left. You should continue the conversation until it is "
"automatically terminated. This means you should NOT preemptively end the "
'conversation, either explicitly (by selecting the "End conversation" action) '
"or implicitly (e.g. by telling the user that you have all required information "
"and they should wait for the next step). Your goal is not to maximize efficiency "
"(i.e. complete the artifact as quickly as possible then end the conversation), "
"but rather to make the best use of ALL remaining turns available to you"
)

if is_plural_remaining:
resource_instructions += (
f"{exact_mode_instructions}. This will require you to "
"plan your actions carefully using the agenda: you want to avoid the situation "
"where you have to pack too many topics into the final turns because you didn't "
"account for them earlier, or where you've rushed through the conversation and "
"all fields are completed but there are still many turns left."
)

# special instruction for the final turn (i.e. 1 remaining) in exact mode
else:
resource_instructions += (
f"{exact_mode_instructions}, including this one. Therefore, you should use this "
"turn to ask for any remaining information needed to complete the artifact, or, "
"if the artifact is already completed, continue to broaden/deepen the discussion "
"in a way that's directly relevant to the artifact. Do NOT indicate to the user "
"that the conversation is ending."
)

elif resource.resource_constraint.mode == ResourceConstraintMode.MAXIMUM:
resource_instructions += (
f"You have a maximum of {formatted_remaining_resource} (including this one) left to "
"complete the conversation. You can decide to terminate the conversation at any point "
"(including now), otherwise the conversation will automatically terminate when 0 turns "
"are left. You will need to plan your actions carefully using the agenda: you want to "
"avoid the situation where you have to pack too many topics into the final turns because "
"you didn't account for them earlier."
)
else:
logger.error("Invalid resource mode provided.")

return resource_instructions


async def generate_agenda(
language_model: LanguageModel,
definition: ConversationGuide,
Expand All @@ -118,7 +193,7 @@ async def generate_agenda(
# If there is a resource constraint and there's more than one turn left,
# include additional constraint instructions.
remaining_resource = resource.remaining_units if resource.remaining_units else 0
resource_instructions = resource.get_resource_instructions()
resource_instructions = get_resource_instructions(resource)
total_resource_str = ""
ample_time_str = ""
if (resource_instructions != "") and (remaining_resource > 1):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def conversation_routine(self) -> StateMachineRoutine:
constraint is reached, the conversation will end. An agenda will be
created and followed to guide the conversation. Either supply a
conversation definition in vars["definition"] or use a pre-configured
definition by supplying the name of your defintion in
definition by supplying the name of your definition in
vars["conversation_type"]. Current conversation types you can use are:
"acrostic_poem", "patient_intake", "er_triage", or "interview".
"""
Expand Down Expand Up @@ -196,7 +196,7 @@ async def conversation_init_function(
state["conversation"] = vars.get("conversation") or Conversation()
state["agenda"] = vars.get("agenda") or Agenda()
state["artifact"] = vars.get("artifact", {})
state["resource"] = GCResource(definition.resource_constraint)
state["resource"] = GCResource(resource_constraint=definition.resource_constraint)

# For guided conversation, we want to go ahead and run the first step.
return await self.conversation_step_function(context)
Expand Down
Loading

0 comments on commit c2bf71f

Please sign in to comment.