Goal: Split code across files and define agent interfaces with traits.
Examples:
module navigation.path_planning;
export fn plan_path(from: Pose, to: Pose) -> Path {
return trajectory(from: from, to: to, steps: 8);
}
| Keyword | Purpose |
|---|---|
module name; |
Identifies this compilation unit |
export fn |
Visible to importers |
private fn |
Internal to the module |
import other.module; |
Pull exported symbols into scope |
Cross-file example:
spanda check examples/modules/navigation.sd
Traits define interfaces agents can implement:
trait PathPlanner {
fn plan(goal: NavGoal) -> Path;
}
agent Navigator {
tools [wheels];
goal "Plan safe paths";
plan { wheels.stop(); }
}
impl PathPlanner for Navigator {
fn plan(goal: NavGoal) -> Path {
wheels.stop();
}
}
Call the trait method from a behavior:
let route = Navigator.plan(goal);
This separates what planning means (trait) from who does it (agent).
| Construct | Role |
|---|---|
behavior |
Direct robot logic, often the main loop |
agent |
AI-facing entity with goals, tools, and optional trait impls |
ai_model |
LLM, vision, or other model (Lesson 6) |
spanda check examples/basics/05_traits_and_impl.sd
spanda run examples/basics/05_traits_and_impl.sd
spanda check examples/modules/path_planning.sd
spanda check examples/modules/navigation.sd
examples/modules/my_planner.sd with module my.planner and an exported plan_path
functionplan_path inside a behaviorPlanner and impl Planner for an agent that wraps the call