Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(tests): update agent harness model registration

Steven Enamakelb8ef910d4323
diff --git a/crates/openhuman-core/src/agent/tinyagents/nested_calls_tests.rs b/crates/openhuman-core/src/agent/tinyagents/nested_calls_tests.rs
index 8c485da0b7..41cf90190f 100644
--- a/crates/openhuman-core/src/agent/tinyagents/nested_calls_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/nested_calls_tests.rs
@@ -158,7 +158,7 @@ async fn run_with_hooks(target: &'static str) -> (Option<Outcome>, usize, usize)
let (secret, secret_ran) = leaf("secret");
let outcome = Arc::new(Mutex::new(None));
let mut harness: AgentHarness<(), OpenHumanRunContext> = AgentHarness::new();
- harness.register_model("mock", model());
+ harness.with_model( model());
harness.with_policy(nested_enabled());
harness.register_tool(allowed);
harness.register_tool(secret);
diff --git a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer_tests.rs b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer_tests.rs
index 23f1c0665c..51ab0f0ffe 100644
--- a/crates/openhuman-core/src/agent/tinyagents/payload_summarizer_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/payload_summarizer_tests.rs
@@ -108,8 +108,8 @@ async fn unary_summarizer_child_keeps_summary_output_off_the_streaming_path() {
let model = Arc::new(UnaryOnlyModel(AtomicBool::new(false)));
let mut harness: AgentHarness<(), OpenHumanRunContext> = AgentHarness::new();
harness
- .register_model("summary", model.clone())
- .set_default_model("summary");
+ .with_model( model.clone())
+ ;
let run = harness
.invoke_in_context(&(), child, vec![Message::user("summarize this")])
diff --git a/crates/openhuman-core/src/agent/tinyagents/prompt_cache_golden_tests.rs b/crates/openhuman-core/src/agent/tinyagents/prompt_cache_golden_tests.rs
index 7f8365587b..81a107d629 100644
--- a/crates/openhuman-core/src/agent/tinyagents/prompt_cache_golden_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/prompt_cache_golden_tests.rs
@@ -80,8 +80,8 @@ async fn run(s: &Scenario) -> Value {
}));
let mut harness: AgentHarness<(), OpenHumanRunContext> = AgentHarness::new();
harness
- .register_model("m", model.clone())
- .set_default_model("m");
+ .with_model( model.clone())
+ ;
if s.with_tools {
harness.register_tool(Arc::new(Lookup));
}
diff --git a/crates/openhuman-core/src/agent/tinyagents/tinyagents_tests.rs b/crates/openhuman-core/src/agent/tinyagents/tinyagents_tests.rs
index 985a3f69bb..db0b3b9e93 100644
--- a/crates/openhuman-core/src/agent/tinyagents/tinyagents_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/tinyagents_tests.rs
@@ -142,7 +142,7 @@ async fn run_policy_decodes_stringified_nested_object_arguments() {
let mut harness: tinyagents_harness::runtime::AgentHarness<()> =
tinyagents_harness::runtime::AgentHarness::new();
- harness.register_model("mock", model);
+ harness.with_model( model);
harness.register_tool(tool.clone());
harness.with_policy(run_policy_for(10, false));
diff --git a/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rs b/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rs
index a76228e651..7dbbe29c67 100644
--- a/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/verify_before_finish_tests.rs
@@ -67,7 +67,7 @@ async fn drive_with(
responses.push(ModelResponse::assistant("draft".to_string()));
responses.push(ModelResponse::assistant("checked".to_string()));
let mut harness: AgentHarness<()> = AgentHarness::new();
- harness.register_model("mock", Arc::new(ScriptedModel::new(responses)));
+ harness.with_model( Arc::new(ScriptedModel::new(responses)));
harness.register_tool(Arc::new(FakeTool::returning("lookup", "ok")));
harness.register_tool(Arc::new(FakeTool::returning("todo", "ok")));
harness.with_policy(RunPolicy {
@@ -199,7 +199,7 @@ async fn requirements_check_allows_a_fix_for_different_tasks() {
]);
let model = Arc::new(ScriptedModel::new(responses));
let mut harness: AgentHarness<()> = AgentHarness::new();
- harness.register_model("mock", model.clone());
+ harness.with_model( model.clone());
harness.register_tool(Arc::new(FakeTool::returning("lookup", "ok")));
harness.with_policy(RunPolicy {
limits: RunLimits::default().with_max_model_calls(50),
diff --git a/crates/openhuman-core/src/artifacts/preview.rs b/crates/openhuman-core/src/artifacts/preview.rs
index 9084f9176a..7c7cb4d166 100644
--- a/crates/openhuman-core/src/artifacts/preview.rs
+++ b/crates/openhuman-core/src/artifacts/preview.rs
@@ -15,7 +15,7 @@
use std::path::Path;
use serde::Serialize;
-use tiny_artifacts::{ArtifactKind, ArtifactRecord};
+use tiny_artifacts::{ArtifactKind, ArtifactRecord, FileRef, FileStore};
use crate::config::Config;
@@ -46,17 +46,21 @@ pub struct ArtifactBody {
///
/// Returns an error when the artifact does not exist or its record cannot be
/// read.
-pub async fn read_body(config: &Config, id: &str) -> Result<ArtifactBody, String> {
+pub async fn read_body(
+ config: &Config,
+ id: &str,
+ ctx: &crate::core::runtime::DispatchCtx,
+) -> Result<ArtifactBody, String> {
let files = super::files::FileRoots::from_config(config);
- let mut roots =
- super::tiny_store::file_roots(&config.workspace_dir, &files, Some(&config.action_dir));
- let versioned = super::tiny_store::artifacts_service(
+ let artifacts = super::tiny_store::artifacts_service(
&config.workspace_dir,
files.clone(),
Some(&config.action_dir),
None,
- )
- .get(id)
+ ctx,
+ );
+ let versioned = artifacts
+ .get(id)
.await
.map_err(|e| e.to_string())?;
let record = match versioned {
@@ -64,21 +68,13 @@ pub async fn read_body(config: &Config, id: &str) -> Result<ArtifactBody, String
// An artifact made before versioning has only its legacy record: show
// the file that record vouches for.
None => {
- let record = legacy_record(&config.workspace_dir, &files, id).await?;
- if let Some(folder) = record
- .latest()
- .and_then(|v| v.file.as_ref())
- .and_then(|f| Path::new(&f.path).parent())
- {
- roots.push(folder.to_path_buf());
- }
- record
+ legacy_record(&config.workspace_dir, &files, id, &artifacts).await?
}
};
let converter = DocumentConverter::for_config(config);
Ok(body_of(
&record,
- &super::tiny_store::guarded_roots(roots),
+ artifacts.file_store(),
&converter,
)
.await)
@@ -91,6 +87,7 @@ async fn legacy_record(
workspace_dir: &Path,
files: &super::files::FileRoots,
id: &str,
+ artifacts: &tiny_artifacts::Artifacts,
) -> Result<ArtifactRecord, String> {
let meta = super::store::get_artifact(workspace_dir, id)
.await
@@ -98,18 +95,40 @@ async fn legacy_record(
let path = super::files::resolve_ready_file(workspace_dir, files, id).await?;
let path = path.display().to_string();
let at = u64::try_from(meta.created_at.timestamp_millis()).unwrap_or(0);
+ let legacy_ref = FileRef {
+ key: path.clone(),
+ size_bytes: meta.size_bytes,
+ media_type: None,
+ };
+ let file_store = super::tiny_store::file_store_for(
+ workspace_dir,
+ &crate::core::runtime::DispatchCtx::ambient(),
+ )
+ .ok_or_else(|| "artifact file storage is unavailable".to_string())?;
+ let roots = super::tiny_store::guarded_roots(super::tiny_store::file_roots(
+ workspace_dir,
+ files,
+ None,
+ ));
+ let imported = tiny_artifacts::import_legacy_file(
+ file_store.as_ref(),
+ &roots,
+ &legacy_ref,
+ &format!("artifacts/files/{id}/v1.{}", Path::new(&path)
+ .extension()
+ .and_then(|ext| ext.to_str())
+ .unwrap_or("bin")),
+ )
+ .await
+ .map_err(|e| e.to_string())?;
let mut version = tiny_artifacts::ArtifactVersion::new(
1,
- path.clone(),
+ imported.key.clone(),
tiny_artifacts::ArtifactAuthor::Agent,
super::tiny_store::AGENT_AUTHOR_ID,
at,
);
- version.file = Some(tiny_artifacts::FileRef {
- size_bytes: meta.size_bytes,
- media_type: None,
- path,
- });
+ version.file = Some(imported);
let mut record = ArtifactRecord::pending(id, meta.title, ArtifactKind::File, at);
record.versions.push(version);
Ok(record)
@@ -170,7 +189,7 @@ impl<'a> DocumentConverter<'a> {
/// `roots`.
pub(crate) async fn body_of(
record: &ArtifactRecord,
- roots: &tiny_artifacts::FileRoots,
+ file_store: Option<&std::sync::Arc<dyn FileStore>>,
converter: &DocumentConverter<'_>,
) -> ArtifactBody {
let latest = record.latest();
@@ -186,19 +205,21 @@ pub(crate) async fn body_of(
if !record.holds_file() {
return preview;
}
- let path = latest
- .and_then(|v| v.file.as_ref())
- .map_or(stored, |f| f.path.clone());
- preview.body = path.clone();
- // Inside the trusted folders, an existing regular file: anything else is
- // shown by its path only.
- let Ok(file) = roots.resolve(&path).await else {
+ let Some(file) = latest.and_then(|v| v.file.as_ref()) else {
+ preview.body = stored;
+ return preview;
+ };
+ preview.body = file.file_name().unwrap_or(&file.key).to_string();
+ let Some(file_store) = file_store else {
+ return preview;
+ };
+ let Ok(Some(metadata)) = file_store.metadata(&file.key).await else {
return preview;
};
- if file.size_bytes > PREVIEW_MAX_BYTES {
+ if metadata.size_bytes > PREVIEW_MAX_BYTES {
return preview;
}
- let Ok(bytes) = tokio::fs::read(Path::new(&file.path)).await else {
+ let Ok(bytes) = file_store.read(&file.key).await else {
return preview;
};
let probe = &bytes[..bytes.len().min(8192)];
diff --git a/crates/openhuman-core/src/config/schema/tokenjuice.rs b/crates/openhuman-core/src/config/schema/tokenjuice.rs
index 9b0be21845..4addc75aa0 100644
--- a/crates/openhuman-core/src/config/schema/tokenjuice.rs
+++ b/crates/openhuman-core/src/config/schema/tokenjuice.rs
@@ -20,8 +20,9 @@ pub struct TokenjuiceConfig {
/// a `⟦tj:<hash>⟧` retrieval footer. Disabling makes compaction one-way.
#[serde(default = "default_true")]
pub ccr_enabled: bool,
- /// Persist CCR originals to disk under `<workspace>/.tokenjuice/ccr` so
- /// retrieval survives memory eviction (written by the core only).
+ /// Request durable CCR storage through the host-granted TinyJuice storage
+ /// backend. The legacy `<workspace>/.tokenjuice/ccr` directory is read
+ /// only as migration input; the key is retained for config compatibility.
#[serde(default)]
pub ccr_disk_enabled: bool,
/// Store a large result behind a handle and show the model a stats line, a
@@ -35,10 +36,8 @@ pub struct TokenjuiceConfig {
/// `juice_retrieve` round trip.
#[serde(default = "default_true")]
pub repl_handle_enabled: bool,
- /// Also write each stored original to
- /// `<workspace>/.tokenjuice/repl/<handle>.txt` (mode 0600) so the agent can
- /// script over it. Off by default: it puts raw tool output on disk, and
- /// nothing prunes the directory.
+ /// Retired REPL snapshot option, retained for config compatibility. The
+ /// TinyJuice bus no longer writes plaintext copies of stored originals.
#[serde(default)]
pub repl_save_enabled: bool,
/// Max number of originals retained in the in-memory CCR store.