Skip to content

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

refactor(tokenjuice): drop local query bridge in favour of host trait

Steven Enamakel7019e4f88aaf
diff --git a/crates/openhuman-core/src/inference/tokenjuice/mod.rs b/crates/openhuman-core/src/inference/tokenjuice/mod.rs
index 50c1ee8501..c16b5e73fa 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/mod.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/mod.rs
@@ -15,53 +15,30 @@ use tinyjuice_bus::types::{AgentTokenjuiceCompression, CompressorKind};
use tinyjuice_bus::wire::{QueryRequest, QueryResponse};
use tinytools::{Tool, ToolRunContext, ToolSpec};
-/// The host-specific query seam for TinyJuice's shared REPL tools.
-#[async_trait]
-trait QuerySource: Send + Sync {
- async fn query(
- &self,
- ctx: &DispatchCtx,
- request: QueryRequest,
- ) -> Result<QueryResponse, String>;
-}
-
struct ModuleSource(Option<Arc<crate::config::Config>>);
#[async_trait]
-impl QuerySource for ModuleSource {
+impl tinyjuice_host::repl_tools::QuerySource for ModuleSource {
async fn query(
&self,
- ctx: &DispatchCtx,
+ context: Option<&dyn ToolRunContext>,
request: QueryRequest,
) -> Result<QueryResponse, String> {
+ let ctx = crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(context);
match &self.0 {
Some(config) => query_for_config(config, request).await,
- None => query(ctx, request).await,
+ None => query(&ctx, request).await,
}
}
}
-struct QueryBridge(Arc<dyn QuerySource>);
-
-#[async_trait]
-impl tinyjuice_host::repl_tools::QuerySource for QueryBridge {
- async fn query(
- &self,
- context: Option<&dyn ToolRunContext>,
- request: QueryRequest,
- ) -> Result<QueryResponse, String> {
- let ctx = crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(context);
- self.0.query(&ctx, request).await
- }
-}
-
fn host_repl_tools(
- source: Arc<dyn QuerySource>,
+ source: Arc<dyn tinyjuice_host::repl_tools::QuerySource>,
limits: ReplLimits,
artifacts_dir: Option<PathBuf>,
) -> Vec<Box<dyn Tool>> {
tinyjuice_host::repl_tools::repl_tools(
- Arc::new(QueryBridge(source)),
+ source,
limits,
artifacts_dir,
tinytools_std::filesystem::FileReadTool::MAX_FILE_SIZE_BYTES,
@@ -70,7 +47,10 @@ fn host_repl_tools(
}
#[cfg(test)]
-fn repl_tools_with(source: Arc<dyn QuerySource>, limits: ReplLimits) -> Vec<Box<dyn Tool>> {
+fn repl_tools_with(
+ source: Arc<dyn tinyjuice_host::repl_tools::QuerySource>,
+ limits: ReplLimits,
+) -> Vec<Box<dyn Tool>> {
host_repl_tools(source, limits, None)
}
@@ -119,9 +99,7 @@ pub(crate) fn repl_tools_for_recorded(
.collect();
tinyjuice_host::repl_tools::repl_tools_with_declarations(
declarations,
- Arc::new(QueryBridge(Arc::new(ModuleSource(
- config.cloned().map(Arc::new),
- )))),
+ Arc::new(ModuleSource(config.cloned().map(Arc::new))),
ReplLimits::default(),
Some(crate::security::policy::tool_result_artifacts_dir(
workspace_dir,
diff --git a/crates/openhuman-core/src/inference/tokenjuice/repl_tools_tests.rs b/crates/openhuman-core/src/inference/tokenjuice/repl_tools_tests.rs
index 00b27c463b..3c6a3e5baf 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/repl_tools_tests.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/repl_tools_tests.rs
@@ -8,8 +8,13 @@ use tinytools::ToolCallOptions;
struct CoreRecordingSource(Mutex<Vec<Option<Arc<crate::core::runtime::CoreContext>>>>);
#[async_trait]
-impl QuerySource for CoreRecordingSource {
- async fn query(&self, ctx: &DispatchCtx, _: QueryRequest) -> Result<QueryResponse, String> {
+impl tinyjuice_host::repl_tools::QuerySource for CoreRecordingSource {
+ async fn query(
+ &self,
+ context: Option<&dyn tinytools::ToolRunContext>,
+ _: QueryRequest,
+ ) -> Result<QueryResponse, String> {
+ let ctx = crate::agent::tinyagents::host::run_context::dispatch_ctx_for_tool(context);
self.0.lock().unwrap().push(ctx.core().cloned());
Ok(Ok(ReplOutput::Text { text: "ok".into() }))
}