Skip to content

revert: remove unnecessary prompt and parser changes from #156#169

Merged
graycyrus merged 1 commit intotinyhumansai:mainfrom
sanil-23:fix/reliable-provider-chat
Apr 1, 2026
Merged

revert: remove unnecessary prompt and parser changes from #156#169
graycyrus merged 1 commit intotinyhumansai:mainfrom
sanil-23:fix/reliable-provider-chat

Conversation

@sanil-23
Copy link
Copy Markdown
Contributor

@sanil-23 sanil-23 commented Apr 1, 2026

Summary

Problem

  • PR fix: reduce agent loop hallucination and improve tool call reliability #156 fixed the real bug (missing ReliableProvider.chat(ChatRequest)) but also included prompt changes and a bracket parser that were added during debugging
  • The prompt changes in instructions.rs replaced the original tool-use instructions with verbose anti-hallucination rules — unnecessary since the model was already calling tools correctly; the issue was the provider not forwarding them
  • The bracket parser ([TOOL_CALL] format) was only seen when the agent fell through to the text-only chat_with_history() path — now that native tools work, the model uses structured tool_calls, never bracket format

Solution

Submission Checklist

  • Unit testscargo check + cargo fmt pass
  • E2E / integration — Verified with real staging backend (agentic-v1): shell tool calls execute, file read works, multi-iteration tool loop completes, no Jinja template errors
  • N/A — No new code, only reverting unnecessary additions
  • Doc comments — N/A (reverts restore original comments)
  • Inline comments — N/A

Impact

  • Desktop + CLI: Prompt is slightly shorter (less noise for the model)
  • No behavioral change: The real fix (ReliableProvider.chat) remains untouched

Related

Summary by CodeRabbit

  • Refactor
    • Clarified AI agent instructions for improved consistency in tool call execution and result processing
    • Streamlined tool call parsing by standardizing on a single syntax format for better reliability

…i#156

The actual fix in tinyhumansai#156 was adding chat(ChatRequest) to
ReliableProvider. The prompt changes in instructions.rs and the
bracket tool call parser in parse.rs were added during investigation
but are not needed — the model uses native tool calls when
ReliableProvider properly delegates to the inner provider.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 1, 2026

📝 Walkthrough

Walkthrough

The pull request simplifies agent loop instructions by consolidating multiple anti-hallucination constraints into a single critical requirement and updating example guidance. Concurrently, bracket-style tool-call parsing logic and related open-tag entries are removed from the parser, with the fallback behavior simplified to emit warnings rather than attempt bracket pseudo-syntax extraction.

Changes

Cohort / File(s) Summary
Agent Loop Instructions
src/openhuman/agent/loop_/instructions.rs
Removed detailed numbered "Rules (MUST follow)" section with multiple constraints; replaced with single "CRITICAL" instruction. Updated example section from labeled block to inline directive with explicit <tool_call> payload. Added clarification on multiple tool calls and <tool_result> handling.
Agent Loop Parsing
src/openhuman/agent/loop_/parse.rs
Removed parse_bracket_tool_call() function and bracket-style markers ([TOOL_CALL], [tool_call]) from TOOL_CALL_OPEN_TAGS. Simplified parse_tool_calls() fallback to emit warning instead of attempting bracket pseudo-syntax parsing.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly Related PRs

Poem

🐰 The bracket syntax hops away,
Simplified rules now light the way,
One critical path shines so clear,
XML tags the agents cheer,
Parsing leaner, logic sincere! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: reverting unnecessary modifications from PR #156 to instructions.rs and parse.rs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@sanil-23 sanil-23 marked this pull request as draft April 1, 2026 15:16
@sanil-23 sanil-23 marked this pull request as ready for review April 1, 2026 15:19
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/openhuman/agent/loop_/instructions.rs (1)

12-18: Scope the “CRITICAL” rule to tool-invocation turns to avoid over-constraining normal replies.

The current wording is absolute (“never ... give examples”) while this block also provides an example. Tighten scope so the model understands this restriction applies when emitting tool calls, not to every response.

