| Crates.io | goaprs |
| lib.rs | goaprs |
| version | 0.2.1 |
| created_at | 2025-07-28 14:50:13.183243+00 |
| updated_at | 2025-07-28 14:50:13.183243+00 |
| description | Goal Oriented Action Planning implementation in Rust |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1771227 |
| size | 428,991 |
A Goal-Oriented Action Planning (GOAP) implementation in Rust. This library provides a flexible and efficient way to implement autonomous agents that can plan sequences of actions to achieve specific goals.
Add this to your Cargo.toml:
[dependencies]
goaprs = "0.2.0"
Here's a simple example of how to use the library:
use goap_rs::{Action, State, Planner, Result};
fn main() -> Result<()> {
// Create actions
let mut gather_wood = Action::new("gather_wood", 1.0)?;
gather_wood.preconditions.set("has_axe", true);
gather_wood.effects.set("has_wood", true);
let mut build_house = Action::new("build_house", 2.0)?;
build_house.preconditions.set("has_wood", true);
build_house.effects.set("has_house", true);
// Create the planner with available actions (Default A* search)
// For Dijkstra search algorithm use:
// let planner = Planner::with_search_algorithm(actions, Box::new(DijkstraSearch));
let planner = Planner::new(vec![gather_wood, build_house]);
// Define the current state
let mut current_state = State::new();
current_state.set("has_axe", true);
current_state.set("has_wood", false);
current_state.set("has_house", false);
// Define the goal state
let mut goal_state = State::new();
goal_state.set("has_house", true);
// Find a plan
let plan = planner.plan(¤t_state, &goal_state)?;
// Execute the plan
for action in plan {
println!("Executing action: {}", action.name);
}
Ok(())
}
If you want to visualize the plan you can use the GoapVizualizer::new():
let visualizer = GoapVisualizer::new();
visualizer.visualize_plan(&actions, ¤t_state, &goal_state, &plan, "output.dot")?;
GOAP (Goal-Oriented Action Planning) is an AI architecture that enables agents to plan sequences of actions to achieve specific goals. The system works by:
The planner will find the most efficient path from the current state to the goal state, taking into account the cost of each action.
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.