Expand description
Multi-turn interactive session management.
This module provides the Session struct for managing multi-turn
conversations with Claude, maintaining conversation history and
accumulating statistics across turns.
§Overview
A session wraps a ClaudeClient to provide:
- Multi-turn conversation support with history tracking
- Streaming responses with event handlers
- Cumulative statistics across all conversation turns
- Session isolation via unique session IDs
§Example
use gba_core::{Engine, EngineConfig, TaskStats};
use gba_core::event::PrintEventHandler;
use gba_pm::PromptManager;
// Create engine
let mut prompts = PromptManager::new();
prompts.load_dir("./tasks")?;
let config = EngineConfig::builder()
.workdir(".")
.prompts(prompts)
.build();
let engine = Engine::new(config)?;
// Create a session
let mut session = engine.session(None)?;
// Send messages (non-streaming)
let response = session.send("What is Rust?").await?;
println!("Response: {}", response);
// Send with streaming
let mut handler = PrintEventHandler::new().with_auto_flush();
let response = session.send_stream("Tell me more about ownership", &mut handler).await?;
// Check accumulated stats
let stats = session.stats();
println!("Total turns: {}", stats.turns);
println!("Total cost: ${:.4}", stats.cost_usd);
// Disconnect when done
session.disconnect().await?;Structs§
- Session
- Multi-turn interactive session with Claude.
- Session
Builder - Builder for creating sessions with custom options.
Enums§
- Conversation
Message - A message in a conversation.