✏️ Suggested wording tweak
-    instructions.push_str(
-        "CRITICAL: Output actual <tool_call> tags—never describe steps or give examples.\n\n",
-    );
+    instructions.push_str(
+        "CRITICAL: When you need to call a tool, output actual <tool_call> tags only; do not describe intended tool-call steps in prose.\n\n",
+    );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openhuman/agent/loop_/instructions.rs` around lines 12 - 18, The
"CRITICAL" rule is currently absolute and over-constrains normal replies; update
the string literal that begins "CRITICAL: Output actual <tool_call> tags—never
describe steps or give examples." (the text assembled via the
instructions.push_str calls) so it explicitly applies only to turns where the
model is emitting tool invocations (e.g., say "When emitting <tool_call> tags:
...") and allow examples/descriptions in other contexts; keep the rest of the
guidance about providing examples and continuing reasoning (the subsequent
instructions.push_str blocks) consistent with this scoped wording change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/openhuman/agent/loop_/parse.rs`:
- Line 379: Replace the generic tracing::warn! call that logs "Malformed
<tool_call> JSON: expected tool-call object in tag body" with a structured
tracing::warn! that attaches the tag text and body length (e.g.,
tracing::warn!(open_tag = %open_tag, body_len = body.len(), "Malformed
<tool_call> JSON: expected tool-call object in tag body")); ensure you reference
the same variables used in this scope (open_tag and body) and keep the original
message text for consistency so production traces include the tag content and
size for diagnostics.
- Line 85: The parse logic lost compatibility with the "<tool>" wrapper causing
tool calls to be dropped; restore "<tool>" to the recognized open-tag list by
adding "<tool>" back into the TOOL_CALL_OPEN_TAGS constant, and ensure the
matching close-tag set (e.g., TOOL_CALL_CLOSE_TAGS or whatever close-tag
constant the parse_tool_calls function uses) includes "</tool>" so
parse_tool_calls correctly recognizes and extracts tool-call blocks (also
run/update any relevant tests that assert telegram provider "<tool>...</tool>"
behavior).

---

Nitpick comments:
In `@src/openhuman/agent/loop_/instructions.rs`:
- Around line 12-18: The "CRITICAL" rule is currently absolute and
over-constrains normal replies; update the string literal that begins "CRITICAL:
Output actual <tool_call> tags—never describe steps or give examples." (the text
assembled via the instructions.push_str calls) so it explicitly applies only to
turns where the model is emitting tool invocations (e.g., say "When emitting
<tool_call> tags: ...") and allow examples/descriptions in other contexts; keep
the rest of the guidance about providing examples and continuing reasoning (the
subsequent instructions.push_str blocks) consistent with this scoped wording
change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 05ccaede-62ac-48fa-89cd-b6e9069edfc9

📥 Commits

Reviewing files that changed from the base of the PR and between 3c247a2 and 881bac9.

📒 Files selected for processing (2)
  • src/openhuman/agent/loop_/instructions.rs
  • src/openhuman/agent/loop_/parse.rs

"[TOOL_CALL]",
"[tool_call]",
];
const TOOL_CALL_OPEN_TAGS: [&str; 4] = ["<tool_call>", "<toolcall>", "<tool-call>", "<invoke>"];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Restore <tool> tag compatibility to avoid silent missed tool dispatches.

Line 85 removes <tool> from recognized open tags, but src/openhuman/channels/providers/telegram/text.rs still treats <tool>...</tool> as a valid tool-call wrapper. If such output reaches parse_tool_calls, calls can be dropped and downstream fallback in tool_loop.rs/dispatcher.rs may silently no-op.

🔧 Proposed compatibility patch
-const TOOL_CALL_OPEN_TAGS: [&str; 4] = ["<tool_call>", "<toolcall>", "<tool-call>", "<invoke>"];
+const TOOL_CALL_OPEN_TAGS: [&str; 5] =
+    ["<tool_call>", "<toolcall>", "<tool-call>", "<tool>", "<invoke>"];

 pub(crate) fn matching_tool_call_close_tag(open_tag: &str) -> Option<&'static str> {
     match open_tag {
         "<tool_call>" => Some("</tool_call>"),
         "<toolcall>" => Some("</toolcall>"),
         "<tool-call>" => Some("</tool-call>"),
+        "<tool>" => Some("</tool>"),
         "<invoke>" => Some("</invoke>"),
         _ => None,
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openhuman/agent/loop_/parse.rs` at line 85, The parse logic lost
compatibility with the "<tool>" wrapper causing tool calls to be dropped;
restore "<tool>" to the recognized open-tag list by adding "<tool>" back into
the TOOL_CALL_OPEN_TAGS constant, and ensure the matching close-tag set (e.g.,
TOOL_CALL_CLOSE_TAGS or whatever close-tag constant the parse_tool_calls
function uses) includes "</tool>" so parse_tool_calls correctly recognizes and
extracts tool-call blocks (also run/update any relevant tests that assert
telegram provider "<tool>...</tool>" behavior).


if !parsed_any {
tracing::warn!("Malformed tool_call body: could not parse tag content as JSON or bracket syntax");
tracing::warn!("Malformed <tool_call> JSON: expected tool-call object in tag body");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Add structured debug context on malformed tag bodies.

Line 379 logs a generic warning only. Include open_tag and body size so parse failures are diagnosable in production traces.

🪵 Proposed logging improvement
-            if !parsed_any {
-                tracing::warn!("Malformed <tool_call> JSON: expected tool-call object in tag body");
-            }
+            if !parsed_any {
+                tracing::warn!(
+                    open_tag = %open_tag,
+                    body_len = inner.len(),
+                    "Malformed tool-call payload: expected tool-call object in tag body"
+                );
+            }

As per coding guidelines, src/**/*.rs changes should include substantial debug/trace logging on new or modified flows.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
tracing::warn!("Malformed <tool_call> JSON: expected tool-call object in tag body");
tracing::warn!(
open_tag = %open_tag,
body_len = inner.len(),
"Malformed tool-call payload: expected tool-call object in tag body"
);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openhuman/agent/loop_/parse.rs` at line 379, Replace the generic
tracing::warn! call that logs "Malformed <tool_call> JSON: expected tool-call
object in tag body" with a structured tracing::warn! that attaches the tag text
and body length (e.g., tracing::warn!(open_tag = %open_tag, body_len =
body.len(), "Malformed <tool_call> JSON: expected tool-call object in tag
body")); ensure you reference the same variables used in this scope (open_tag
and body) and keep the original message text for consistency so production
traces include the tag content and size for diagnostics.

@graycyrus graycyrus self-requested a review April 1, 2026 15:37
@graycyrus graycyrus merged commit 2383d51 into tinyhumansai:main Apr 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants