Skip to content

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

feat(embed): let a turn run on history its host supplies

sanil-232ad875096331
diff --git a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
index 4e257d51e9..0e1624f72a 100644
--- a/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
+++ b/crates/openhuman-core/src/inference/host_runtime/ops/agent_chat.rs
@@ -90,6 +90,18 @@ pub enum AgentChatTarget<'a> {
Definition {
definition: &'a crate::agent::harness::definition::AgentDefinition,
host: Option<&'a crate::agent::HostTools>,
+ /// History to seed this turn with, as `(role, content)` rows, instead
+ /// of whatever the session would otherwise resume.
+ ///
+ /// Rides the target for the same reason `host` does, and it is the
+ /// per-turn half of the same idea: a host whose history lives in its
+ /// own log -- a journal, a board, an episode -- is the only thing that
+ /// can say what this turn should have seen. Seeding is how that view
+ /// reaches the session with roles intact; passing it as prose in the
+ /// message would flatten the host's own prior turns into quoted text.
+ ///
+ /// `None` leaves resume untouched, which is every existing caller.
+ seed: Option<&'a [(String, String)]>,
},
}
@@ -101,10 +113,15 @@ impl std::fmt::Debug for AgentChatTarget<'_> {
match self {
Self::Orchestrator => f.write_str("Orchestrator"),
Self::AgentId(id) => f.debug_tuple("AgentId").field(id).finish(),
- Self::Definition { definition, host } => f
+ Self::Definition {
+ definition,
+ host,
+ seed,
+ } => f
.debug_struct("Definition")
.field("definition", &definition.id)
.field("host_tools", &host.is_some())
+ .field("seed_rows", &seed.map_or(0, <[(String, String)]>::len))
.finish(),
}
}
@@ -120,7 +137,9 @@ fn build_turn_agent(
log::debug!("[inference] agent_chat building agent_id={id}");
OpenHumanSessionHost::from_config_for_agent(config, id)
}
- AgentChatTarget::Definition { definition, host } => match host {
+ AgentChatTarget::Definition {
+ definition, host, ..
+ } => match host {
Some(host) => {
OpenHumanSessionHost::from_config_with_host_tools(config, definition, host)
}
@@ -220,6 +239,32 @@ pub async fn agent_chat_for(
// set one explicitly (web chat, platform socket, flows, skills) hold their
// own `Agent` and never reach this path — where both could apply, the
// explicitly-set sink wins because it is applied to the agent it owns.
+ // A seeded turn replaces resume rather than adding to it.
+ //
+ // The three calls are one operation and the order is load-bearing:
+ // `clear_history` drops the composed session so `seed_resume_from_messages`
+ // -- which returns early on a live one -- can take effect, and the override
+ // stops the runtime reloading from its own durable transcript the history
+ // that was just replaced. A caller seeding from its own log means that log
+ // to be the whole of what this turn has seen; leaving either of the other
+ // two off would quietly reunite it with a second source.
+ if let AgentChatTarget::Definition {
+ seed: Some(seed), ..
+ } = target
+ {
+ agent.clear_history();
+ agent
+ .seed_resume_from_messages(seed.to_vec(), message)
+ .map_err(|e| e.to_string())?;
+ agent.set_next_turn_overrides(crate::agent::session_host::TurnOverrides {
+ suppress_transcript_autoload: true,
+ ..Default::default()
+ });
+ log::debug!(
+ "[inference] agent_chat seeded {} row(s); transcript autoload suppressed",
+ seed.len()
+ );
+ }
if let Some(tx) = crate::agent::progress_sink::current_progress_sink() {
agent.set_on_progress(Some(tx));
}
diff --git a/crates/openhuman-embed/src/turn.rs b/crates/openhuman-embed/src/turn.rs
index 880a825e52..776da572c9 100644
--- a/crates/openhuman-embed/src/turn.rs
+++ b/crates/openhuman-embed/src/turn.rs
@@ -226,6 +226,7 @@ pub struct Turn {
session_id: Option<String>,
origin: Option<AgentTurnOrigin>,
progress: Option<tokio::sync::mpsc::Sender<AgentProgress>>,
+ seed: Option<Vec<(String, String)>>,
}
impl Turn {
@@ -236,6 +237,7 @@ impl Turn {
session_id: None,
origin: None,
progress: None,
+ seed: None,
}
}
@@ -251,6 +253,48 @@ impl Turn {
self
}
+ /// Run this turn against `history` instead of whatever the session holds.
+ ///
+ /// Rows are `(role, content)` -- `"system"`, `"user"`, `"assistant"` --
+ /// and they replace resume rather than adding to it: the session's own
+ /// history is dropped, these are put in its place, and the durable
+ /// transcript is not reloaded for this turn.
+ ///
+ /// # When a host wants this
+ ///
+ /// A host whose conversations live in its own log -- a journal, a board,
+ /// an episode -- is the only thing that can say what a turn should have
+ /// seen. That view is rarely the session's: it may be scoped to one
+ /// conversation, filtered to what this agent is allowed to read, windowed,
+ /// or cut at a watermark. Seeding is how it reaches the model with roles
+ /// intact. Passing the same thing as prose in the message would flatten
+ /// the agent's own prior turns into quoted text, which is not the same
+ /// input.
+ ///
+ /// Pair it with a [`session`](Self::session) id of its own. Seeding is
+ /// refused on a session that already holds history, and a turn that varies
+ /// its belt or its prompt wants a session it is not sharing.
+ ///
+ /// Only a runtime-owned [`Agent`](crate::Agent) can honour this; a turn on
+ /// a caller-built runtime's orchestrator is refused rather than run
+ /// unseeded, since silently dropping the history would run the agent
+ /// blind.
+ ///
+ /// ```no_run
+ /// # use openhuman_embed::Agent;
+ /// # async fn go(agent: &Agent, rows: Vec<(String, String)>) -> anyhow::Result<()> {
+ /// agent.turn("what did we decide?")
+ /// .session(format!("turn-{}", uuid::Uuid::new_v4()))
+ /// .seed(rows)
+ /// .send()
+ /// .await?;
+ /// # Ok(()) }
+ /// ```
+ pub fn seed(mut self, history: Vec<(String, String)>) -> Self {
+ self.seed = Some(history);
+ self
+ }
+
/// Pin this turn to a model id.
pub fn model(mut self, model: impl Into<String>) -> Self {
self.request.model_override = Some(model.into());
@@ -358,7 +402,7 @@ impl Turn {
}
}
- let dispatch = dispatch(self.target, self.request);
+ let dispatch = dispatch(self.target, self.request, self.seed.take());
let reply = match (self.origin, self.progress) {
(Some(origin), Some(sink)) => {
@@ -412,9 +456,22 @@ impl Turn {
/// target reaches `agent_chat_for` natively under the agent's own context —
/// the definition it carries cannot travel as JSON — so it applies the
/// DomainSet gate itself before touching the core.
-async fn dispatch(target: TurnTarget, request: TurnRequest) -> Result<String, CoreError> {
+async fn dispatch(
+ target: TurnTarget,
+ request: TurnRequest,
+ seed: Option<Vec<(String, String)>>,
+) -> Result<String, CoreError> {
match target {
- TurnTarget::Runtime(rt) => call::<_, String>(&rt, AGENT_CHAT, &request).await,
+ TurnTarget::Runtime(rt) => {
+ // Refused rather than dropped. `AGENT_CHAT`'s params are a wire
+ // contract and carry no history, so this path cannot seed -- and a
+ // turn that asked for history and silently ran without it would be
+ // the agent answering blind, which is worse than a clear error.
+ if seed.is_some() {
+ return Err(CoreError::Unavailable { method: AGENT_CHAT });
+ }
+ call::<_, String>(&rt, AGENT_CHAT, &request).await
+ }
TurnTarget::Agent(agent) => {
if !agent.ctx.domains().inference {
return Err(CoreError::Unavailable { method: AGENT_CHAT });
@@ -440,6 +497,7 @@ async fn dispatch(target: TurnTarget, request: TurnRequest) -> Result<String, Co
let target = AgentChatTarget::Definition {
definition: &inner.definition,
host: inner.host_tools.as_ref(),
+ seed: seed.as_deref(),
};
agent_chat_for(
&mut config,
diff --git a/crates/openhuman-embed/src/turn_tests.rs b/crates/openhuman-embed/src/turn_tests.rs
index a0ecc50677..623aae8bd4 100644
--- a/crates/openhuman-embed/src/turn_tests.rs
+++ b/crates/openhuman-embed/src/turn_tests.rs
@@ -183,3 +183,31 @@ fn sanitize_redacts_unparseable_urls() {
assert!(!normalized.contains("sk-secret"));
assert!(!normalized.contains("leaky"));
}
+
+/// `agent_chat` declares no input a seeded history could travel in.
+///
+/// This is why [`Turn::seed`] rides the target rather than [`TurnRequest`],
+/// and why the `TurnTarget::Runtime` arm refuses a seed instead of dropping
+/// it: that path speaks to the controller over these fields and there is
+/// nowhere in them to put history. If a future controller gains such an input,
+/// this test fails and the refusal can be reconsidered on purpose rather than
+/// discovered by an agent answering with no memory of the conversation.
+#[test]
+fn the_controller_declares_nowhere_for_a_seed_to_travel() {
+ let schema = openhuman_core::inference::host_runtime::all_local_inference_controller_schemas()
+ .into_iter()
+ .find(|s| s.namespace == "inference" && s.function == "agent_chat")
+ .expect("inference.agent_chat is a registered controller");
+
+ let carries_history = schema.inputs.iter().any(|field| {
+ let name = field.name.to_ascii_lowercase();
+ name.contains("history") || name.contains("messages") || name.contains("seed")
+ });
+
+ assert!(
+ !carries_history,
+ "agent_chat gained a history-shaped input ({:?}); Turn::seed refuses the \
+ Runtime path on the assumption it has none",
+ schema.inputs.iter().map(|f| f.name).collect::<Vec<_>>()
+ );
+}