pub struct Agent { /* private fields */ }Expand description
Multimodal agent for web automation and research.
Designed to be wrapped in Arc for concurrent access.
§Example
use spider_agent::{Agent, AgentConfig};
use std::sync::Arc;
let agent = Arc::new(Agent::builder()
.with_openai("sk-...", "gpt-4o")
.with_search_serper("serper-key")
.build()?);
// Spawn concurrent tasks
let agent_clone = agent.clone();
tokio::spawn(async move {
agent_clone.search("rust web frameworks").await
});Implementations§
Source§impl Agent
impl Agent
Sourcepub fn builder() -> AgentBuilder
pub fn builder() -> AgentBuilder
Create a new agent builder.
Sourcepub async fn prompt(&self, messages: Vec<Message>) -> AgentResult<String>
pub async fn prompt(&self, messages: Vec<Message>) -> AgentResult<String>
Send a prompt to the LLM and get a response.
Sourcepub async fn complete(
&self,
messages: Vec<Message>,
) -> AgentResult<CompletionResponse>
pub async fn complete( &self, messages: Vec<Message>, ) -> AgentResult<CompletionResponse>
Send a completion request with full options.
Sourcepub async fn extract(&self, html: &str, prompt: &str) -> AgentResult<Value>
pub async fn extract(&self, html: &str, prompt: &str) -> AgentResult<Value>
Extract structured data from HTML using the LLM.
Sourcepub async fn extract_structured(
&self,
html: &str,
schema: &Value,
) -> AgentResult<Value>
pub async fn extract_structured( &self, html: &str, schema: &Value, ) -> AgentResult<Value>
Extract data with a JSON schema for structured output.
Sourcepub async fn fetch(&self, url: &str) -> AgentResult<FetchResult>
pub async fn fetch(&self, url: &str) -> AgentResult<FetchResult>
Fetch a URL and return the HTML content.
Sourcepub fn memory_get(&self, key: &str) -> Option<Value>
pub fn memory_get(&self, key: &str) -> Option<Value>
Get a value from memory (lock-free).
Sourcepub fn memory_set(&self, key: &str, value: Value)
pub fn memory_set(&self, key: &str, value: Value)
Set a value in memory (lock-free).
Sourcepub fn memory_clear(&self)
pub fn memory_clear(&self)
Clear all memory (lock-free).
Sourcepub fn memory(&self) -> &AgentMemory
pub fn memory(&self) -> &AgentMemory
Get the memory instance for direct access.
Sourcepub fn usage(&self) -> UsageSnapshot
pub fn usage(&self) -> UsageSnapshot
Get a snapshot of usage statistics.
Sourcepub fn usage_stats(&self) -> &Arc<UsageStats>
pub fn usage_stats(&self) -> &Arc<UsageStats>
Get the raw usage stats for direct access.
Sourcepub fn reset_usage(&self)
pub fn reset_usage(&self)
Reset usage statistics.
Sourcepub fn register_custom_tool(&self, tool: CustomTool)
pub fn register_custom_tool(&self, tool: CustomTool)
Register a custom tool.
Sourcepub fn remove_custom_tool(&self, name: &str) -> bool
pub fn remove_custom_tool(&self, name: &str) -> bool
Remove a custom tool.
Sourcepub fn list_custom_tools(&self) -> Vec<String>
pub fn list_custom_tools(&self) -> Vec<String>
List all registered custom tools.
Sourcepub fn has_custom_tool(&self, name: &str) -> bool
pub fn has_custom_tool(&self, name: &str) -> bool
Check if a custom tool is registered.
Sourcepub async fn execute_custom_tool(
&self,
name: &str,
path: Option<&str>,
query: Option<&[(&str, &str)]>,
body: Option<&str>,
) -> AgentResult<CustomToolResult>
pub async fn execute_custom_tool( &self, name: &str, path: Option<&str>, query: Option<&[(&str, &str)]>, body: Option<&str>, ) -> AgentResult<CustomToolResult>
Execute a custom tool by name.
§Arguments
name- The registered tool namepath- Optional path to append to the base URLquery- Optional query parametersbody- Optional request body
Sourcepub async fn execute_custom_tool_json(
&self,
name: &str,
path: Option<&str>,
query: Option<&[(&str, &str)]>,
body: Option<&str>,
) -> AgentResult<Value>
pub async fn execute_custom_tool_json( &self, name: &str, path: Option<&str>, query: Option<&[(&str, &str)]>, body: Option<&str>, ) -> AgentResult<Value>
Execute a custom tool and parse the JSON response.
Sourcepub fn custom_tool_registry(&self) -> &CustomToolRegistry
pub fn custom_tool_registry(&self) -> &CustomToolRegistry
Get the custom tool registry for direct access.
Sourcepub fn register_spider_cloud(&self, config: SpiderCloudToolConfig) -> usize
pub fn register_spider_cloud(&self, config: SpiderCloudToolConfig) -> usize
Register Spider Cloud routes as custom tools.
Core routes (/crawl, /scrape, /search, /links, /transform,
/unblocker) are enabled by default. AI routes are gated and disabled
by default.
Returns the number of tools registered.