SDK sausage-actor; examples and agent on the SDK; agent without limits
- sausage-actor: Message, messages(), send/reply/publish, async Inbox - agent: append-only /data/history.jsonl, no caps on history, steps, waits, tool output, or reads; max_tokens only when configured (Anthropic: 32000)
This commit is contained in:
+8
-15
@@ -6,7 +6,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Value, json};
|
||||
use wstd::http::{Body, Client, Request};
|
||||
use wstd::time::Duration;
|
||||
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct Config {
|
||||
@@ -18,12 +17,8 @@ pub struct Config {
|
||||
/// Optional reasoning effort for OpenAI models ("low", "medium", ...).
|
||||
#[serde(default)]
|
||||
pub reasoning_effort: Option<String>,
|
||||
#[serde(default = "default_max_tokens")]
|
||||
pub max_tokens: u32,
|
||||
}
|
||||
|
||||
fn default_max_tokens() -> u32 {
|
||||
16000
|
||||
#[serde(default)]
|
||||
pub max_tokens: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
@@ -57,17 +52,13 @@ async fn post(url: &str, headers: &[(&str, String)], body: &Value) -> Result<Val
|
||||
req = req.header(*k, v.as_str());
|
||||
}
|
||||
let req = req.body(Body::from(body.to_string())).map_err(|e| format!("request: {e}"))?;
|
||||
let mut client = Client::new();
|
||||
client.set_first_byte_timeout(Duration::from_secs(600));
|
||||
client.set_between_bytes_timeout(Duration::from_secs(600));
|
||||
let client = Client::new();
|
||||
let resp = client.send(req).await.map_err(|e| format!("HTTP request failed: {e:?}"))?;
|
||||
let status = resp.status();
|
||||
let mut body = resp.into_body();
|
||||
let text = body.str_contents().await.map_err(|e| format!("reading the response failed: {e:?}"))?.to_string();
|
||||
if !status.is_success() {
|
||||
let mut t = text;
|
||||
t.truncate(2000);
|
||||
return Err(format!("HTTP {status}: {t}"));
|
||||
return Err(format!("HTTP {status}: {text}"));
|
||||
}
|
||||
serde_json::from_str(&text).map_err(|e| format!("invalid JSON in response: {e}"))
|
||||
}
|
||||
@@ -99,8 +90,10 @@ async fn openai(cfg: &Config, system: &str, tools: &[Tool], history: &[Entry]) -
|
||||
"tools": tools,
|
||||
"store": false,
|
||||
"include": ["reasoning.encrypted_content"],
|
||||
"max_output_tokens": cfg.max_tokens,
|
||||
});
|
||||
if let Some(max_tokens) = cfg.max_tokens {
|
||||
body["max_output_tokens"] = json!(max_tokens);
|
||||
}
|
||||
if let Some(effort) = &cfg.reasoning_effort {
|
||||
body["reasoning"] = json!({"effort": effort});
|
||||
}
|
||||
@@ -170,7 +163,7 @@ async fn anthropic(cfg: &Config, system: &str, tools: &[Tool], history: &[Entry]
|
||||
"system": system,
|
||||
"messages": messages,
|
||||
"tools": tools,
|
||||
"max_tokens": cfg.max_tokens,
|
||||
"max_tokens": cfg.max_tokens.unwrap_or(32000),
|
||||
});
|
||||
let url = format!("{}/v1/messages", cfg.base_url);
|
||||
let resp = post(
|
||||
|
||||
Reference in New Issue
Block a user