pub struct Engine<'a> { /* private fields */ }Expand description
Core execution engine for GBA.
The engine orchestrates AI-assisted workflows by:
- Loading task configurations from the
tasks/directory - Rendering system and user prompts using templates
- Configuring and invoking the Claude agent
- Processing responses and extracting results
§Example
use gba_core::{Engine, EngineConfig, Task, TaskKind};
use gba_pm::PromptManager;
use serde_json::json;
// Create and configure the prompt manager
let mut prompts = PromptManager::new();
prompts.load_dir("./tasks")?;
// Create the engine
let config = EngineConfig::builder()
.workdir(".")
.prompts(prompts)
.build();
let engine = Engine::new(config)?;
// Run a task
let task = Task::new(TaskKind::Init, json!({"repo_path": "."}));
let result = engine.run(task).await?;
println!("Success: {}", result.success);Implementations§
Source§impl<'a> Engine<'a>
impl<'a> Engine<'a>
Sourcepub fn new(config: EngineConfig<'a>) -> Result<Self>
pub fn new(config: EngineConfig<'a>) -> Result<Self>
Sourcepub async fn run(&self, task: Task) -> Result<TaskResult>
pub async fn run(&self, task: Task) -> Result<TaskResult>
Run a task and return the result.
This method:
- Loads the task configuration from
tasks/<kind>/config.yml - Renders the system and user prompts from templates
- Configures the Claude agent based on the task config
- Executes the query and processes the response
§Arguments
task- The task to execute
§Errors
Returns an error if:
- The task configuration cannot be loaded
- The prompt templates cannot be rendered
- The Claude agent query fails
Sourcepub async fn run_stream(
&self,
task: Task,
handler: &mut impl EventHandler,
) -> Result<TaskResult>
pub async fn run_stream( &self, task: Task, handler: &mut impl EventHandler, ) -> Result<TaskResult>
Run a task with streaming events.
This method is similar to run() but streams events
to the provided handler during execution, enabling real-time
feedback and progress tracking.
§Arguments
task- The task to executehandler- Event handler for streaming events
§Errors
Returns an error if:
- The task configuration cannot be loaded
- The prompt templates cannot be rendered
- The Claude agent query fails
§Example
use gba_core::{Engine, EngineConfig, Task, TaskKind};
use gba_core::event::PrintEventHandler;
use gba_pm::PromptManager;
use serde_json::json;
let mut prompts = PromptManager::new();
prompts.load_dir("./tasks")?;
let config = EngineConfig::builder()
.workdir(".")
.prompts(prompts)
.build();
let engine = Engine::new(config)?;
let task = Task::new(TaskKind::Init, json!({"repo_path": "."}));
let mut handler = PrintEventHandler::new().with_auto_flush();
let result = engine.run_stream(task, &mut handler).await?;Sourcepub fn session(&self, session_id: Option<String>) -> Result<Session>
pub fn session(&self, session_id: Option<String>) -> Result<Session>
Create an interactive session for multi-turn conversations.
Sessions maintain a persistent connection to Claude and track conversation history and statistics across multiple turns.
§Arguments
session_id- Optional session ID; if None, a UUID is generated
§Errors
Returns an error if the session cannot be created.
§Example
use gba_core::{Engine, EngineConfig};
use gba_pm::PromptManager;
let mut prompts = PromptManager::new();
let config = EngineConfig::builder()
.workdir(".")
.prompts(prompts)
.build();
let engine = Engine::new(config)?;
let mut session = engine.session(None)?;
let response = session.send("Hello Claude!").await?;
println!("Claude: {}", response);
// Follow-up in same session
let response = session.send("Tell me more").await?;
// Check accumulated stats
let stats = session.stats();
println!("Total turns: {}", stats.turns);
session.disconnect().await?;Sourcepub fn session_with_task(
&self,
task_kind: &TaskKind,
context: &Value,
session_id: Option<String>,
) -> Result<Session>
pub fn session_with_task( &self, task_kind: &TaskKind, context: &Value, session_id: Option<String>, ) -> Result<Session>
Create a session with a specific task configuration.
This method creates a session that uses the configuration from a specific task type, including its system prompt and tool settings.
§Arguments
task_kind- The task kind to use for configurationcontext- Context for rendering the system prompt templatesession_id- Optional session ID
§Errors
Returns an error if the task configuration cannot be loaded or the session cannot be created.