Skip to main content

HttpAgentAdapter

Trait HttpAgentAdapter 

Source
pub trait HttpAgentAdapter:
    Send
    + Sync
    + 'static {
    // Required methods
    fn provider_name(&self) -> &'static str;
    fn endpoint_url(&self, model: &str) -> String;
    fn auth_headers(&self) -> Vec<(String, String)>;
    fn build_request(&self, config: &AgentConfig) -> Result<Value, AgentError>;
    fn parse_response(
        &self,
        body: &Value,
        config: &AgentConfig,
    ) -> Result<TurnResult, AgentError>;
    fn parse_sse_line(&self, line: &str) -> Option<SseDelta>;
    fn fold_sse_deltas(
        &self,
        deltas: Vec<SseDelta>,
        config: &AgentConfig,
    ) -> Result<TurnResult, AgentError>;
    fn compute_cost(
        &self,
        model: &str,
        input_tokens: u64,
        output_tokens: u64,
    ) -> Option<f64>;
    fn resolve_model(&self, model: &str) -> String;
}
Expand description

Internal trait implemented by each HTTP provider backend.

The generic HttpAgentProvider calls these methods to build requests, parse responses, and configure authentication. The agentic loop, retry, and timeout are handled by the wrapper.

Required Methods§

Source

fn provider_name(&self) -> &'static str

Provider name for logging and errors.

Source

fn endpoint_url(&self, model: &str) -> String

Full endpoint URL for the given model.

Source

fn auth_headers(&self) -> Vec<(String, String)>

Authentication and provider-specific headers.

Source

fn build_request(&self, config: &AgentConfig) -> Result<Value, AgentError>

Build the initial JSON request body from an AgentConfig.

Source

fn parse_response( &self, body: &Value, config: &AgentConfig, ) -> Result<TurnResult, AgentError>

Parse a non-streaming response body into a TurnResult.

Source

fn parse_sse_line(&self, line: &str) -> Option<SseDelta>

Parse a single SSE data: line into a streaming delta.

Source

fn fold_sse_deltas( &self, deltas: Vec<SseDelta>, config: &AgentConfig, ) -> Result<TurnResult, AgentError>

Fold accumulated SSE deltas into a complete TurnResult.

Source

fn compute_cost( &self, model: &str, input_tokens: u64, output_tokens: u64, ) -> Option<f64>

Compute cost in USD from token counts. Returns None if unknown.

Source

fn resolve_model(&self, model: &str) -> String

Resolve model alias (e.g. “sonnet”) to a provider-specific model ID.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§