Skip to content

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

refactor(session_host): extract system prompt builder into its own module

Steven Enamakel660759cce89d
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 d121ed25a0..f24444e366 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session.rs
@@ -10,6 +10,8 @@ mod attachment_input;
#[path = "runtime_session_enrichment.rs"]
mod enrichment;
mod memory_ingest;
+#[path = "runtime_session_prompt.rs"]
+mod prompt;
mod permanent;
mod post_commit;
mod tool_rules;
@@ -271,84 +273,6 @@ impl OpenHumanTurnPrelude {
})
}
- fn build_system_prompt_tiered(&self) -> Result<crate::agent::prompts::TieredPrompt> {
- use crate::agent::prompts::{PromptContext, PromptTool};
- let surface = self
- .tool_surface
- .lock()
- .unwrap_or_else(std::sync::PoisonError::into_inner);
- let withheld = self.rule_withheld_tools(&surface);
- let specs = surface
- .visible_tool_specs
- .iter()
- .filter(|spec| !withheld.contains(&spec.name))
- .filter(|spec| {
- self.thread_id.is_some()
- || !crate::agent::tinyagents::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::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());
- prompt_tools.retain(|tool| !surface.permanent_tool_names.contains(tool.name.as_ref()));
- prompt_tools.retain(|tool| !withheld.contains(tool.name.as_ref()));
- let mut visible_tool_names = surface.tool_policy_session.visible_tool_names_for_prompt();
- visible_tool_names.retain(|name| !withheld.contains(name));
- visible_tool_names.retain(|name| !surface.permanent_tool_names.contains(name));
- if self.thread_id.is_none() {
- visible_tool_names.retain(|name| {
- !crate::agent::tinyagents::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,
- visible_tool_names: &visible_tool_names,
- tool_call_format: self.tool_dispatcher.tool_call_format(),
- connected_integrations: &mutable.connected_integrations,
- connected_identities_md: self.connected_identities_md(),
- 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> {
self.tool_surface
.lock()
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..2409c9eb39
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session_prompt.rs
@@ -0,0 +1,80 @@
+impl super::OpenHumanTurnPrelude {
+ pub(super) fn build_system_prompt_tiered(&self) -> Result<crate::agent::prompts::TieredPrompt> {
+ use crate::agent::prompts::{PromptContext, PromptTool};
+ let surface = self
+ .tool_surface
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner);
+ let withheld = self.rule_withheld_tools(&surface);
+ let specs = surface
+ .visible_tool_specs
+ .iter()
+ .filter(|spec| !withheld.contains(&spec.name))
+ .filter(|spec| {
+ self.thread_id.is_some()
+ || !crate::agent::tinyagents::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::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());
+ prompt_tools.retain(|tool| !surface.permanent_tool_names.contains(tool.name.as_ref()));
+ prompt_tools.retain(|tool| !withheld.contains(tool.name.as_ref()));
+ let mut visible_tool_names = surface.tool_policy_session.visible_tool_names_for_prompt();
+ visible_tool_names.retain(|name| !withheld.contains(name));
+ visible_tool_names.retain(|name| !surface.permanent_tool_names.contains(name));
+ if self.thread_id.is_none() {
+ visible_tool_names.retain(|name| {
+ !crate::agent::tinyagents::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,
+ visible_tool_names: &visible_tool_names,
+ tool_call_format: self.tool_dispatcher.tool_call_format(),
+ connected_integrations: &mutable.connected_integrations,
+ connected_identities_md: self.connected_identities_md(),
+ 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)]
+}