Skip to content

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

feat(agent): introduce thread reasoning tracking

Steven Enamakel512cbc0397d5
diff --git a/crates/openhuman-core/src/agent/tinyagents/mod.rs b/crates/openhuman-core/src/agent/tinyagents/mod.rs
index 11cc1b9959..de00a9e06a 100644
--- a/crates/openhuman-core/src/agent/tinyagents/mod.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/mod.rs
@@ -50,6 +50,7 @@ pub(crate) mod reaper;
mod routes;
mod steering_forwarder;
mod supplemental_trace;
+pub(crate) mod thread_reasoning;
pub(crate) mod tool_registration;
mod turn_exec;
mod turn_exec_native;
@@ -65,7 +66,7 @@ pub(crate) use crate::agent::message_convert::chat_message_to_message;
#[cfg(feature = "flows")]
pub(crate) use crate::agent::message_convert::ta_call_to_oh_call;
-pub(crate) use crate::inference::reasoning::{apply_requested_effort, parse_reasoning_effort};
+pub(crate) use thread_reasoning::apply_requested_effort;
pub use crate::inference::turn_models::TurnModelSource;
pub(crate) use observability::SubagentScope;
pub(crate) use supplemental_trace::SupplementalTrace;
diff --git a/crates/openhuman-core/src/agent/tinyagents/thread_reasoning.rs b/crates/openhuman-core/src/agent/tinyagents/thread_reasoning.rs
index 90aaf92ba9..585337c52d 100644
--- a/crates/openhuman-core/src/agent/tinyagents/thread_reasoning.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/thread_reasoning.rs
@@ -14,6 +14,31 @@ pub(crate) fn store(ctx: &DispatchCtx) -> Arc<ThreadReasoningStore> {
crate::core::runtime::slot_for::<ThreadReasoningStore>(ctx)
}
+pub(crate) fn thread_effort(ctx: &DispatchCtx, thread_id: &str) -> Option<ReasoningEffort> {
+ store(ctx).get(&ThreadId::new(thread_id))
+}
+
+pub(crate) fn set_thread_effort(
+ ctx: &DispatchCtx,
+ thread_id: &str,
+ effort: Option<ReasoningEffort>,
+) {
+ let thread_id = ThreadId::new(thread_id);
+ let store = store(ctx);
+ let previous = match effort {
+ Some(effort) => store.set_effort(&thread_id, effort),
+ None => store.clear(&thread_id),
+ };
+ if previous != effort {
+ log::info!(
+ "[agent][reasoning] thread reasoning effort changed thread_id={} {:?} -> {:?}",
+ thread_id.as_str(),
+ previous.map(ReasoningEffort::as_str),
+ effort.map(ReasoningEffort::as_str)
+ );
+ }
+}
+
/// Applies a chat request's optional reasoning choice, preserving the wire
/// error text used by existing clients for an unrecognized effort.
pub(crate) fn apply_requested_effort(
@@ -35,23 +60,14 @@ pub(crate) fn apply_requested_effort(
.ok_or_else(|| format!("unknown reasoning_effort '{trimmed}'"))?)
};
- let thread_id = ThreadId::new(thread_id);
- let store = store(ctx);
- let previous = match requested {
- Some(effort) => store.set_effort(&thread_id, effort),
- None => store.clear(&thread_id),
- };
- if previous != requested {
- log::info!(
- "[agent][reasoning] thread reasoning effort changed thread_id={} {:?} -> {:?}",
- thread_id.as_str(),
- previous.map(ReasoningEffort::as_str),
- requested.map(ReasoningEffort::as_str)
- );
- }
+ set_thread_effort(ctx, thread_id, requested);
Ok(())
}
+pub(crate) fn parse_reasoning_effort(raw: &str) -> Option<ReasoningEffort> {
+ ReasoningEffort::parse(raw)
+}
+
#[cfg(test)]
#[path = "thread_reasoning_tests.rs"]
mod tests;