Skip to main content

Crate ai_agent

Crate ai_agent 

Source

Re-exports§

pub use types::ids::AgentId;
pub use utils::AbortController;
pub use utils::AbortSignal;
pub use utils::create_abort_controller;
pub use utils::create_abort_controller_default;
pub use utils::create_agent_id;
pub use utils::create_child_abort_controller;
pub use utils::get_aws_region;
pub use utils::get_claude_config_home_dir;
pub use utils::get_cwd;
pub use utils::get_default_vertex_region;
pub use utils::get_original_cwd;
pub use utils::get_teams_dir;
pub use utils::get_vertex_region_for_model;
pub use utils::has_node_option;
pub use utils::is_bare_mode;
pub use utils::is_env_defined_falsy;
pub use utils::is_env_truthy;
pub use utils::is_in_protected_namespace;
pub use utils::is_running_on_homespace;
pub use utils::parse_env_vars;
pub use utils::pwd;
pub use utils::run_with_cwd_override;
pub use utils::set_cwd;
pub use utils::should_maintain_project_working_dir;
pub use utils::validate_uuid;
pub use agent::Agent;
pub use ai_md::AI_MD_INSTRUCTION_PROMPT;
pub use ai_md::AiMdContent;
pub use ai_md::AiMdFile;
pub use ai_md::AiMdType;
pub use ai_md::MAX_AI_MD_CHARACTER_COUNT;
pub use ai_md::get_ai_md_files;
pub use ai_md::load_ai_md;
pub use ai_md::process_ai_md_file;
pub use bridge_enabled::OauthAccountInfo;
pub use bridge_enabled::check_bridge_min_version;
pub use bridge_enabled::get_bridge_disabled_reason;
pub use bridge_enabled::get_ccr_auto_connect_default;
pub use bridge_enabled::is_bridge_enabled;
pub use bridge_enabled::is_bridge_enabled_blocking;
pub use bridge_enabled::is_ccr_mirror_enabled;
pub use bridge_enabled::is_cse_shim_enabled;
pub use bridge_enabled::is_env_less_bridge_enabled;
pub use compact::AUTOCOMPACT_BUFFER_TOKENS;
pub use compact::CompactCommand;
pub use compact::ERROR_THRESHOLD_BUFFER_TOKENS;
pub use compact::MANUAL_COMPACT_BUFFER_TOKENS;
pub use compact::MAX_CONSECUTIVE_AUTOCOMPACT_FAILURES;
pub use compact::TokenWarningState;
pub use compact::WARNING_THRESHOLD_BUFFER_TOKENS;
pub use compact::calculate_token_warning_state;
pub use compact::compact_errors;
pub use compact::estimate_token_count;
pub use compact::get_auto_compact_threshold;
pub use compact::get_compact_command;
pub use compact::get_effective_context_window_size;
pub use compact::should_compact;
pub use env::EnvConfig;
pub use env::is_assistant_mode;
pub use env::is_assistant_mode_enabled;
pub use error::AgentError;
pub use extract_memories::ExtractMemoriesConfig;
pub use extract_memories::ExtractMemoriesResult;
pub use extract_memories::ExtractMemoriesState;
pub use extract_memories::MemoryEntry;
pub use extract_memories::MemoryEntryType;
pub use extract_memories::PendingExtraction;
pub use extract_memories::build_extract_auto_only_prompt;
pub use extract_memories::build_extract_combined_prompt;
pub use extract_memories::count_model_visible_messages_since;
pub use extract_memories::count_tool_calls;
pub use extract_memories::create_auto_mem_can_use_tool;
pub use extract_memories::drain_pending_extractions;
pub use extract_memories::execute_extract_memories;
pub use extract_memories::parse_extracted_content;
pub use extract_memories::should_extract_memories;
pub use hooks::CONFIG_CHANGE_SOURCES;
pub use hooks::EXIT_REASONS;
pub use hooks::HOOK_EVENTS;
pub use hooks::HookConfig;
pub use hooks::HookDefinition;
pub use hooks::HookInput;
pub use hooks::HookOutput;
pub use hooks::HookRegistry;
pub use hooks::INSTRUCTIONS_LOAD_REASONS;
pub use hooks::INSTRUCTIONS_MEMORY_TYPES;
pub use hooks::create_hook_registry;
pub use memdir::EntrypointTruncation;
pub use memdir::MAX_ENTRYPOINT_LINES;
pub use memdir::MemoryFrontmatter;
pub use memdir::MemoryType;
pub use memdir::ensure_memory_dir_exists;
pub use memdir::get_auto_mem_path;
pub use memdir::get_memory_base_dir;
pub use memdir::get_memory_entrypoint;
pub use memdir::is_auto_mem_path;
pub use memdir::is_auto_memory_enabled;
pub use memdir::load_memory_prompt_sync;
pub use message_queue_types::MessageQueueEntry;
pub use permission::PermissionAllowDecision;
pub use permission::PermissionAskDecision;
pub use permission::PermissionBehavior;
pub use permission::PermissionContext;
pub use permission::PermissionDecision;
pub use permission::PermissionDecisionReason;
pub use permission::PermissionDenyDecision;
pub use permission::PermissionHandler;
pub use permission::PermissionMetadata;
pub use permission::PermissionMode;
pub use permission::PermissionResult;
pub use permission::PermissionRule;
pub use permission::PermissionRuleSource;
pub use plugin::BUILTIN_MARKETPLACE_NAME_CONST;
pub use plugin::clear_builtin_plugins;
pub use plugin::get_builtin_plugin_definition;
pub use plugin::get_builtin_plugin_skill_definitions;
pub use plugin::get_builtin_plugins;
pub use plugin::is_builtin_plugin_id;
pub use plugin::register_builtin_plugin;
pub use plugin::BuiltinPluginResult;
pub use plugin::CommandAvailability;
pub use plugin::CommandMetadata;
pub use plugin::CommandRegistry;
pub use plugin::CommandResult;
pub use plugin::CommandResultDisplay;
pub use plugin::CommandSource;
pub use plugin::LoadedPlugin;
pub use plugin::PluginAuthor;
pub use plugin::PluginCommand;
pub use plugin::PluginComponent;
pub use plugin::PluginConfig;
pub use plugin::PluginError;
pub use plugin::PluginLoadResult;
pub use plugin::PluginManifest;
pub use plugin::PluginMcpServer;
pub use plugin::PluginMcpServerManager;
pub use plugin::PluginRepository;
pub use plugin::PluginSkill;
pub use plugin::get_plugin_error_message;
pub use plugin::load_plugin;
pub use plugin::load_plugin_skills;
pub use plugin::load_plugins_from_dir;
pub use plugin::load_plugins_from_sources;
pub use plugin::register_plugin_skills;
pub use services::compact::auto_compact::AutoCompactResult;
pub use services::compact::auto_compact::AutoCompactTrackingState;
pub use services::compact::auto_compact::RecompactionInfo;
pub use services::compact::auto_compact::is_auto_compact_enabled;
pub use services::compact::auto_compact::should_auto_compact;
pub use services::api::retry_helpers::is_connection_error;
pub use services::api::retry_helpers::is_max_tokens_overflow as is_max_tokens_overflow_error;
pub use services::api::retry_helpers::is_server_error;
pub use services::api::with_retry::DEFAULT_MAX_RETRIES as API_DEFAULT_MAX_RETRIES;
pub use services::api::with_retry::FLOOR_OUTPUT_TOKENS;
pub use services::api::with_retry::MAX_529_RETRIES;
pub use services::api::with_retry::RetryConfig as ApiRetryConfig;
pub use services::api::with_retry::extract_retry_after_ms;
pub use services::api::with_retry::get_retry_delay;
pub use services::api::with_retry::is_529_error;
pub use services::api::with_retry::parse_max_tokens_overflow;
pub use services::api::with_retry::retry_post;
pub use services::api::with_retry::should_retry;
pub use services::api::with_retry::with_retry;
pub use services::api::API_ERROR_MESSAGE_PREFIX;
pub use services::api::API_TIMEOUT_ERROR_MESSAGE;
pub use services::api::ApiErrorMessage;
pub use services::api::ApiErrorType;
pub use services::api::CCR_AUTH_ERROR_MESSAGE;
pub use services::api::CREDIT_BALANCE_TOO_LOW_ERROR_MESSAGE;
pub use services::api::CUSTOM_OFF_SWITCH_MESSAGE;
pub use services::api::INVALID_API_KEY_ERROR_MESSAGE;
pub use services::api::INVALID_API_KEY_ERROR_MESSAGE_EXTERNAL;
pub use services::api::NO_RESPONSE_REQUESTED;
pub use services::api::OAUTH_ORG_NOT_ALLOWED_ERROR_MESSAGE;
pub use services::api::ORG_DISABLED_ERROR_MESSAGE_ENV_KEY;
pub use services::api::ORG_DISABLED_ERROR_MESSAGE_ENV_KEY_WITH_OAUTH;
pub use services::api::PROMPT_TOO_LONG_ERROR_MESSAGE;
pub use services::api::REPEATED_529_ERROR_MESSAGE;
pub use services::api::SDKAssistantMessageError;
pub use services::api::TOKEN_REVOKED_ERROR_MESSAGE;
pub use services::api::categorize_retryable_api_error;
pub use services::api::classify_api_error;
pub use services::api::create_assistant_api_error_message;
pub use services::api::create_assistant_api_error_message_with_options;
pub use services::api::extract_unknown_error_format;
pub use services::api::get_error_message_if_refusal;
pub use services::api::get_image_too_large_error_message;
pub use services::api::get_oauth_org_not_allowed_error_message;
pub use services::api::get_pdf_invalid_error_message;
pub use services::api::get_pdf_password_protected_error_message;
pub use services::api::get_pdf_too_large_error_message;
pub use services::api::get_prompt_too_long_token_gap;
pub use services::api::get_request_too_large_error_message;
pub use services::api::get_token_revoked_error_message;
pub use services::api::is_ccr_mode;
pub use services::api::is_media_size_error;
pub use services::api::is_media_size_error_message;
pub use services::api::is_prompt_too_long_message;
pub use services::api::is_valid_api_message;
pub use services::api::parse_prompt_too_long_token_counts;
pub use services::api::starts_with_api_error_prefix;
pub use services::model_cost::COST_HAIKU_35;
pub use services::model_cost::COST_HAIKU_45;
pub use services::model_cost::COST_TIER_3_15;
pub use services::model_cost::COST_TIER_5_25;
pub use services::model_cost::COST_TIER_15_75;
pub use services::model_cost::CostSummary;
pub use services::model_cost::ModelCostRegistry;
pub use services::model_cost::ModelCosts;
pub use services::model_cost::ModelInfo;
pub use services::model_cost::TokenUsage;
pub use services::model_cost::calculate_cost;
pub use services::model_cost::format_cost;
pub use services::model_cost::get_available_models;
pub use services::rate_limit::RateLimit as RateLimitInfo;
pub use services::rate_limit::RateLimitConfig;
pub use services::rate_limit::RateLimitStatus;
pub use services::rate_limit::RateLimiter;
pub use services::rate_limit::RateLimiterBuilder;
pub use services::retry::DEFAULT_MAX_RETRIES;
pub use services::retry::RetryConfig;
pub use services::retry::RetryError;
pub use services::retry::is_rate_limit_error;
pub use services::retry::is_retryable_error;
pub use services::retry::is_service_unavailable_error;
pub use services::retry::retry_async;
pub use services::retry::retry_with_retry_after;
pub use services::token_estimation::EstimationMethod;
pub use services::token_estimation::TokenEstimate;
pub use services::token_estimation::calculate_padding;
pub use services::token_estimation::estimate_conversation;
pub use services::token_estimation::estimate_tokens;
pub use services::token_estimation::estimate_tokens_characters;
pub use services::token_estimation::estimate_tokens_words;
pub use services::token_estimation::estimate_tool_definitions;
pub use services::token_estimation::fits_in_context;
pub use session::SessionData;
pub use session::SessionMetadata;
pub use session::append_to_session;
pub use session::delete_session;
pub use session::fork_session;
pub use session::get_session_info;
pub use session::get_session_messages;
pub use session::list_sessions;
pub use session::load_session;
pub use session::rename_session;
pub use session::save_session;
pub use session::tag_session;
pub use session_discovery::discover_assistant_sessions;
pub use session_history::HISTORY_PAGE_SIZE;
pub use session_history::HistoryAuthCtx;
pub use session_history::HistoryPage;
pub use session_history::OAuthTokens;
pub use session_history::OauthConfig;
pub use session_history::SDKMessage;
pub use session_history::create_history_auth_ctx;
pub use session_history::fetch_latest_events;
pub use session_history::fetch_older_events;
pub use session_history::get_bridge_access_token;
pub use session_history::get_bridge_base_url;
pub use session_history::get_bridge_base_url_override;
pub use session_history::get_bridge_headers;
pub use session_history::get_bridge_token_override;
pub use session_history::get_oauth_headers;
pub use session_history::prepare_api_request;
pub use session_memory::DEFAULT_SESSION_MEMORY_CONFIG;
pub use session_memory::ManualExtractionResult;
pub use session_memory::SessionMemoryConfig;
pub use session_memory::get_last_summarized_message_id;
pub use session_memory::get_session_memory_config;
pub use session_memory::get_session_memory_content;
pub use session_memory::get_session_memory_dir;
pub use session_memory::get_session_memory_path;
pub use session_memory::get_tool_calls_between_updates;
pub use session_memory::has_met_initialization_threshold;
pub use session_memory::has_met_update_threshold;
pub use session_memory::init_session_memory_file;
pub use session_memory::is_session_memory_initialized;
pub use session_memory::mark_session_memory_initialized;
pub use session_memory::record_extraction_token_count;
pub use session_memory::reset_session_memory_state;
pub use session_memory::set_last_summarized_message_id;
pub use session_memory::set_session_memory_config;
pub use session_memory::should_extract_memory;
pub use session_memory::wait_for_session_memory_extraction;
pub use skills::BundledSkill;
pub use skills::LoadedSkill;
pub use skills::SkillMetadata;
pub use skills::get_bundled_skills;
pub use skills::init_bundled_skills;
pub use skills::load_skill_from_dir;
pub use skills::load_skills_from_dir;
pub use state::Store;
pub use stream::CancelGuard;
pub use stream::EventSubscriber;
pub use task::LocalShellSpawnInput;
pub use task::ShellKind;
pub use task::TASK_ID_ALPHABET;
pub use task::TASK_ID_PREFIXES;
pub use task::TaskHandle;
pub use task::TaskStateBase;
pub use task::TaskStatus;
pub use task::TaskType;
pub use task::create_task_state_base;
pub use task::generate_task_id;
pub use task::get_task_id_prefix;
pub use task::get_task_output_path;
pub use task::is_terminal_task_status;
pub use team_memory::MAX_CONFLICT_RETRIES;
pub use team_memory::MAX_FILE_SIZE_BYTES;
pub use team_memory::MAX_PUT_BODY_BYTES;
pub use team_memory::MAX_RETRIES;
pub use team_memory::SkippedSecretFile;
pub use team_memory::SyncState;
pub use team_memory::TEAM_MEMORY_SYNC_TIMEOUT_MS;
pub use team_memory::TeamMemoryContent;
pub use team_memory::TeamMemoryData;
pub use team_memory::TeamMemoryHashesResult;
pub use team_memory::TeamMemorySyncFetchResult;
pub use team_memory::TeamMemorySyncPushResult;
pub use team_memory::TeamMemorySyncUploadResult;
pub use team_memory::TeamMemoryTooManyEntries;
pub use team_memory::batch_delta_by_bytes;
pub use team_memory::compute_delta;
pub use team_memory::create_sync_state;
pub use team_memory::delete_local_team_memory_entry;
pub use team_memory::disable_team_memory;
pub use team_memory::enable_team_memory;
pub use team_memory::get_last_sync_error;
pub use team_memory::get_team_memory_dir;
pub use team_memory::get_team_memory_path;
pub use team_memory::hash_content;
pub use team_memory::is_team_memory_enabled;
pub use team_memory::is_team_memory_sync_available;
pub use team_memory::pull_team_memory;
pub use team_memory::push_team_memory;
pub use team_memory::read_local_team_memory;
pub use team_memory::scan_entries_for_secrets;
pub use team_memory::scan_for_secrets;
pub use team_memory::set_last_sync_error;
pub use team_memory::sync_team_memory;
pub use team_memory::validate_team_memory_key;
pub use team_memory::write_local_team_memory;
pub use tool_helper::SdkToolDefinition;
pub use tool_helper::ToolAnnotations;
pub use tool_helper::create_tool;
pub use tool_helper::create_tool_with_annotations;
pub use tool_helper::sdk_tool_to_tool_definition;
pub use tools::Tool;
pub use tools::ToolDefinition;
pub use tools::ToolFuture;
pub use tools::ToolInputSchema;
pub use tools::filter_tools;
pub use tools::get_all_base_tools;
pub use user_agent::get_claude_code_user_agent;
pub use coordinator::WORKER_AGENT;
pub use coordinator::apply_coordinator_tool_filter;
pub use coordinator::get_coordinator_system_prompt;
pub use coordinator::get_coordinator_user_context;
pub use coordinator::is_coordinator_mode;
pub use coordinator::is_pr_activity_subscription_tool;
pub use coordinator::match_session_mode;
pub use types::*;

