moonbitstack/moonkoog/plan does not have a README file

    GoapAction

    pub(all) struct GoapAction[S] {
    name : String
    applies : (S) -> Bool
    effect : (S) -> S
    cost : (S) -> Double
    }

    One action of a goal-oriented plan: when it applies, what it changes, and what it costs.

    A GOAP plan is searched over world states, so an action has to be a pure function of the state it runs in — that is what lets the search try it without side effects.

    GoapAction::new

    fn[S] GoapAction::new(name~ : String, applies~ : (S) -> Bool, effect~ : (S) -> S, cost? : (S) -> Double) -> GoapAction[S]

    An action named name that applies when applies, produces effect, and costs 1 by default.

    GoapGoal

    pub(all) struct GoapGoal[S] {
    reached : (S) -> Bool
    estimate : (S) -> Double
    }

    What a plan is for: a test for "done", and an estimate of how far away that is.

    GoapGoal::new

    fn[S] GoapGoal::new(reached~ : (S) -> Bool, estimate? : (S) -> Double) -> GoapGoal[S]

    A goal with no estimate beyond "zero when reached" — Dijkstra's search instead of A*.

    advance_node

    let advance_node : String

    The node that records a step as done, and decides whether to plan again.

    done

    How many steps the state has finished.

    index_key

    let index_key : String

    How many steps are done.

    parse_steps

    fn parse_steps(text : String, limit : Int) -> Array[String]

    Read a list of steps out of a model reply: the JSON array when there is one, otherwise the lines that look like steps. A model that answers with a numbered list instead of JSON is common enough that refusing it would make the feature unusable.

    plan_and_execute

    Turn the config into a plan-and-execute agent: a planner writes the steps, the model works through them with its tools, and a failed step sends the run back to the planner.

    The loop lives in the graph, so a run that stops — for approval, for a checkpoint, for a cap — resumes at the step it was on with the plan it had.

    plan_key

    let plan_key : String

    The steps a run is working through, in order.

    planner_node

    let planner_node : String

    The names of the nodes a plan-and-execute run adds to a graph.

    planning_prompt

    fn planning_prompt(task : String, limit : Int) -> String

    The prompt that turns a task into steps.
    fn[S : Eq + Hash] search(actions : Array[GoapAction[S]], start : S, goal : GoapGoal[S]) -> Array[String]?

    The least-cost sequence of action names that reaches goal from start, or None when no sequence does.

    The search is A* over the state space: the frontier is ordered by the cost so far plus the goal's estimate, and a state reached more cheaply replaces the one recorded. A state is keyed by the value itself, so the state type has to be comparable — for a world state that means a record of flags or a small map, not a mutable object.

    step_node

    let step_node : String

    The node that hands the next step to the model.

    steps

    The plan a state holds.