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;
60pub mod error;
61pub mod file_history;
62pub mod hitl;
63pub mod hooks;
64pub mod llm;
65pub mod mcp;
66pub mod memory;
67pub mod permissions;
68pub mod planning;
69pub(crate) mod prompts;
70pub mod queue;
71pub(crate) mod retry;
72pub mod sandbox;
73pub mod security;
74pub mod session;
75pub mod session_lane_queue;
76pub mod skills;
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, Attachment, ContentBlock, ImageSource, LlmClient, LlmResponse, Message,
90    OpenAiClient, TokenUsage,
91};
92pub use queue::{
93    ExternalTask, ExternalTaskResult, LaneHandlerConfig, SessionLane, SessionQueueConfig,
94    SessionQueueStats, TaskHandlerMode,
95};
96pub use sandbox::SandboxConfig;
97pub use session::{SessionConfig, SessionManager, SessionState};
98pub use session_lane_queue::SessionLaneQueue;
99pub use skills::{builtin_skills, Skill, SkillKind};
100pub use tools::{ToolContext, ToolExecutor, ToolResult};