The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
refactor(channels): route host agent turns through external channel runner
Steven Enamakelee342d179dcd
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/turn.rsindex 5b2bd81eda..d92d8bcc6a 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/turn.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/turn.rs@@ -7,21 +7,19 @@ use crate::agent::bus::AgentTurnResponse;use crate::agent::host_agents::HostAgent;use crate::agent::turn_origin::AgentTurnOrigin;use tinyagents_harness::progress::AgentProgress;-use tinyagents_session::transcript::TranscriptMessage;/// One channel message, as a host agent's turn needs it.pub(crate) struct HostChannelTurn {- /// Durable thread supplied explicitly by a hosted relay.+ /// Existing trusted relay correlation used by scoped tools.pub(crate) relay_thread: Option<String>,/// The channel the message came in on (`"telegram"`).pub(crate) channel: String,- /// The chat's history key: the session the host belt is told about and- /// the event session id.- pub(crate) history_key: String,- /// This chat's prior turns, `(role, content)`, oldest first. The channel- /// owns them, as it does for the orchestrator, so the session is seeded- /// from them rather than from a durable transcript.- pub(crate) prior_turns: Vec<(String, String)>,+ /// TinyChannels' canonical conversation identity, tenant-scoped by the+ /// host before it reaches this runner.+ pub(crate) session_key: String,+ /// Stable event/approval identity retained by the existing channel+ /// surface. It is attribution, not the transcript key.+ pub(crate) event_session_id: String,/// The message the agent answers.pub(crate) message: String,/// Who asked: the channel's `ExternalChannel` origin.@@ -31,6 +29,8 @@ pub(crate) struct HostChannelTurn {/// Where this turn's parked approvals surface; default for a channel/// without an approval surface.pub(crate) approval: crate::security::approval::ApprovalTurnContext,+ pub(crate) cancellation: tinyagents_harness::CancellationToken,+ pub(crate) turn_deadline: Option<std::time::Duration>,}/// Run `turn` as `host`: its definition and host tools, inside its context,@@ -42,13 +42,16 @@ pub(crate) async fn run_host_agent_turn(let HostChannelTurn {relay_thread,channel,- history_key,- prior_turns,+ session_key,+ event_session_id,message,origin,progress,approval,+ cancellation,+ turn_deadline,} = turn;+ let mut host = *host;let mut config = host.config.clone();let profile_ceiling = host.context@@ -67,54 +70,28 @@ pub(crate) async fn run_host_agent_turn(.map(|tools| posture::guard_host_tools(tools, ceiling));}let agent_id = host.definition.id.clone();- let model = config.default_model.clone().unwrap_or_default();tracing::info!(channel = %channel,agent_id = %agent_id,- prior_turns = prior_turns.len(),"[channels::dispatch::host_agent] running channel turn as host agent");-+ host.config = config;host.context = host.context- .derive_channel_turn(relay_thread.clone(), Some(origin.clone()));- let mut session = host.session_host(- &config,- Some(relay_thread.as_deref().unwrap_or(&history_key)),- )?;- session.set_thread_id(relay_thread.as_deref());- // The channel names the session, which also selects the channel's- // permission ceiling in the session's tool policy.- session.set_event_context(history_key, channel);- // The chat's history is the channel's, so the session holds exactly that- // and never resumes a transcript of its own.- session.clear_history();- session.seed_resume_from_messages(prior_turns, &message)?;- session.set_next_turn_overrides(crate::agent::TurnOverrides {- suppress_transcript_autoload: true,- ..Default::default()- });- session.set_on_progress(progress);-+ .derive_channel_turn(relay_thread, Some(origin.clone()));+ let model = host.config.default_model.clone().unwrap_or_default();let text = host- .scope(session.run_single_with_approval(&message, Some(origin), approval))+ .run_external_channel_turn(+ &session_key,+ &event_session_id,+ &channel,+ &message,+ origin,+ approval,+ progress,+ cancellation,+ turn_deadline,+ ).await?;- Ok(AgentTurnResponse::with_resolved_route(- text,- format!("agent:{agent_id}"),- model,- ))-}--/// The prior turns of a channel `history` (`[system, ..prior, user]`) as seed-/// rows: the channel's own system prompt and the new message are dropped, the-/// agent brings its own prompt and the message is the turn.-pub(crate) fn seed_rows(history: &[TranscriptMessage]) -> Vec<(String, String)> {- let end = history.len().saturating_sub(1);- history- .get(1..end)- .unwrap_or_default()- .iter()- .map(|row| (row.role.clone(), row.content.clone()))- .collect()+ Ok(AgentTurnResponse::with_resolved_route(text, format!("agent:{agent_id}"), model))}