spider_agent/lib.rs
1//! # Spider Agent
2//!
3//! A concurrent-safe multimodal agent for web automation and research.
4//!
5//! ## Features
6//!
7//! - **Concurrent-safe**: Designed to be wrapped in `Arc` for multi-task access
8//! - **Feature-gated**: Only include dependencies you need
9//! - **Multiple LLM providers**: OpenAI, OpenAI-compatible APIs
10//! - **Multiple search providers**: Serper, Brave, Bing, Tavily
11//! - **Browser automation**: Chrome support via chromiumoxide
12//!
13//! ## Quick Start
14//!
15//! ```rust,ignore
16//! use spider_agent::{Agent, AgentConfig};
17//! use std::sync::Arc;
18//!
19//! #[tokio::main]
20//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
21//! let agent = Arc::new(Agent::builder()
22//! .with_openai("sk-...", "gpt-4o-mini")
23//! .with_search_serper("serper-key")
24//! .build()?);
25//!
26//! // Search
27//! let results = agent.search("rust web frameworks").await?;
28//! println!("Found {} results", results.len());
29//!
30//! // Extract from first result
31//! let html = agent.fetch(&results.results[0].url).await?.html;
32//! let data = agent.extract(&html, "Extract framework name and features").await?;
33//! println!("{}", serde_json::to_string_pretty(&data)?);
34//!
35//! Ok(())
36//! }
37//! ```
38//!
39//! ## Concurrent Execution
40//!
41//! ```rust,ignore
42//! use spider_agent::Agent;
43//! use std::sync::Arc;
44//!
45//! let agent = Arc::new(Agent::builder()
46//! .with_openai("sk-...", "gpt-4o")
47//! .with_search_serper("serper-key")
48//! .with_max_concurrent_llm_calls(10)
49//! .build()?);
50//!
51//! // Execute multiple searches concurrently
52//! let queries = vec!["rust async", "rust web frameworks", "rust databases"];
53//! let mut handles = Vec::new();
54//!
55//! for query in queries {
56//! let agent = agent.clone();
57//! let query = query.to_string();
58//! handles.push(tokio::spawn(async move {
59//! agent.search(&query).await
60//! }));
61//! }
62//!
63//! // Collect results
64//! for handle in handles {
65//! let result = handle.await??;
66//! println!("Found {} results", result.results.len());
67//! }
68//! ```
69//!
70//! ## Feature Flags
71//!
72//! - `openai` - OpenAI/OpenAI-compatible LLM provider
73//! - `chrome` - Browser automation via chromiumoxide
74//! - `search` - Base search functionality
75//! - `search_serper` - Serper.dev search provider
76//! - `search_brave` - Brave Search provider
77//! - `search_bing` - Bing Search provider
78//! - `search_tavily` - Tavily AI Search provider
79//! - `full` - All features
80
81#![warn(missing_docs)]
82
83mod agent;
84pub mod automation;
85mod config;
86mod error;
87mod llm;
88mod memory;
89
90#[cfg(feature = "search")]
91pub mod search;
92
93#[cfg(feature = "chrome")]
94pub mod browser;
95
96#[cfg(feature = "webdriver")]
97pub mod webdriver;
98
99#[cfg(feature = "fs")]
100pub mod temp;
101
102// Re-exports
103pub use agent::{Agent, AgentBuilder, FetchResult, PageExtraction};
104pub use config::{AgentConfig, HtmlCleaningMode, ResearchOptions, RetryConfig, SearchOptions, TimeRange, UsageSnapshot, UsageStats};
105pub use error::{AgentError, AgentResult, SearchError};
106pub use llm::{CompletionOptions, CompletionResponse, LLMProvider, Message, MessageContent, TokenUsage};
107pub use memory::AgentMemory;
108
109// Automation re-exports
110pub use automation::{
111 ActionRecord, ActionResult, ActionType, AutomationConfig, AutomationResult, AutomationUsage,
112 CaptureProfile, ChainBuilder, ChainCondition, ChainContext, ChainResult, ChainStep,
113 ChainStepResult, CleaningIntent, ContentAnalysis, CostTier, ExtractionSchema, FormField,
114 FormInfo, HtmlCleaningProfile, InteractiveElement, ModelPolicy, NavigationOption,
115 PageObservation, RecoveryStrategy, RetryPolicy, SelectorCache, SelectorCacheEntry,
116 StructuredOutputConfig,
117};
118
119// Performance re-exports
120pub use automation::cache::{CacheStats, CacheValue, SmartCache};
121pub use automation::executor::{BatchExecutor, ChainExecutor, PrefetchManager};
122pub use automation::router::{ModelRouter, RoutingDecision, TaskAnalysis, TaskCategory};
123
124#[cfg(feature = "search")]
125pub use agent::ResearchResult;
126
127#[cfg(feature = "search")]
128pub use search::{SearchProvider, SearchResult, SearchResults};
129
130#[cfg(feature = "openai")]
131pub use llm::OpenAIProvider;
132
133#[cfg(feature = "search_serper")]
134pub use search::SerperProvider;
135
136#[cfg(feature = "search_brave")]
137pub use search::BraveProvider;
138
139#[cfg(feature = "search_bing")]
140pub use search::BingProvider;
141
142#[cfg(feature = "search_tavily")]
143pub use search::TavilyProvider;
144
145#[cfg(feature = "chrome")]
146pub use browser::BrowserContext;
147
148#[cfg(feature = "webdriver")]
149pub use webdriver::WebDriverContext;
150
151#[cfg(feature = "fs")]
152pub use temp::{TempStorage, TempFile};