Skip to content

Refactor: Add plan_functions to new PlanModel #1729

Closed

Description

@abbiemery

Follows #1728

Now we have a unified Plan model in the context, we can store the plan
functions in there also.

This allows us to put the build_paramaters into this model and utilise
a __call__ to streamline some of the calling

The final Plan would look like this:

class Plan(BlueapiBaseModel):
    """
    A plan that can be run
    """

    name: str = Field(description="Referenceable name of the plan")
    description: str | None = Field(
        description="Description/docstring of the plan", default=None
    )
    model: type[BaseModel] = Field(
        description="Validation model of the parameters for the plan"
    )
    func: PlanGenerator = Field(description="The plan function to be run")

    def to_dict(self) -> dict[str, Any]:
        return {
            "name": self.name,
            "parameter_schema": self.model.model_json_schema(),
            "description": self.description,
        }

    def build_parameters(self, json_params: Mapping[str, Any]) -> dict[str, Any]:
        param_model = self.model.model_validate(json_params)
        prepared_params = {
            field: getattr(param_model, field)
            for field in param_model.__pydantic_fields__
        }
        return prepared_params

    def __call__(self, json_params: Mapping[str, Any]) -> MsgGenerator:
        p = self.build_parameters(json_params)
        return self.func(**p)

Would also close this old issue I just found on the same thing:
#180

Acceptance Criteria

  • The plan paramater building method is co-located with the rest of the
    Plan logic
  • All previous paramater building and error handling is preserved

Activity

  1. linked a pull request that will close this issuerefactor: Combine plans and plan_functions #1743on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions