Skip to content

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

test: cover prompt tool catalogue fallback

Steven Enamakelf6b075d778d5
diff --git a/crates/openhuman-core/src/agent/prompts/mod_tests_builder_sections_tests.rs b/crates/openhuman-core/src/agent/prompts/mod_tests_builder_sections_tests.rs
index 98b629f9eb..77d8be67b5 100644
--- a/crates/openhuman-core/src/agent/prompts/mod_tests_builder_sections_tests.rs
+++ b/crates/openhuman-core/src/agent/prompts/mod_tests_builder_sections_tests.rs
@@ -484,6 +484,63 @@ fn tools_section_pformat_renders_signature_not_schema() {
);
}
+#[test]
+fn tools_section_renders_invalid_schema_tool_without_arguments() {
+ struct InvalidSchemaTool;
+ #[async_trait]
+ impl Tool for InvalidSchemaTool {
+ fn name(&self) -> &str {
+ "invalid_schema"
+ }
+
+ fn description(&self) -> &str {
+ "falls back to an argument-free catalogue entry"
+ }
+
+ fn parameters_schema(&self) -> serde_json::Value {
+ serde_json::Value::String("not JSON schema text".to_string())
+ }
+
+ async fn execute(
+ &self,
+ _args: serde_json::Value,
+ ) -> anyhow::Result<crate::tools::ToolResult> {
+ Ok(crate::tools::ToolResult::success("ok"))
+ }
+ }
+
+ let tools: Vec<Box<dyn Tool>> = vec![Box::new(InvalidSchemaTool)];
+ let prompt_tools = PromptTool::from_tools(&tools);
+ let ctx = PromptContext {
+ workspace_dir: Path::new("/tmp"),
+ model_name: "test-model",
+ agent_id: "",
+ tools: &prompt_tools,
+ workflows: &[],
+ dispatcher_instructions: "",
+ learned: LearnedContextData::default(),
+ visible_tool_names: &NO_FILTER,
+ tool_call_format: ToolCallFormat::PFormat,
+ connected_integrations: &[],
+ connected_identities_md: String::new(),
+ include_profile: false,
+ include_memory_md: false,
+ curated_snapshot: None,
+ user_identity: None,
+ personality_soul_md: None,
+ personality_memory_md: None,
+ personality_roster: vec![],
+ agents_md_global: None,
+ agents_md_local: None,
+ };
+
+ let rendered = ToolsSection.build(&ctx).unwrap();
+ assert!(
+ rendered.contains("Call as: `invalid_schema[]`"),
+ "invalid schemas must remain renderable without arguments, got:\n{rendered}"
+ );
+}
+
#[test]
fn tools_section_uses_pformat_signature_for_text_dispatchers() {
// Tool rendering is uniform across text dispatchers: always the
diff --git a/crates/openhuman-core/src/agent/prompts/sections.rs b/crates/openhuman-core/src/agent/prompts/sections.rs
index 0b8c5bd479..a468f23cb9 100644
--- a/crates/openhuman-core/src/agent/prompts/sections.rs
+++ b/crates/openhuman-core/src/agent/prompts/sections.rs
@@ -15,9 +15,6 @@ use std::fmt::Write;
use tinyagents_harness::tool_calling::dialect::render_pformat_catalogue;
use tinytools::ToolSpec;
-mod user_identity;
-pub use user_identity::UserIdentitySection;
-
// ─────────────────────────────────────────────────────────────────────────────
// Special sections (archetype, dynamic, reflection)
// ─────────────────────────────────────────────────────────────────────────────
@@ -121,6 +118,11 @@ pub struct UserMemorySection;
/// empty — keeps the prompt clean for users who haven't yet expressed
/// any reflection-style content.
pub struct UserReflectionsSection;
+/// Renders the authenticated user's non-secret identity fields
+/// (`id` / `name` / `email`) into the system prompt — see issue #926.
+/// Empty when [`PromptContext::user_identity`] is `None` or the identity has no
+/// populated fields. Tokens and opaque credentials are forbidden.
+pub struct UserIdentitySection;
/// Injects the user-specific, session-frozen workspace files
/// (`PROFILE.md` + `MEMORY.md`), each capped at [`USER_FILE_MAX_CHARS`].
@@ -696,3 +698,53 @@ impl PromptSection for DateTimeSection {
Ok(out)
}
}
+
+impl PromptSection for UserIdentitySection {
+ fn tier(&self) -> PromptTier {
+ // The signed-in user, which changes on login and on logout.
+ PromptTier::Volatile
+ }
+
+ fn name(&self) -> &str {
+ "user_identity"
+ }
+
+ fn build(&self, ctx: &PromptContext<'_>) -> Result<String> {
+ let identity = match ctx.user_identity.as_ref() {
+ Some(id) if !id.is_empty() => id,
+ _ => return Ok(String::new()),
+ };
+
+ let mut fields = String::new();
+ if let Some(name) = identity.name.as_deref().filter(|s| !s.trim().is_empty()) {
+ let _ = writeln!(fields, "- name: {}", sanitize_identity_field(name));
+ }
+ if let Some(email) = identity.email.as_deref().filter(|s| !s.trim().is_empty()) {
+ let _ = writeln!(fields, "- email: {}", sanitize_identity_field(email));
+ }
+ if let Some(id) = identity.id.as_deref().filter(|s| !s.trim().is_empty()) {
+ let _ = writeln!(fields, "- id: {}", sanitize_identity_field(id));
+ }
+ if fields.trim().is_empty() {
+ return Ok(String::new());
+ }
+
+ let mut out = String::from("## User\n\n");
+ out.push_str(
+ "The signed-in user is identified below. Use these fields directly in tool \
+ calls and do not ask the user to repeat them.\n\n",
+ );
+ out.push_str(&fields);
+ Ok(out.trim_end().to_string())
+ }
+}
+
+/// Collapse whitespace in a user-identity field for a single markdown bullet.
+fn sanitize_identity_field(s: &str) -> String {
+ s.chars()
+ .map(|c| if c == '\n' || c == '\r' { ' ' } else { c })
+ .collect::<String>()
+ .split_whitespace()
+ .collect::<Vec<_>>()
+ .join(" ")
+}
diff --git a/crates/openhuman-core/src/agent/prompts/sections/user_identity.rs b/crates/openhuman-core/src/agent/prompts/sections/user_identity.rs
deleted file mode 100644
index 204611ff64..0000000000
--- a/crates/openhuman-core/src/agent/prompts/sections/user_identity.rs
+++ /dev/null
@@ -1,64 +0,0 @@
-//! Rendering of the authenticated user's non-secret identity prompt block.
-
-use super::super::types::{PromptContext, PromptSection, PromptTier};
-use anyhow::Result;
-use std::fmt::Write;
-
-/// Renders the authenticated user's non-secret identity fields
-/// (`id` / `name` / `email`) into the system prompt — see issue #926.
-///
-/// Empty when [`PromptContext::user_identity`] is `None` or the
-/// identity has no populated fields. Tokens, refresh tokens, and any
-/// opaque credential material are forbidden — only the three
-/// identifying fields ship.
-pub struct UserIdentitySection;
-
-impl PromptSection for UserIdentitySection {
- fn tier(&self) -> PromptTier {
- // The signed-in user, which changes on login and on logout.
- PromptTier::Volatile
- }
-
- fn name(&self) -> &str {
- "user_identity"
- }
-
- fn build(&self, ctx: &PromptContext<'_>) -> Result<String> {
- let identity = match ctx.user_identity.as_ref() {
- Some(id) if !id.is_empty() => id,
- _ => return Ok(String::new()),
- };
-
- let mut fields = String::new();
- if let Some(name) = identity.name.as_deref().filter(|s| !s.trim().is_empty()) {
- let _ = writeln!(fields, "- name: {}", sanitize_identity_field(name));
- }
- if let Some(email) = identity.email.as_deref().filter(|s| !s.trim().is_empty()) {
- let _ = writeln!(fields, "- email: {}", sanitize_identity_field(email));
- }
- if let Some(id) = identity.id.as_deref().filter(|s| !s.trim().is_empty()) {
- let _ = writeln!(fields, "- id: {}", sanitize_identity_field(id));
- }
- if fields.trim().is_empty() {
- return Ok(String::new());
- }
-
- let mut out = String::from("## User\n\n");
- out.push_str(
- "The signed-in user is identified below. Use these fields directly in tool \
- calls and do not ask the user to repeat them.\n\n",
- );
- out.push_str(&fields);
- Ok(out.trim_end().to_string())
- }
-}
-
-/// Collapse whitespace in a user-identity field for a single markdown bullet.
-fn sanitize_identity_field(s: &str) -> String {
- s.chars()
- .map(|c| if c == '\n' || c == '\r' { ' ' } else { c })
- .collect::<String>()
- .split_whitespace()
- .collect::<Vec<_>>()
- .join(" ")
-}