Skip to main content

a3s_code_core/
lib.rs

1//! A3S Code Core Library
2//!
3//! Embeddable AI agent library with tool execution capabilities.
4//! This crate contains all business logic extracted from the A3S Code agent,
5//! enabling direct Rust API usage as an embedded library.
6//!
7//! ## Quick Start
8//!
9//! ```rust,no_run
10//! use a3s_code_core::{Agent, AgentEvent};
11//!
12//! # async fn run() -> anyhow::Result<()> {
13//! // From a config file path (.hcl or .json)
14//! let agent = Agent::new("agent.hcl").await?;
15//!
16//! // Create a workspace-bound session
17//! let session = agent.session("/my-project", None)?;
18//!
19//! // Non-streaming
20//! let result = session.send("What files handle auth?", None).await?;
21//! println!("{}", result.text);
22//!
23//! // Streaming (AgentEvent is #[non_exhaustive])
24//! let (mut rx, _handle) = session.stream("Refactor auth", None).await?;
25//! while let Some(event) = rx.recv().await {
26//!     match event {
27//!         AgentEvent::TextDelta { text } => print!("{text}"),
28//!         AgentEvent::End { .. } => break,
29//!         _ => {} // required: #[non_exhaustive]
30//!     }
31//! }
32//! # Ok(())
33//! # }
34//! ```
35//!
36//! ## Architecture
37//!
38//! ```text
39//! Agent (facade — config-driven, workspace-independent)
40//!   +-- LlmClient (Anthropic / OpenAI)
41//!   +-- CodeConfig (HCL / JSON)
42//!   +-- SessionManager (multi-session support)
43//!         |
44//!         +-- AgentSession (workspace-bound)
45//!               +-- AgentLoop (core execution engine)
46//!               |     +-- ToolExecutor (14 tools: 11 builtin + 3 skill discovery)
47//!               |     +-- LlmPlanner (JSON-structured planning)
48//!               |     +-- HITL Confirmation
49//!               +-- HookEngine (8 lifecycle events)
50//!               +-- Security (sanitizer, taint, injection detection, audit)
51//!               +-- Memory (episodic, semantic, procedural, working)
52//!               +-- MCP (JSON-RPC 2.0, stdio + HTTP+SSE)
53//!               +-- Cost Tracking / Telemetry
54//! ```
55
56pub mod agent;
57pub mod agent_api;
58pub mod config;
59pub mod context;
60#[cfg(feature = "context-store")]
61pub mod context_store;
62pub mod error;
63pub mod file_history;
64pub mod hitl;
65pub mod hooks;
66pub mod llm;
67pub mod mcp;
68pub mod memory;
69pub mod permissions;
70pub mod planning;
71pub(crate) mod prompts;
72pub mod queue;
73pub(crate) mod retry;
74pub mod security;
75pub mod session;
76pub mod session_lane_queue;
77pub mod store;
78pub(crate) mod subagent;
79pub mod telemetry;
80pub mod tools;
81
82// Re-export key types at crate root for ergonomic usage
83pub use agent::{AgentConfig, AgentEvent, AgentLoop, AgentResult};
84pub use agent_api::{Agent, AgentSession, SessionOptions, ToolCallResult};
85pub use config::{CodeConfig, ModelConfig, ModelCost, ModelLimit, ModelModalities, ProviderConfig};
86pub use error::{CodeError, Result};
87pub use hooks::HookEngine;
88pub use llm::{
89    AnthropicClient, ContentBlock, LlmClient, LlmResponse, Message, OpenAiClient, TokenUsage,
90};
91pub use queue::{
92    ExternalTask, ExternalTaskResult, LaneHandlerConfig, SessionLane, SessionQueueConfig,
93    SessionQueueStats, TaskHandlerMode,
94};
95pub use session::{SessionConfig, SessionManager, SessionState};
96pub use session_lane_queue::SessionLaneQueue;
97pub use tools::{ToolContext, ToolExecutor, ToolResult};