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 error;
65pub mod file_history;
66pub mod git;
67pub mod hitl;
68pub mod hooks;
69pub mod llm;
70pub mod mcp;
71pub mod memory;
72pub mod orchestrator;
73pub mod permissions;
74pub mod planning;
75pub mod plugin;
76pub(crate) mod prompts;
77pub mod queue;
78pub(crate) mod retry;
79pub mod sandbox;
80pub mod scheduler;
81pub mod security;
82pub mod session;
83pub mod session_lane_queue;
84pub mod skills;
85pub mod store;
86pub(crate) mod subagent;
87pub mod task;
88pub mod telemetry;
89#[cfg(feature = "telemetry")]
90pub mod telemetry_otel;
91pub(crate) mod text;
92pub mod tool_search;
93pub mod tools;
94pub mod undercover;
95
96// Re-export key types at crate root for ergonomic usage
97pub use a3s_lane::MetricsSnapshot;
98pub use agent::{AgentConfig, AgentEvent, AgentLoop, AgentResult};
99pub use agent_api::{Agent, AgentSession, BtwResult, SessionOptions, ToolCallResult};
100pub use agent_teams::{
101    AgentExecutor, AgentTeam, TeamConfig, TeamMember, TeamMemberOptions, TeamMessage, TeamRole,
102    TeamRunResult, TeamRunner, TeamTaskBoard,
103};
104pub use commands::{
105    CommandAction, CommandContext, CommandOutput, CommandRegistry, CronCancelCommand,
106    CronListCommand, LoopCommand, SlashCommand,
107};
108pub use config::{CodeConfig, ModelConfig, ModelCost, ModelLimit, ModelModalities, ProviderConfig};
109pub use error::{CodeError, Result};
110pub use hooks::HookEngine;
111pub use llm::{
112    AnthropicClient, Attachment, ContentBlock, ImageSource, LlmClient, LlmResponse, Message,
113    OpenAiClient, TokenUsage,
114};
115pub use orchestrator::AgentSlot;
116pub use plugin::{Plugin, PluginContext, PluginManager, SkillPlugin};
117pub use prompts::{
118    AgentStyle,
119    DetectionConfidence,
120    PlanningMode,
121    SystemPromptSlots,
122    // Verification agent
123    AGENT_VERIFICATION,
124    AGENT_VERIFICATION_RESTRICTIONS,
125    // Intent classification
126    INTENT_CLASSIFY_SYSTEM,
127    // Prompt suggestion
128    PROMPT_SUGGESTION,
129    // Session memory
130    SESSION_MEMORY_TEMPLATE,
131    // Existing prompts
132    SUBAGENT_EXPLORE,
133    SUBAGENT_PLAN,
134    SUBAGENT_SUMMARY,
135    SUBAGENT_TITLE,
136    // Undercover mode
137    UNDERCOVER_INSTRUCTIONS,
138};
139pub use queue::{
140    ExternalTask, ExternalTaskResult, LaneHandlerConfig, SessionCommand, SessionLane,
141    SessionQueueConfig, SessionQueueStats, TaskHandlerMode,
142};
143pub use sandbox::SandboxConfig;
144pub use scheduler::{CronScheduler, ScheduledFire, ScheduledTask, ScheduledTaskInfo};
145pub use session::{SessionConfig, SessionManager, SessionState};
146pub use session_lane_queue::SessionLaneQueue;
147pub use skills::{builtin_skills, Skill, SkillKind};
148pub use subagent::{load_agents_from_dir, AgentDefinition, AgentRegistry};
149pub use task::manager::TaskEvent;
150pub use task::{
151    AgentProgress, Coordinator, IdlePhase, IdleTask, IdleTurn, ProgressTracker, Task, TaskId,
152    TaskManager, TaskResult, TaskStatus, TaskTokenUsage, TaskType, ToolActivity,
153};
154pub use tool_search::{ToolIndex, ToolMatch, ToolSearchConfig};
155pub use tools::{ToolContext, ToolExecutor, ToolResult};