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 agent_teams;
59#[cfg(feature = "ahp")]
60pub mod ahp;
61pub mod commands;
62pub mod config;
63pub mod context;
64pub mod default_parser;
65pub mod document_parser;
66pub mod error;
67pub mod file_history;
68pub mod hitl;
69pub mod hooks;
70pub mod llm;
71pub mod mcp;
72pub mod memory;
73pub mod orchestrator;
74pub mod permissions;
75pub mod planning;
76pub mod plugin;
77pub(crate) mod prompts;
78pub mod queue;
79pub(crate) mod retry;
80pub mod sandbox;
81pub mod scheduler;
82pub mod security;
83pub mod session;
84pub mod session_lane_queue;
85pub mod skills;
86pub mod store;
87pub(crate) mod subagent;
88pub mod telemetry;
89#[cfg(feature = "telemetry")]
90pub mod telemetry_otel;
91pub(crate) mod text;
92pub mod tool_search;
93pub mod tools;
94
95// Re-export key types at crate root for ergonomic usage
96pub use a3s_lane::MetricsSnapshot;
97pub use agent::{AgentConfig, AgentEvent, AgentLoop, AgentResult};
98pub use agent_api::{Agent, AgentSession, BtwResult, SessionOptions, ToolCallResult};
99pub use agent_teams::{
100    AgentExecutor, AgentTeam, TeamConfig, TeamMember, TeamMemberOptions, TeamMessage, TeamRole,
101    TeamRunResult, TeamRunner, TeamTaskBoard,
102};
103pub use commands::{
104    CommandAction, CommandContext, CommandOutput, CommandRegistry, CronCancelCommand,
105    CronListCommand, LoopCommand, SlashCommand,
106};
107pub use config::{CodeConfig, ModelConfig, ModelCost, ModelLimit, ModelModalities, ProviderConfig};
108pub use default_parser::{DefaultParser, DefaultParserOcrProvider};
109pub use document_parser::{
110    DocumentBlock, DocumentBlockKind, DocumentParser, DocumentParserRegistry, ParsedDocument,
111    PlainTextParser,
112};
113pub use error::{CodeError, Result};
114pub use hooks::HookEngine;
115pub use llm::{
116    AnthropicClient, Attachment, ContentBlock, ImageSource, LlmClient, LlmResponse, Message,
117    OpenAiClient, TokenUsage,
118};
119pub use orchestrator::AgentSlot;
120pub use plugin::{Plugin, PluginContext, PluginManager, SkillPlugin};
121pub use prompts::SystemPromptSlots;
122pub use queue::{
123    ExternalTask, ExternalTaskResult, LaneHandlerConfig, SessionCommand, SessionLane,
124    SessionQueueConfig, SessionQueueStats, TaskHandlerMode,
125};
126pub use sandbox::SandboxConfig;
127pub use scheduler::{CronScheduler, ScheduledFire, ScheduledTask, ScheduledTaskInfo};
128pub use session::{SessionConfig, SessionManager, SessionState};
129pub use session_lane_queue::SessionLaneQueue;
130pub use skills::{builtin_skills, Skill, SkillKind};
131pub use subagent::{load_agents_from_dir, AgentDefinition, AgentRegistry};
132pub use tool_search::{ToolIndex, ToolMatch, ToolSearchConfig};
133pub use tools::{ToolContext, ToolExecutor, ToolResult};