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 security;
73pub mod session;
74pub mod session_lane_queue;
75pub mod skills;
76pub mod store;
77pub(crate) mod subagent;
78pub mod telemetry;
79pub mod tools;
80
81// Re-export key types at crate root for ergonomic usage
82pub use agent::{AgentConfig, AgentEvent, AgentLoop, AgentResult};
83pub use agent_api::{Agent, AgentSession, SessionOptions, ToolCallResult};
84pub use config::{CodeConfig, ModelConfig, ModelCost, ModelLimit, ModelModalities, ProviderConfig};
85pub use error::{CodeError, Result};
86pub use hooks::HookEngine;
87pub use llm::{
88    AnthropicClient, ContentBlock, LlmClient, LlmResponse, Message, OpenAiClient, TokenUsage,
89};
90pub use queue::{
91    ExternalTask, ExternalTaskResult, LaneHandlerConfig, SessionLane, SessionQueueConfig,
92    SessionQueueStats, TaskHandlerMode,
93};
94pub use session::{SessionConfig, SessionManager, SessionState};
95pub use session_lane_queue::SessionLaneQueue;
96pub use skills::{builtin_skills, Skill, SkillKind};
97pub use tools::{ToolContext, ToolExecutor, ToolResult};