Skip to content

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

refactor(agent): encapsulate session turn runner in AgentTurnHost

Steven Enamakelaeb523334b53
diff --git a/crates/openhuman-core/src/agent/host_agents.rs b/crates/openhuman-core/src/agent/host_agents.rs
index b1422837de..145df0956b 100644
--- a/crates/openhuman-core/src/agent/host_agents.rs
+++ b/crates/openhuman-core/src/agent/host_agents.rs
@@ -104,7 +104,7 @@ impl HostAgent {
session.set_thread_id(Some(session_key));
session.set_event_context(event_session_id, channel);
session.adopt_imported_history(imported_history)?;
- self.scope(crate::agent::turn_host::run_session_turn(
+ self.scope(crate::agent::turn_host::AgentTurnHost::run(
&mut session,
crate::agent::turn_host::AgentTurnRequest {
message: message.to_owned(),
diff --git a/crates/openhuman-core/src/agent/turn_host.rs b/crates/openhuman-core/src/agent/turn_host.rs
index 5f95c80959..c33fe51eb5 100644
--- a/crates/openhuman-core/src/agent/turn_host.rs
+++ b/crates/openhuman-core/src/agent/turn_host.rs
@@ -33,39 +33,44 @@ pub(crate) struct AgentTurnRequest {
pub(crate) host_env: HostTurnEnv,
}
+/// Shared agent-domain execution port used by web and external-channel hosts.
+pub(crate) struct AgentTurnHost;
+
/// Run a turn with the caller's resolved trusted session and policy context.
///
/// Cancellation and the harness deadline are captured in `host_env`; outer
/// callers remain responsible for their own idle/backstop lifecycle. Queue,
/// workspace and progress are bound only to this turn and never reused as
/// ambient authority by the next session.
-pub(crate) async fn run_session_turn(
- session: &mut OpenHumanSessionHost,
- request: AgentTurnRequest,
-) -> anyhow::Result<String> {
- session.set_on_progress(request.progress);
- session.set_run_queue(request.run_queue);
- session.set_thread_id(request.thread_id);
- let mut host_env = request.host_env;
- host_env.cancellation = Some(request.cancellation);
- host_env.turn_deadline = request
- .turn_deadline
- .map(tinyagents_harness::turn_deadline::TurnDeadline::starting_now);
- session.set_host_env(host_env);
- if let Some(workspace) = request.workspace {
- session.set_workspace_descriptor(Some(workspace));
- }
+impl AgentTurnHost {
+ pub(crate) async fn run(
+ session: &mut OpenHumanSessionHost,
+ request: AgentTurnRequest,
+ ) -> anyhow::Result<String> {
+ session.set_on_progress(request.progress);
+ session.set_run_queue(request.run_queue);
+ session.set_thread_id(request.thread_id);
+ let mut host_env = request.host_env;
+ host_env.cancellation = Some(request.cancellation);
+ host_env.turn_deadline = request
+ .turn_deadline
+ .map(tinyagents_harness::turn_deadline::TurnDeadline::starting_now);
+ session.set_host_env(host_env);
+ if let Some(workspace) = request.workspace {
+ session.set_workspace_descriptor(Some(workspace));
+ }
- // Keep the large agent future behind a pointer while the origin scope is
- // active. The origin is explicit and independent from RPC metadata.
- Box::pin(with_origin(
- request.origin.clone(),
- session.run_single_with_approval(
- &request.message,
- Some(request.origin),
- request.approval,
- ),
- ))
- .await
+ // Keep the large agent future behind a pointer while the origin scope
+ // is active. The origin is explicit and independent from RPC metadata.
+ Box::pin(with_origin(
+ request.origin.clone(),
+ session.run_single_with_approval(
+ &request.message,
+ Some(request.origin),
+ request.approval,
+ ),
+ ))
+ .await
+ }
}
diff --git a/crates/openhuman-core/src/web_chat/turn_host.rs b/crates/openhuman-core/src/web_chat/turn_host.rs
index dafa3b1634..31f30ca3cf 100644
--- a/crates/openhuman-core/src/web_chat/turn_host.rs
+++ b/crates/openhuman-core/src/web_chat/turn_host.rs
@@ -249,7 +249,7 @@ 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(crate::agent::turn_host::run_session_turn(
+ let turn = Box::pin(crate::agent::turn_host::AgentTurnHost::run(
agent,
crate::agent::turn_host::AgentTurnRequest {
message: request.text.clone(),