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
feat(embed): add turn control for embedding sessions
Steven Enamakelc6f9e9fa6718
diff --git a/crates/openhuman-embed/src/lib.rs b/crates/openhuman-embed/src/lib.rsindex dfd623d32f..5783a92903 100644--- a/crates/openhuman-embed/src/lib.rs+++ b/crates/openhuman-embed/src/lib.rs@@ -91,7 +91,7 @@ pub use openhuman_core::tools::toolpacks::{GroupMode, ToolGroups};// vendored tinytools. An embedder that took `tinytools` as its own dependency// would build tools of a different, incompatible type.pub use openhuman_core::agent::tinyagents::host::LastTurnUsage;-pub use openhuman_core::agent::{HostTools, HostTurnTools, TurnContext};+pub use openhuman_core::agent::{HostAttachment, HostTools, HostTurnTools, TurnContext};pub use openhuman_core::{CoreBuilder, CoreRuntime, DaemonConfig, DomainSet, HostKind, ServiceSet, TokenSource,};diff --git a/crates/openhuman-embed/src/turn.rs b/crates/openhuman-embed/src/turn.rsindex e3fedd4f9d..c2e9187c22 100644--- a/crates/openhuman-embed/src/turn.rs+++ b/crates/openhuman-embed/src/turn.rs@@ -74,6 +74,7 @@ pub struct Turn {origin: Option<AgentTurnOrigin>,progress: Option<tokio::sync::mpsc::Sender<AgentProgress>>,seed: Option<Vec<(String, String)>>,+ attachments: Vec<openhuman_core::agent::HostAttachment>,meter: Option<Box<dyn FnOnce(Option<LastTurnUsage>) + Send>>,response_format: Option<crate::complete::ResponseFormat>,structured_retries: u8,@@ -103,6 +104,7 @@ impl Turn {origin: None,progress: None,seed: None,+ attachments: Vec::new(),meter: None,response_format: None,structured_retries: 0,@@ -257,6 +259,46 @@ impl Turn {self}+ /// Attach a file to this turn's message, after any already attached.+ ///+ /// The host hands over the bytes; the file is staged into the agent's+ /// acting workspace and reaches the model ahead of the message, as an+ /// image block (`image/*`) or a document block (anything else). A model+ /// that cannot take the file natively gets the core's fallback instead:+ /// extracted text for documents, a vision readout for images. The+ /// configured multimodal count and size limits apply, and a turn over+ /// them fails before it runs. No local path is read, so attachments are+ /// accepted whatever the turn's [`origin`](Self::origin).+ ///+ /// Only a runtime-owned [`Agent`](crate::Agent) can honour this; a turn on+ /// a caller-built runtime's orchestrator is refused rather than run+ /// without its files.+ ///+ /// ```no_run+ /// # use openhuman_embed::{Agent, HostAttachment};+ /// # async fn go(agent: &Agent, photo: Vec<u8>) -> anyhow::Result<()> {+ /// agent.turn("what is in this picture?")+ /// .attach(HostAttachment::new(photo, "image/jpeg").named("photo.jpg"))+ /// .send()+ /// .await?;+ /// # Ok(()) }+ /// ```+ #[must_use]+ pub fn attach(mut self, attachment: openhuman_core::agent::HostAttachment) -> Self {+ self.attachments.push(attachment);+ self+ }++ /// Attach every file in `attachments`, in order; see [`attach`](Self::attach).+ #[must_use]+ pub fn attachments(+ mut self,+ attachments: impl IntoIterator<Item = openhuman_core::agent::HostAttachment>,+ ) -> Self {+ self.attachments.extend(attachments);+ self+ }+/// Report what this turn spent, whether or not it succeeded.////// [`TurnOutcome::usage`] carries the same figures, but only when there is@@ -456,6 +498,7 @@ struct AgentTurnOptions {tools: Option<openhuman_core::agent::HostTools>,shape: std::sync::Arc<ResponseShapeScope>,untrusted_input: bool,+ attachments: Vec<openhuman_core::agent::HostAttachment>,}async fn dispatch(@@ -488,6 +531,20 @@ async fn dispatch(expected_user_state: true,});}+ // Refused for the same reason: `AGENT_CHAT` carries a string, and+ // a turn that silently ran without its files would answer about+ // something it never saw.+ if !options.attachments.is_empty() {+ return Err(CoreError::Domain {+ method: AGENT_CHAT,+ message: "attachments are not supported on a caller-built runtime's \+ orchestrator; run the turn on a runtime-owned Agent"+ .to_owned(),+ kind: Some("attachments_unsupported".to_owned()),+ data: None,+ expected_user_state: true,+ });+ }call::<_, String>(&rt, AGENT_CHAT, &request).await.map(|reply| (reply, None))@@ -523,6 +580,7 @@ async fn dispatch(host_only: inner.host_only,untrusted_input: options.untrusted_input,shape: Some(&options.shape),+ attachments: &options.attachments,};let outcome = agent_chat_for(&mut config,diff --git a/crates/openhuman-embed/src/turn_control.rs b/crates/openhuman-embed/src/turn_control.rsindex 1549866b97..eb80a94255 100644--- a/crates/openhuman-embed/src/turn_control.rs+++ b/crates/openhuman-embed/src/turn_control.rs@@ -353,6 +353,7 @@ impl Turn {),untrusted_input: self.untrusted_input,tools: self.tools.take(),+ attachments: std::mem::take(&mut self.attachments),};let budget = self.budget.take().map(|budget| crate::budget::ModelBudget {ledger: budget.ledger.child(crate::budget::SpendLimits::default()),