Skip to content

.Net: Exceptions thrown from the HandlebarsPlanner should be specific and should contain Exception-Data. #4440

@Cotspheer

Description

@Cotspheer

Currently when HandlebarsPlanner throws an exception I have no way to recover from that in a meaningful and graceful manner. I don't have the plan, I don't have the prompt template and I have no way to differentiate between Exceptions besides testing the message if it contains a specific text.

Request:

  • Use of specific meaningful exceptions like InsufficientFunctionsForGoalException instead of KernelException (overall not specific to Planners!)
  • Include Details in the Exception-Data-Bag. For the planner for example:
    • Include the created plan / attempt
    • Include the created prompt

Reason why:

The message "Additional helpers may be required" triggers the exception but the plan is perfectly fine. So I want to recover from that and therefore I need the created plan. I'm totally able to handle the "Additional helpers may be required" message myself. So my intent is to test for a specific exception then extract the plan form the Exception-Data-Bag and continue with executing the plan. A specific exception would prevent the abuse of the Exception-Data-Bag and the properties may could set explicite.

Maybe the HandlebarsPlannerOptions should be extended with an option: "ShouldThrow" or something similar. Then the HandlebarsPlan could be extended with HasError and an Error-Object. So that HandlebarsPlan is more treated like a "Result Object".

Current Code:

        var planner = new HandlebarsPlanner(new HandlebarsPlannerOptions()
        {
            AllowLoops = true,
        });

        try
        {
            var plan = await planner.CreatePlanAsync(kernel, intent, cancellationToken);
            this.logger.LogInformation($"Plan: {plan}");
        }
        catch (Exception ex)
        {
            // try to extract the plan
            throw ex;
        }

Example Code:

        var plannerOptions = new HandlebarsPlannerOptions()
        {
            AllowLoops = true,
            ShouldThrow = false
        };

        var planner = new HandlebarsPlanner(plannerOptions);

        var plan = await planner.CreatePlanAsync(kernel, intent, cancellationToken);

        if (plan.HasError) {
            // some logic to test the ErrorObject if we can try to continue
        }

        // try to use the plan
        this.logger.LogInformation($"Plan: {plan}");

Metadata

Metadata

Assignees

Labels

.NETIssue or Pull requests regarding .NET code

Type

No type

Projects

Status

Sprint: Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions