A3S CodeExamples
Planning
Task decomposition with goal tracking
Planning
Planning mode decomposes a complex prompt into a structured execution plan before running. Each step is tracked independently, enabling goal-oriented multi-step tasks.
Planning adds one extra LLM call to generate the plan. Use it for complex multi-file tasks; skip it for simple queries.
Enable Planning
use a3s_code_core::{Agent, SessionOptions};
let opts = SessionOptions::new()
.with_permissive_policy()
.with_planning(true)
.with_goal_tracking(true);
let session = agent.session("/my-project", Some(opts))?;
let result = session.send(
"Add input validation to all API endpoints, write tests, and update the README",
None,
).await?;
println!("{}", result.text);
println!("Tool calls: {}", result.tool_calls_count);Run: cargo run --example 05_planning
Source: core/examples/05_planning.rs
session = agent.session("/my-project",
permissive=True,
planning=True,
goal_tracking=True,
)
result = await session.send(
"Add input validation to all API endpoints, write tests, and update the README"
)
print(result.text)
print(f"Tool calls: {result.tool_calls_count}")const session = agent.session('/my-project', {
permissive: true,
planning: true,
goalTracking: true,
});
const result = await session.send(
'Add input validation to all API endpoints, write tests, and update the README'
);
console.log(result.text);
console.log(`Tool calls: ${result.toolCallsCount}`);Streaming Planning Events
let (mut rx, handle) = session.stream("Refactor and test the auth module", None).await?;
while let Some(event) = rx.recv().await {
match event {
AgentEvent::PlanningStart { prompt } => {
println!("📋 Planning: {}", prompt);
}
AgentEvent::PlanReady { steps, .. } => {
println!("Plan ({} steps):", steps.len());
for (i, step) in steps.iter().enumerate() {
println!(" {}. {}", i + 1, step);
}
}
AgentEvent::End { .. } => break,
_ => {}
}
}
handle.await??;async for event in session.stream("Refactor and test the auth module"):
t = event.get("type")
if t == "planning_start":
print(f"📋 Planning: {event['prompt']}")
elif t == "plan_ready":
print(f"Plan ({len(event['steps'])} steps):")
for i, step in enumerate(event["steps"], 1):
print(f" {i}. {step}")
elif t == "end":
breakfor await (const event of stream) {
if (event.type === 'planning_start') {
console.log(`📋 Planning: ${event.prompt}`);
} else if (event.type === 'plan_ready') {
console.log(`Plan (${event.steps.length} steps):`);
event.steps.forEach((step, i) => console.log(` ${i + 1}. ${step}`));
} else if (event.type === 'end') {
break;
}
}API Reference
SessionOptions
Prop
Type
Planning Events
Prop
Type