pub struct DeepseekAgent { /* private fields */ }Expand description
An agent that combines a Conversation with a set of callable tools.
Build one with the fluent builder methods, then call chat
to start a turn:
use ds_api::{DeepseekAgent, tool};
use serde_json::{Value, json};
struct MyTool;
#[tool]
impl ds_api::Tool for MyTool {
async fn greet(&self, name: String) -> Value {
json!({ "greeting": format!("Hello, {name}!") })
}
}
let agent = DeepseekAgent::new("sk-...")
.add_tool(MyTool);Implementations§
Source§impl DeepseekAgent
impl DeepseekAgent
Sourcepub fn new(token: impl Into<String>) -> Self
pub fn new(token: impl Into<String>) -> Self
Create a new agent targeting the DeepSeek API with deepseek-chat.
Sourcepub fn custom(
token: impl Into<String>,
base_url: impl Into<String>,
model: impl Into<String>,
) -> Self
pub fn custom( token: impl Into<String>, base_url: impl Into<String>, model: impl Into<String>, ) -> Self
Create an agent targeting an OpenAI-compatible provider.
All three parameters are set at construction time and never change:
use ds_api::DeepseekAgent;
let agent = DeepseekAgent::custom(
"sk-or-...",
"https://openrouter.ai/api/v1",
"meta-llama/llama-3.3-70b-instruct:free",
);Sourcepub fn add_tool<TT: Tool + 'static>(self, tool: TT) -> Self
pub fn add_tool<TT: Tool + 'static>(self, tool: TT) -> Self
Register a tool (builder-style, supports chaining).
The tool’s protocol-level function names are indexed so incoming tool-call requests from the model can be dispatched to the correct implementation.
Sourcepub fn chat(self, user_message: &str) -> AgentStream
pub fn chat(self, user_message: &str) -> AgentStream
Push a user message and return an AgentStream
that drives the full agent loop (API calls + tool execution).
Sourcepub fn with_streaming(self) -> Self
pub fn with_streaming(self) -> Self
Enable SSE streaming for each API turn (builder-style).
Sourcepub fn with_system_prompt(self, prompt: impl Into<String>) -> Self
pub fn with_system_prompt(self, prompt: impl Into<String>) -> Self
Prepend a permanent system prompt to the conversation history (builder-style).
System messages added this way are never removed by the built-in summarizers.
Sourcepub fn with_summarizer(self, summarizer: impl Summarizer + 'static) -> Self
pub fn with_summarizer(self, summarizer: impl Summarizer + 'static) -> Self
Replace the summarizer used for context-window management (builder-style).