Skip to content

Commit f357b45

Browse files
Python: Fixes Plan using an empty function in describe and incorrectly setting context variables for next steps. (microsoft#4673)
### Motivation and Context This PR fixes microsoft#4658 and fixes microsoft#2933. ### Description The first one basically needed a None check before using `self._function` in the `Plan.describe` method. The second one was incorrectly setting the values for variables for the next step in the plan. The solution for this was suggested by @amritpal-singh-98, thank you! ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [X] The code builds clean without any errors or warnings - [X] 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 - [X] All unit tests pass, and I have added new tests where possible - [X] I didn't break anyone 😄 --------- Co-authored-by: Evan Mattson <[email protected]>
1 parent a5bc63d commit f357b45

File tree

1 file changed

+12
-12
lines changed
  • python/semantic_kernel/planning

1 file changed

+12
-12
lines changed

python/semantic_kernel/planning/plan.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,10 @@ def set_default_skill_collection(
240240
if self._function is not None:
241241
self._function.set_default_skill_collection(skills)
242242

243-
def describe(self) -> FunctionView:
244-
return self._function.describe()
243+
def describe(self) -> Optional[FunctionView]:
244+
if self._function is not None:
245+
return self._function.describe()
246+
return None
245247

246248
def set_available_functions(self, plan: "Plan", context: SKContext) -> "Plan":
247249
if len(plan.steps) == 0:
@@ -400,19 +402,17 @@ def get_next_step_variables(self, variables: ContextVariables, step: "Plan") ->
400402
elif param.name in self._state and (self._state[param.name] is not None and self._state[param.name] != ""):
401403
step_variables.set(param.name, self._state[param.name])
402404

403-
for param_var in step.parameters.variables:
404-
if param_var in step_variables:
405+
for param_name, param_val in step.parameters.variables.items():
406+
if param_name in step_variables:
405407
continue
406408

407-
expanded_value = self.expand_from_variables(variables, param_var)
408-
if expanded_value.lower() == param_var.lower():
409-
step_variables.set(param_var, step.parameters.variables[param_var])
410-
elif param_var in variables:
411-
step_variables.set(param_var, variables[param_var])
412-
elif param_var in self._state:
413-
step_variables.set(param_var, self._state[param_var])
409+
if param_name in variables:
410+
step_variables.set(param_name, param_val)
411+
elif param_name in self._state:
412+
step_variables.set(param_name, self._state[param_name])
414413
else:
415-
step_variables.set(param_var, expanded_value)
414+
expanded_value = self.expand_from_variables(variables, param_val)
415+
step_variables.set(param_name, expanded_value)
416416

417417
for item in variables.variables:
418418
if item not in step_variables:

0 commit comments

Comments
 (0)