Skip to content

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

feat(agent): add budget correlation to tinyagents journal

Steven Enamakel16815d4a77c4
diff --git a/crates/openhuman-core/src/agent/tinyagents/journal.rs b/crates/openhuman-core/src/agent/tinyagents/journal.rs
index 54e4851434..e836d74ef3 100644
--- a/crates/openhuman-core/src/agent/tinyagents/journal.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/journal.rs
@@ -60,14 +60,14 @@ use tinyagents_harness::store::AppendStore;
/// Best-effort live request → durable tinyagents journal stream map. The web
/// progress bridge uses this at turn end to shadow-project spans from the
/// journal and compare them against the live `SpanCollector` path during C4 S3.
-fn request_journal_runs() -> std::sync::Arc<RequestJournalRuns> {
- crate::core::runtime::current_slot::<RequestJournalRuns>()
+fn request_journal_runs(ctx: &DispatchCtx) -> std::sync::Arc<RequestJournalRuns> {
+ crate::core::runtime::slot_for::<RequestJournalRuns>(ctx)
}
type RequestJournalRuns = Mutex<HashMap<String, String>>;
-pub(crate) fn register_request_journal_run(request_id: &str, run_id: &str) {
- match request_journal_runs().lock() {
+pub(crate) fn register_request_journal_run(ctx: &DispatchCtx, request_id: &str, run_id: &str) {
+ match request_journal_runs(ctx).lock() {
Ok(mut runs) => {
runs.insert(request_id.to_string(), run_id.to_string());
log::debug!(
@@ -85,8 +85,8 @@ pub(crate) fn register_request_journal_run(request_id: &str, run_id: &str) {
}
}
-pub(crate) fn take_request_journal_run(request_id: &str) -> Option<String> {
- request_journal_runs()
+pub(crate) fn take_request_journal_run(ctx: &DispatchCtx, request_id: &str) -> Option<String> {
+ request_journal_runs(ctx)
.lock()
.ok()
.and_then(|mut runs| runs.remove(request_id))
diff --git a/crates/openhuman-core/src/agent/tinyagents/reasoning.rs b/crates/openhuman-core/src/agent/tinyagents/reasoning.rs
index 81972de0fe..34131f8dd6 100644
--- a/crates/openhuman-core/src/agent/tinyagents/reasoning.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/reasoning.rs
@@ -23,8 +23,8 @@ use crate::config::Config;
type ThreadEfforts = Mutex<HashMap<String, ReasoningEffort>>;
-fn thread_efforts() -> Arc<ThreadEfforts> {
- crate::core::runtime::current_slot::<ThreadEfforts>()
+fn thread_efforts(ctx: &DispatchCtx) -> Arc<ThreadEfforts> {
+ crate::core::runtime::slot_for::<ThreadEfforts>(ctx)
}
/// The effort a thread's user picked, if any.
diff --git a/crates/openhuman-core/src/agent/tinyagents/run_mode.rs b/crates/openhuman-core/src/agent/tinyagents/run_mode.rs
index 22cae38fc8..ba711ef407 100644
--- a/crates/openhuman-core/src/agent/tinyagents/run_mode.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/run_mode.rs
@@ -27,8 +27,8 @@ use crate::core::events::DomainEvent;
type RunModeRegistry = Mutex<HashMap<String, RunModeHandle>>;
-fn registry() -> Arc<RunModeRegistry> {
- crate::core::runtime::current_slot::<RunModeRegistry>()
+fn registry(ctx: &DispatchCtx) -> Arc<RunModeRegistry> {
+ crate::core::runtime::slot_for::<RunModeRegistry>(ctx)
}
/// Returns the [`RunModeHandle`] for `thread_id`, creating one (starting in
diff --git a/crates/openhuman-core/src/memory/tools.rs b/crates/openhuman-core/src/memory/tools.rs
index 3892356a45..a12d3c3070 100644
--- a/crates/openhuman-core/src/memory/tools.rs
+++ b/crates/openhuman-core/src/memory/tools.rs
@@ -42,8 +42,8 @@ type TurnCitations = Mutex<HashMap<String, Vec<TurnCitation>>>;
/// Citations `recall` produced during a thread's in-flight turn, drained by
/// the chat surface once the turn returns ([`take_turn_citations`]).
-fn turn_citations() -> Arc<TurnCitations> {
- crate::core::runtime::current_slot::<TurnCitations>()
+fn turn_citations(ctx: &DispatchCtx) -> Arc<TurnCitations> {
+ crate::core::runtime::slot_for::<TurnCitations>(ctx)
}
fn record_turn_citations(thread_id: &str, citations: &[tinymemory_api::Citation]) {
diff --git a/crates/openhuman-core/src/web_chat/ops/budget_correlation.rs b/crates/openhuman-core/src/web_chat/ops/budget_correlation.rs
index 4d98005a75..aee5156cb0 100644
--- a/crates/openhuman-core/src/web_chat/ops/budget_correlation.rs
+++ b/crates/openhuman-core/src/web_chat/ops/budget_correlation.rs
@@ -42,8 +42,8 @@ struct BudgetSignal {
/// Kept in a sibling map rather than on `SessionEntry` so the signal survives
/// the de-poison session drop (an empty turn is not poisoned, but cold-boot
/// reseeds would otherwise be the wrong lifetime to hang this on).
-fn thread_budget_signals() -> Arc<ThreadBudgetSignals> {
- crate::core::runtime::current_slot::<ThreadBudgetSignals>()
+fn thread_budget_signals(ctx: &DispatchCtx) -> Arc<ThreadBudgetSignals> {
+ crate::core::runtime::slot_for::<ThreadBudgetSignals>(ctx)
}
type ThreadBudgetSignals = Mutex<HashMap<String, BudgetSignal>>;
diff --git a/crates/openhuman-core/src/web_chat/ops/state.rs b/crates/openhuman-core/src/web_chat/ops/state.rs
index c635b98d79..b5f2df5ff1 100644
--- a/crates/openhuman-core/src/web_chat/ops/state.rs
+++ b/crates/openhuman-core/src/web_chat/ops/state.rs
@@ -18,21 +18,21 @@ type InFlight = Mutex<HashMap<String, InFlightEntry>>;
type ParallelInFlight = Mutex<HashMap<String, ParallelEntry>>;
/// The current agent context's per-thread session cache.
-pub(crate) fn thread_sessions() -> Arc<ThreadSessions> {
- crate::core::runtime::current_slot::<ThreadSessions>()
+pub(crate) fn thread_sessions(ctx: &DispatchCtx) -> Arc<ThreadSessions> {
+ crate::core::runtime::slot_for::<ThreadSessions>(ctx)
}
/// The current agent context's primary in-flight turns, keyed by thread.
-pub(crate) fn in_flight() -> Arc<InFlight> {
- crate::core::runtime::current_slot::<InFlight>()
+pub(crate) fn in_flight(ctx: &DispatchCtx) -> Arc<InFlight> {
+ crate::core::runtime::slot_for::<InFlight>(ctx)
}
/// Parallel (forked) turns, keyed by `request_id`. A separate lane from
/// [`in_flight`] (which holds one primary, interrupt-able turn per thread) so
/// any number of concurrent `QueueMode::Parallel` turns can run on the same
/// thread without touching interrupt/steer/queue semantics.
-pub(crate) fn parallel_in_flight() -> Arc<ParallelInFlight> {
- crate::core::runtime::current_slot::<ParallelInFlight>()
+pub(crate) fn parallel_in_flight(ctx: &DispatchCtx) -> Arc<ParallelInFlight> {
+ crate::core::runtime::slot_for::<ParallelInFlight>(ctx)
}
/// The map key for `thread_id` in the calling scope.