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    clear_http_metrics_callback, set_http_metrics_callback, AnthropicClient, Attachment,
113    ContentBlock, HttpMetricsCallback, HttpMetricsRecord, ImageSource, LlmClient, LlmResponse,
114    Message, OpenAiClient, TokenUsage,
115};
116pub use orchestrator::AgentSlot;
117pub use plugin::{Plugin, PluginContext, PluginManager, SkillPlugin};
118pub use prompts::{
119    AgentStyle,
120    DetectionConfidence,
121    PlanningMode,
122    SystemPromptSlots,
123    // Verification agent
124    AGENT_VERIFICATION,
125    AGENT_VERIFICATION_RESTRICTIONS,
126    // Intent classification
127    INTENT_CLASSIFY_SYSTEM,
128    // Prompt suggestion
129    PROMPT_SUGGESTION,
130    // Session memory
131    SESSION_MEMORY_TEMPLATE,
132    // Existing prompts
133    SUBAGENT_EXPLORE,
134    SUBAGENT_PLAN,
135    SUBAGENT_SUMMARY,
136    SUBAGENT_TITLE,
137    // Undercover mode
138    UNDERCOVER_INSTRUCTIONS,
139};
140pub use queue::{
141    ExternalTask, ExternalTaskResult, LaneHandlerConfig, SessionCommand, SessionLane,
142    SessionQueueConfig, SessionQueueStats, TaskHandlerMode,
143};
144pub use sandbox::SandboxConfig;
145pub use scheduler::{CronScheduler, ScheduledFire, ScheduledTask, ScheduledTaskInfo};
146pub use session::{SessionConfig, SessionManager, SessionState};
147pub use session_lane_queue::SessionLaneQueue;
148pub use skills::{builtin_skills, Skill, SkillKind};
149pub use subagent::{load_agents_from_dir, AgentDefinition, AgentRegistry};
150pub use task::manager::TaskEvent;
151pub use task::{
152    AgentProgress, Coordinator, IdlePhase, IdleTask, IdleTurn, ProgressTracker, Task, TaskId,
153    TaskManager, TaskResult, TaskStatus, TaskTokenUsage, TaskType, ToolActivity,
154};
155pub use tool_search::{ToolIndex, ToolMatch, ToolSearchConfig};
156pub use tools::{ToolContext, ToolExecutor, ToolResult};