Skip to content

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

refactor(runtime_session): extract prompt building into dedicated module

Steven Enamakel5de3512ecc04
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session.rs b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
index a42061da19..7e631f90dc 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -1,3 +1,5 @@
+mod prompt;
+
//! The live OpenHuman composition over `tinyagents_runtime::Session`.
//!
//! The mutex is intentionally narrow: it carries host preparation and
@@ -358,87 +360,6 @@ impl OpenHumanTurnPrelude {
}
}
- fn build_system_prompt_tiered(
- &self,
- learned: crate::agent::prompts::LearnedContextData,
- ) -> Result<crate::agent::prompts::TieredPrompt> {
- use crate::agent::prompts::{tool_call_format_from_dialect, PromptContext, PromptTool};
- let surface = self
- .tool_surface
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner);
- let specs = surface
- .visible_tool_specs
- .iter()
- .filter(|spec| {
- self.thread_id.is_some()
- || !crate::agent::tinyagents::harness_tool_registration::is_thread_goal_tool(
- &spec.name,
- )
- })
- .map(|spec| spec.as_ref().clone())
- .collect::<Vec<_>>();
- let instructions = self.tool_dispatcher.prompt_instructions(&specs);
- let tool_refs = surface
- .tools
- .iter()
- .chain(surface.synthesized_tools.iter())
- .filter(|tool| {
- self.thread_id.is_some()
- || !crate::agent::tinyagents::harness_tool_registration::is_thread_goal_tool(
- tool.name(),
- )
- })
- .map(|tool| tool.as_ref())
- .collect::<Vec<_>>();
- let mut prompt_tools = PromptTool::from_tool_refs(tool_refs.iter().copied());
- let mut visible_tool_names = surface.tool_policy_session.visible_tool_names_for_prompt();
- if self.thread_id.is_none() {
- visible_tool_names.retain(|name| {
- !crate::agent::tinyagents::harness_tool_registration::is_thread_goal_tool(name)
- });
- }
- crate::agent::prompts::swap_deferred_for_discovery_bridge(
- &mut prompt_tools,
- &mut visible_tool_names,
- &surface.deferred_tool_names,
- );
- let agents_md = if self.config.agents_md_enabled {
- crate::agent::prompts::load_agents_md_layers(&self.workspace_dir, &self.action_dir)
- } else {
- Default::default()
- };
- let mutable = self
- .mutable
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner);
- let context = PromptContext {
- workspace_dir: &self.workspace_dir,
- model_name: &self.model_name,
- agent_id: &self.agent_definition_name,
- tools: &prompt_tools,
- workflows: &mutable.workflows,
- dispatcher_instructions: &instructions,
- learned,
- visible_tool_names: &visible_tool_names,
- tool_call_format: tool_call_format_from_dialect(
- self.tool_dispatcher.tool_call_format(),
- ),
- connected_integrations: &mutable.connected_integrations,
- connected_identities_md: crate::agent::prompts::render_connected_identities(),
- include_profile: !self.omit_profile,
- include_memory_md: !self.omit_memory_md,
- curated_snapshot: None,
- user_identity: crate::security::credentials::identity::peek_credential_user_identity(),
- personality_roster: vec![],
- agents_md_global: agents_md.global,
- agents_md_local: agents_md.local,
- };
- self.context
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner)
- .build_system_prompt_tiered(&context)
- }
#[cfg(test)]
fn synthesized_tool_names_for_test(&self) -> std::collections::HashSet<String> {
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/prompt.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/prompt.rs
new file mode 100644
index 0000000000..a9e306e24b
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/prompt.rs
@@ -0,0 +1,86 @@
+use super::*;
+
+impl OpenHumanTurnPrelude {
+ pub(super) fn build_system_prompt_tiered(
+ &self,
+ learned: crate::agent::prompts::LearnedContextData,
+ ) -> Result<crate::agent::prompts::TieredPrompt> {
+ use crate::agent::prompts::{tool_call_format_from_dialect, PromptContext, PromptTool};
+ let surface = self
+ .tool_surface
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
+ let specs = surface
+ .visible_tool_specs
+ .iter()
+ .filter(|spec| {
+ self.thread_id.is_some()
+ || !crate::agent::tinyagents::harness_tool_registration::is_thread_goal_tool(
+ &spec.name,
+ )
+ })
+ .map(|spec| spec.as_ref().clone())
+ .collect::<Vec<_>>();
+ let instructions = self.tool_dispatcher.prompt_instructions(&specs);
+ let tool_refs = surface
+ .tools
+ .iter()
+ .chain(surface.synthesized_tools.iter())
+ .filter(|tool| {
+ self.thread_id.is_some()
+ || !crate::agent::tinyagents::harness_tool_registration::is_thread_goal_tool(
+ tool.name(),
+ )
+ })
+ .map(|tool| tool.as_ref())
+ .collect::<Vec<_>>();
+ let mut prompt_tools = PromptTool::from_tool_refs(tool_refs.iter().copied());
+ let mut visible_tool_names = surface.tool_policy_session.visible_tool_names_for_prompt();
+ if self.thread_id.is_none() {
+ visible_tool_names.retain(|name| {
+ !crate::agent::tinyagents::harness_tool_registration::is_thread_goal_tool(name)
+ });
+ }
+ crate::agent::prompts::swap_deferred_for_discovery_bridge(
+ &mut prompt_tools,
+ &mut visible_tool_names,
+ &surface.deferred_tool_names,
+ );
+ let agents_md = if self.config.agents_md_enabled {
+ crate::agent::prompts::load_agents_md_layers(&self.workspace_dir, &self.action_dir)
+ } else {
+ Default::default()
+ };
+ let mutable = self
+ .mutable
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
+ let context = PromptContext {
+ workspace_dir: &self.workspace_dir,
+ model_name: &self.model_name,
+ agent_id: &self.agent_definition_name,
+ tools: &prompt_tools,
+ workflows: &mutable.workflows,
+ dispatcher_instructions: &instructions,
+ learned,
+ visible_tool_names: &visible_tool_names,
+ tool_call_format: tool_call_format_from_dialect(
+ self.tool_dispatcher.tool_call_format(),
+ ),
+ connected_integrations: &mutable.connected_integrations,
+ connected_identities_md: crate::agent::prompts::render_connected_identities(),
+ include_profile: !self.omit_profile,
+ include_memory_md: !self.omit_memory_md,
+ curated_snapshot: None,
+ user_identity: crate::security::credentials::identity::peek_credential_user_identity(),
+ personality_roster: vec![],
+ agents_md_global: agents_md.global,
+ agents_md_local: agents_md.local,
+ };
+ self.context
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner)
+ .build_system_prompt_tiered(&context)
+ }
+
+}