Expand description
A3S Code Core Library
Embeddable AI agent library with tool execution capabilities. This crate contains all business logic extracted from the A3S Code agent, enabling direct Rust API usage as an embedded library.
§Quick Start
use a3s_code_core::{Agent, AgentEvent};
// From a config file path (.hcl or .json)
let agent = Agent::new("agent.hcl").await?;
// Create a workspace-bound session
let session = agent.session("/my-project", None)?;
// Non-streaming
let result = session.send("What files handle auth?", None).await?;
println!("{}", result.text);
// Streaming (AgentEvent is #[non_exhaustive])
let (mut rx, _handle) = session.stream("Refactor auth", None).await?;
while let Some(event) = rx.recv().await {
match event {
AgentEvent::TextDelta { text } => print!("{text}"),
AgentEvent::End { .. } => break,
_ => {} // required: #[non_exhaustive]
}
}§Architecture
Agent (facade — config-driven, workspace-independent)
+-- LlmClient (Anthropic / OpenAI)
+-- CodeConfig (HCL / JSON)
+-- SessionManager (multi-session support)
|
+-- AgentSession (workspace-bound)
+-- AgentLoop (core execution engine)
| +-- ToolExecutor (14 tools: 11 builtin + 3 skill discovery)
| +-- LlmPlanner (JSON-structured planning)
| +-- HITL Confirmation
+-- HookEngine (8 lifecycle events)
+-- Security (sanitizer, taint, injection detection, audit)
+-- Memory (episodic, semantic, procedural, working)
+-- MCP (JSON-RPC 2.0, stdio + HTTP+SSE)
+-- Cost Tracking / TelemetryRe-exports§
pub use agent::AgentConfig;pub use agent::AgentEvent;pub use agent::AgentLoop;pub use agent::AgentResult;pub use agent_api::Agent;pub use agent_api::AgentSession;pub use agent_api::BtwResult;pub use agent_api::SessionOptions;pub use agent_api::ToolCallResult;pub use agent_teams::AgentExecutor;pub use agent_teams::AgentTeam;pub use agent_teams::TeamConfig;pub use agent_teams::TeamMember;pub use agent_teams::TeamMemberOptions;pub use agent_teams::TeamMessage;pub use agent_teams::TeamRole;pub use agent_teams::TeamRunResult;pub use agent_teams::TeamRunner;pub use agent_teams::TeamTaskBoard;pub use commands::CommandAction;pub use commands::CommandContext;pub use commands::CommandOutput;pub use commands::CommandRegistry;pub use commands::CronCancelCommand;pub use commands::CronListCommand;pub use commands::LoopCommand;pub use commands::SlashCommand;pub use config::CodeConfig;pub use config::ModelConfig;pub use config::ModelCost;pub use config::ModelLimit;pub use config::ModelModalities;pub use config::ProviderConfig;pub use error::CodeError;pub use error::Result;pub use hooks::HookEngine;pub use llm::AnthropicClient;pub use llm::Attachment;pub use llm::ContentBlock;pub use llm::ImageSource;pub use llm::LlmClient;pub use llm::LlmResponse;pub use llm::Message;pub use llm::OpenAiClient;pub use llm::TokenUsage;pub use orchestrator::AgentSlot;pub use plugin::Plugin;pub use plugin::PluginContext;pub use plugin::PluginManager;pub use plugin::SkillPlugin;pub use queue::ExternalTask;pub use queue::ExternalTaskResult;pub use queue::LaneHandlerConfig;pub use queue::SessionCommand;pub use queue::SessionLane;pub use queue::SessionQueueConfig;pub use queue::SessionQueueStats;pub use queue::TaskHandlerMode;pub use sandbox::SandboxConfig;pub use scheduler::CronScheduler;pub use scheduler::ScheduledFire;pub use scheduler::ScheduledTask;pub use scheduler::ScheduledTaskInfo;pub use session::SessionConfig;pub use session::SessionManager;pub use session::SessionState;pub use session_lane_queue::SessionLaneQueue;pub use skills::builtin_skills;pub use skills::Skill;pub use skills::SkillKind;pub use task::manager::TaskEvent;pub use task::AgentProgress;pub use task::Coordinator;pub use task::IdlePhase;pub use task::IdleTask;pub use task::IdleTurn;pub use task::ProgressTracker;pub use task::Task;pub use task::TaskId;pub use task::TaskManager;pub use task::TaskResult;pub use task::TaskStatus;pub use task::TaskTokenUsage;pub use task::TaskType;pub use task::ToolActivity;pub use tool_search::ToolIndex;pub use tool_search::ToolMatch;pub use tool_search::ToolSearchConfig;pub use tools::ToolContext;pub use tools::ToolExecutor;pub use tools::ToolResult;
Modules§
- agent
- Agent Loop Implementation
- agent_
api - Agent Facade API
- agent_
teams - Agent Teams — Peer-to-peer multi-agent coordination
- commands
- Slash Commands — Interactive session commands
- config
- Configuration module for A3S Code
- context
- Context Provider Extension Point
- error
- Typed error enum for A3S Code Core
- file_
history - File version history tracking
- git
- Git tool — Uses system git with auto-installation support
- hitl
- Human-in-the-Loop (HITL) confirmation mechanism
- hooks
- Hooks System for A3S Code Agent
- llm
- LLM client abstraction layer
- mcp
- MCP (Model Context Protocol) Support
- memory
- Memory and learning system for the agent.
- orchestrator
- Agent Orchestrator - 主子智能体协调器
- permissions
- Permission system for tool execution control
- planning
- Planning, Goal Tracking, and Task Management
- plugin
- Plugin System for A3S Code
- queue
- Per-session command queue with lane-based priority scheduling
- sandbox
- Sandbox integration for bash tool execution.
- scheduler
- Session-scoped prompt scheduler — backs
/loop,/cron-list,/cron-cancel. - security
- Security Module
- session
- Session management
- session_
lane_ queue - Session Lane Queue - a3s-lane backed command queue
- skills
- Skill System
- store
- Session persistence layer
- task
- Task Lifecycle Management
- telemetry
- Telemetry Module (Core)
- tool_
search - Tool Search — Semantic tool matching for dynamic MCP tool loading
- tools
- Extensible Tool System
- undercover
- Undercover mode for safe public repository operations
Structs§
- Agent
Definition - Agent definition
- Agent
Registry - Agent registry for managing agent definitions
- Metrics
Snapshot - Snapshot of all metrics at a point in time
- System
Prompt Slots - Slot-based system prompt customization with intent-based style selection.
Enums§
- Agent
Style - Agent style — determines which system prompt template is used.
- Detection
Confidence - Detection confidence level for style detection.
- Planning
Mode - Planning mode — controls when planning phase is used.
Constants§
- AGENT_
VERIFICATION - Verification agent — adversarial specialist that tries to break code
- AGENT_
VERIFICATION_ RESTRICTIONS - Tool restrictions for verification agent
- INTENT_
CLASSIFY_ SYSTEM - System prompt for LLM-based intent classification
- PROMPT_
SUGGESTION - Prompt suggestion service with filtering rules
- SESSION_
MEMORY_ TEMPLATE - Session memory template with structured sections
- SUBAGENT_
EXPLORE - Explore subagent — read-only codebase exploration
- SUBAGENT_
PLAN - Plan subagent — read-only planning and analysis
- SUBAGENT_
SUMMARY - Summary subagent — summarize conversation key points
- SUBAGENT_
TITLE - Title subagent — generate concise conversation title
- UNDERCOVER_
INSTRUCTIONS - Undercover mode instructions for commit/PR prompts
Functions§
- load_
agents_ from_ dir - Load all agent definitions from a directory