-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
In notebook-6, if you instantiate the StepwisePlanner by running the StepwisePlanner example cell, then if you go back to run the SequentialPlanner, the SequentialPlanner finds the ExecutePlan skill/function and adds it as the last step of a Sequential Plan, which wipes out the chain of prior steps in the Sequential Plan.
I attempted to block the ExecutePlan skill in the SequentialPlannerConfig, but was unable to do so.
Input cell:
import time
# For ensuring that a function gets retried a few times before giving up
async def retry(func, retries=3):
delay = 5
for i in range(retries):
try:
result = await func()
return result
except Exception:
if i == retries - 1: # Last retry
raise
time.sleep(delay)
from semantic_kernel.planning import SequentialPlanner
from semantic_kernel.core_skills.text_skill import TextSkill
from semantic_kernel.planning.sequential_planner.sequential_planner_config import SequentialPlannerConfig
plugins_directory = "./plugins-sk"
writer_skill = kernel.import_semantic_skill_from_directory(plugins_directory, "LiterateFriend")
# create an instance of sequential planner, and exclude the TextSkill from the list of functions that it can use.
# (excluding functions that ActionPlanner imports to the kernel instance above - it uses 'this' as skillName)
planner = SequentialPlanner(kernel, SequentialPlannerConfig(excluded_skills=["this","StepwisePlanner.ExecutePlan","ExecutePlan"]))
# the ask for which the sequential planner is going to find a relevant function.
ask = """
Tomorrow is Valentine's day. I need to come up with a love poem. Translate the poem to German."""
# ask the sequential planner to identify a suitable function from the list of functions available.
plan = await retry(lambda: planner.create_plan_async(goal=ask))
# ask the sequential planner to execute the identified function.
result = await plan.invoke_async()
for index, step in enumerate(plan._steps):
print(f"✅ Step {index+1} used function `{step._function.name}`")
trace_resultp = True
if trace_resultp:
print("Longform trace:\n")
for index, step in enumerate(plan._steps):
print("Step:", index)
print("Description:",step.description)
print("Function:", step.skill_name + "." + step._function.name)
print("Input vars:", step._parameters.variables)
print("Output vars:", step._outputs)
if len(step._outputs) > 0:
print( " Output:\n", str.replace(result[step._outputs[0]],"\n", "\n "))
display(Markdown(f"## ✨ Generated result from the ask: {ask}\n\n---\n" + str(result)))
output:
✅ Step 1 used function `Summarize`
✅ Step 2 used function `ShortPoem`
✅ Step 3 used function `Translate`
✅ Step 4 used function `ExecutePlan`
Longform trace:
Step: 0
Description: Summarize given text or any text document
Function: LiterateFriend.Summarize
Input vars: {'input': "Tomorrow is Valentine's day. I need to come up with a love poem. Translate the poem to German."}
Output vars: ['SUMMARY']
Output:
Tomorrow is Valentine's day and I need to write a love poem, which I will then translate to German.
Step: 1
Description: Turn a scenario into a short and entertaining poem.
Function: LiterateFriend.ShortPoem
Input vars: {'input': '', 'topic': "Love on Valentine's Day"}
Output vars: ['POEM']
Output:
Roses are red, violets are blue,
I need to write a love poem, it's true.
But my German skills are quite lacking,
So this could end up quite cracking.
Ich liebe dich, my dear Valentine,
I hope this translation is just fine.
But if it's not
Step: 2
Description: Translate the input into a language of your choice
Function: LiterateFriend.Translate
Input vars: {'input': '$POEM', 'language': 'German'}
Output vars: ['TRANSLATED_POEM']
Output:
Rosen sind rot, Veilchen sind blau,
Ich muss ein Liebesgedicht schreiben, das ist wahr.
Aber meine Deutschkenntnisse sind ziemlich mangelhaft,
Also könnte das hier ziemlich schiefgehen.
Ich liebe dich, meine liebe Valentine,
Ich hoffe, diese Übersetzung ist in Ordnung.
Aber wenn nicht...
Step: 3
Description: Execute a plan
Function: StepwisePlanner.ExecutePlan
Input vars: {'input': '', 'function_descriptions': 'LiterateFriend.Translate', 'question': "What is the translated love poem for Valentine's Day?"}
Output vars: ['RESULT__FINAL_ANSWER']
Output:
The translated love poem for Valentine's Day is "Las rosas son rojas. Las violetas son azules. El azúcar es dulce. Y tú también lo eres."
Metadata
Metadata
Assignees
Labels
No labels