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