Modules§

agent
ai_md
AI.md instruction file loading system
analytics
bootstrap
bridge
Bridge module for Remote Control functionality.
bridge_enabled
Bridge mode entitlement checks.
cli_ndjson_safe_stringify
NDJSON-safe JSON serialization.
commands
compact
Context compaction module.
constants
Constants module for ai-agent-sdk
coordinator
cost
env
ENV configuration reader
error
extract_memories
Extract Memories - ported from ~/claudecode/openclaudecode/src/services/extractMemories/
hooks
http_client
interact
mcp
MCP module - re-exports MCP types from types.rs
memdir
Memory directory system - persistent file-based memory for the agent.
memory_types
message_queue_types
Message queue types
permission
Permission management for agent tool access control.
plugin
Plugin module - ported from ~/claudecode/openclaudecode/src/types/plugin.ts
prompts
System prompt constants - COMPLETE translation from TypeScript Translated from openclaudecode/src/constants/prompts.ts (914 lines) Last verified: 2026-04-05
review
services
Service modules for agent functionality.
session
session_discovery
Session discovery for assistant sessions - discover sessions from the remote API
session_history
session_memory
Session memory - backward-compatible re-export of [services::session_memory].
session_restore
Session restore functionality for resuming conversations from NDJSON transcripts.
session_state
Session state machine for tracking agent lifecycle.
skills
Skills module - ported from ~/claudecode/openclaudecode/src/skills
state
State management utilities
stream
streaming_tool_executor
Streaming tool executor that starts executing tools as they stream in from the API.
task
Task types and utilities translated from TypeScript Task.ts
tasks
team_memory
Team Memory Sync - ported from ~/claudecode/openclaudecode/src/services/teamMemorySync/
token_budget
tool
Tool type definitions, traits, and utilities translated from the TypeScript SDK.
tool_errors
Tool error formatting utilities.
tool_helper
tool_result_storage
Tool result size management and disk persistence for large outputs.
tool_validation
Input validation for tool calls.
tools
types
Type definitions module for ai-agent-sdk
user_agent
User-Agent string helpers (legacy re-exports for backwards compat).
utils
Utility modules

Macros§

placeholder_tool
Macro to create a simple placeholder tool struct with Default trait Usage: placeholder_tool!(MonitorTool); This creates: struct MonitorTool, impl with new() -> Self, impl Default

Constants§

MACRO_VERSION
Build-time version constant (matches TypeScript MACRO.VERSION)

Functions§

get_all_tools
Alias for get_all_base_tools to match TypeScript API