Skip to content

Commit b9c77f4

Browse files
Python: Fix parameter propagation bug in Plan Object Model (#2388)
### Motivation and Context Initially called out and fixed by @joowon-dm-snu in #2223 This PR closes [#2094](#2094) There was a bug in the Plan Object Model that propagates the name of the step parameter to the next step. It should be propagating the parameter's value ### Description In addition to making the code change to fix the bug, also added a unit test that covers the changed code. Below image shows the before and after of the test with the fix. ![image](https://github.com/microsoft/semantic-kernel/assets/54643756/7217f42a-a2ac-4491-a709-bea9be7328e3) ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄 Co-authored-by: Abby Harrison <[email protected]>
1 parent 274c4fd commit b9c77f4

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

python/semantic_kernel/planning/plan.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def get_next_step_variables(
410410

411411
expanded_value = self.expand_from_variables(variables, param_var)
412412
if expanded_value.lower() == param_var.lower():
413-
step_variables.set(param_var, expanded_value)
413+
step_variables.set(param_var, step.parameters._variables[param_var])
414414
elif variables.contains_key(param_var):
415415
step_variables.set(param_var, variables[param_var])
416416
elif self._state.contains_key(param_var):

python/tests/unit/planning/test_plan_execution.py

+31
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44

55
import semantic_kernel as sk
6+
from semantic_kernel.core_skills.math_skill import MathSkill
67
from semantic_kernel.core_skills.text_skill import TextSkill
78
from semantic_kernel.planning import Plan
89

@@ -180,3 +181,33 @@ async def test_invoke_multi_step_plan_async():
180181
plan.add_steps([new_step, new_step2])
181182
result = await plan.invoke_async(context=context)
182183
assert result.result == "HELLO WORLD"
184+
185+
186+
@pytest.mark.asyncio
187+
async def test_invoke_multi_step_plan_async_with_variables():
188+
# create a kernel
189+
kernel = sk.Kernel()
190+
191+
# import test (text) skill
192+
skill = MathSkill()
193+
skill_config_dict = kernel.import_skill(skill, "math")
194+
test_function = skill_config_dict["Add"]
195+
test_function2 = skill_config_dict["Subtract"]
196+
197+
plan = Plan(name="test")
198+
199+
# setup context for step 1
200+
context1 = kernel.create_new_context()
201+
context1["amount"] = "10"
202+
new_step = Plan(name="test", function=test_function, parameters=context1._variables)
203+
204+
# setup context for step 2
205+
context2 = kernel.create_new_context()
206+
context2["amount"] = "5"
207+
new_step2 = Plan(
208+
name="test", function=test_function2, parameters=context2._variables
209+
)
210+
211+
plan.add_steps([new_step, new_step2])
212+
result = await plan.invoke_async(input="2")
213+
assert result.result == "7"

0 commit comments

Comments
 (0)