Skip to content

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

refactor(agent): route host agent turns through run_session_turn

Steven Enamakel5d3b60dc7b0a
diff --git a/crates/openhuman-core/src/agent/host_agents.rs b/crates/openhuman-core/src/agent/host_agents.rs
index 20d3ec90f7..b1422837de 100644
--- a/crates/openhuman-core/src/agent/host_agents.rs
+++ b/crates/openhuman-core/src/agent/host_agents.rs
@@ -103,20 +103,31 @@ impl HostAgent {
let mut session = self.session_host(&config, Some(session_key))?;
session.set_thread_id(Some(session_key));
session.set_event_context(event_session_id, channel);
- session.set_on_progress(progress);
- session.set_host_env(crate::agent::turn_env::HostTurnEnv {
- hooks: self.hooks.clone(),
- core: Some(Arc::downgrade(&self.context)),
- cancellation: Some(cancellation),
- turn_deadline: turn_deadline
- .map(tinyagents_harness::turn_deadline::TurnDeadline::starting_now),
- approval: approval.clone(),
- memory_identity: Some(crate::memory::scope::MemoryIdentity::root().child(&agent_id)),
- ..Default::default()
- });
session.adopt_imported_history(imported_history)?;
- self.scope(session.run_single_with_approval(message, Some(origin), approval))
- .await
+ self.scope(crate::agent::turn_host::run_session_turn(
+ &mut session,
+ crate::agent::turn_host::AgentTurnRequest {
+ message: message.to_owned(),
+ thread_id: Some(session_key.to_owned()),
+ origin,
+ approval: approval.clone(),
+ progress,
+ run_queue: None,
+ cancellation,
+ turn_deadline,
+ workspace: None,
+ host_env: crate::agent::turn_env::HostTurnEnv {
+ hooks: self.hooks.clone(),
+ core: Some(Arc::downgrade(&self.context)),
+ approval,
+ memory_identity: Some(
+ crate::memory::scope::MemoryIdentity::root().child(&agent_id),
+ ),
+ ..Default::default()
+ },
+ },
+ ))
+ .await
}
/// Build a session for this agent from `config` -- normally a clone of
diff --git a/crates/openhuman-core/src/web_chat/turn_host.rs b/crates/openhuman-core/src/web_chat/turn_host.rs
index 27a5f534cd..dafa3b1634 100644
--- a/crates/openhuman-core/src/web_chat/turn_host.rs
+++ b/crates/openhuman-core/src/web_chat/turn_host.rs
@@ -37,7 +37,7 @@ use super::web_errors::{
inference_budget_exceeded_user_message, is_inference_budget_exceeded_error,
};
use crate::agent::queued_turn::QueuedPayload;
-use crate::agent::turn_origin::{AgentTurnOrigin, with_origin};
+use crate::agent::turn_origin::AgentTurnOrigin;
use crate::core::events::DomainEvent;
use crate::core::runtime::DispatchCtx;
use tinyagents_harness::progress::AgentProgress;
@@ -249,26 +249,22 @@ impl WebHost {
// a pointer rather than inlining it into this frame.
#[cfg(feature = "tinymemes")]
let turn_started = std::time::Instant::now();
- let turn = Box::pin(with_origin(
- origin.clone(),
- crate::agent::turn_host::run_session_turn(
- agent,
- crate::agent::turn_host::AgentTurnRequest {
- message: request.text.clone(),
- thread_id: Some(thread_id.to_owned()),
- origin,
- approval,
- progress: Some(progress_tx),
- run_queue: Some(queue),
- cancellation,
- turn_deadline: request.deadline,
- // Also the turn's workspace, so attachment reads and
- // delegated sub-agents use the upload folder (#7714).
- workspace: thread_dir
- .map(tinytools::WorkspaceDescriptor::new),
- host_env: Default::default(),
- },
- ),
+ let turn = Box::pin(crate::agent::turn_host::run_session_turn(
+ agent,
+ crate::agent::turn_host::AgentTurnRequest {
+ message: request.text.clone(),
+ thread_id: Some(thread_id.to_owned()),
+ origin,
+ approval,
+ progress: Some(progress_tx),
+ run_queue: Some(queue),
+ cancellation,
+ turn_deadline: request.deadline,
+ // Also the turn's workspace, so attachment reads and
+ // delegated sub-agents use the upload folder (#7714).
+ workspace: thread_dir.map(tinytools::WorkspaceDescriptor::new),
+ host_env: Default::default(),
+ },
));
let outcome = turn.await;
let result = match outcome {