Skip to main content

Agent

Struct Agent 

Source
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

Source

pub fn builder() -> AgentBuilder

Create a new agent builder.

Source

pub fn client(&self) -> &Client

Returns a reference to the underlying HTTP client.

Source

pub async fn prompt(&self, messages: Vec<Message>) -> AgentResult<String>

Send a prompt to the LLM and get a response.

Source

pub async fn complete( &self, messages: Vec<Message>, ) -> AgentResult<CompletionResponse>

Send a completion request with full options.

Source

pub async fn extract(&self, html: &str, prompt: &str) -> AgentResult<Value>

Extract structured data from HTML using the LLM.

Source

pub async fn extract_structured( &self, html: &str, schema: &Value, ) -> AgentResult<Value>

Extract data with a JSON schema for structured output.

Source

pub async fn fetch(&self, url: &str) -> AgentResult<FetchResult>

Fetch a URL and return the HTML content.

Source

pub fn memory_get(&self, key: &str) -> Option<Value>

Get a value from memory (lock-free).

Source

pub fn memory_set(&self, key: &str, value: Value)

Set a value in memory (lock-free).

Source

pub fn memory_clear(&self)

Clear all memory (lock-free).

Source

pub fn memory(&self) -> &AgentMemory

Get the memory instance for direct access.

Source

pub fn usage(&self) -> UsageSnapshot

Get a snapshot of usage statistics.

Source

pub fn usage_stats(&self) -> &Arc<UsageStats>

Get the raw usage stats for direct access.

Source

pub fn reset_usage(&self)

Reset usage statistics.

Source

pub fn register_custom_tool(&self, tool: CustomTool)

Register a custom tool.

Source

pub fn remove_custom_tool(&self, name: &str) -> bool

Remove a custom tool.

Source

pub fn list_custom_tools(&self) -> Vec<String>

List all registered custom tools.

Source

pub fn has_custom_tool(&self, name: &str) -> bool

Check if a custom tool is registered.

Source

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 name
  • path - Optional path to append to the base URL
  • query - Optional query parameters
  • body - Optional request body
Source

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.

Source

pub fn custom_tool_registry(&self) -> &CustomToolRegistry

Get the custom tool registry for direct access.

Source

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.

Auto Trait Implementations§

§

impl Freeze for Agent

§

impl !RefUnwindSafe for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl UnsafeUnpin for Agent

§

impl !UnwindSafe for Agent

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more