Entropic 2.11.1
Local-first agentic inference engine
Loading...
Searching...
No Matches
tool_result_classify.cpp File Reference

Implementation of the tool-result content classifiers (#44). More...

#include <entropic/mcp/tool_result_classify.h>
#include <cctype>
Include dependency graph for tool_result_classify.cpp:

Go to the source code of this file.

Namespaces

namespace  entropic
 Activate model on GPU (WARM → ACTIVE).
 

Functions

ENTROPIC_EXPORT bool entropic::mcp::is_effectively_empty (std::string_view s)
 True if s is empty or contains only ASCII whitespace.
 
bool entropic::mcp::starts_with_json_error (std::string_view trimmed)
 True if input begins with a JSON top-level "error" key.
 
ENTROPIC_EXPORT void entropic::mcp::truncate_to_cap (std::string &content, int cap)
 Truncate tool-result content in place when it exceeds cap.
 
ENTROPIC_EXPORT bool entropic::mcp::looks_like_tool_error (std::string_view content)
 Heuristic: the rendered tool-result text reads as an error.
 

Detailed Description

Implementation of the tool-result content classifiers (#44).

Version
2.1.0

Definition in file tool_result_classify.cpp.

Function Documentation

◆ is_effectively_empty()

bool entropic::mcp::is_effectively_empty ( std::string_view  s)

True if s is empty or contains only ASCII whitespace.

True if input is empty or contains only ASCII whitespace.

@utility

Version
2.1.0

Byte-level emptiness: whitespace-only content counts as empty, so a tool that "succeeded" with nothing to say is classified ok_empty rather than ok.

Parameters
sTool result content (already truncated to the cap).
Returns
true for an empty or whitespace-only view, false as soon as any non-space byte is seen. @req REQ-MCP-019
Version
2.1.0

Definition at line 61 of file tool_result_classify.cpp.

◆ looks_like_tool_error()

bool entropic::mcp::looks_like_tool_error ( std::string_view  content)

Heuristic: the rendered tool-result text reads as an error.

Heuristic match for an error-shaped tool result string.

Recognises (case-insensitively, after stripping leading whitespace):

  • Error: … / ERROR …
  • [error] …
  • top-level { "error": … }

Negative case: "… error somewhere in the middle" is NOT classified as error — only leading-token shapes count.

@utility

Version
2.1.0

Anchored at the first non-space byte, so the word "error" appearing mid-string does NOT classify the result as an error.

Parameters
contentTool result content (already truncated to the cap).
Returns
true when the content leads with Error/ERROR, [error], or a top-level {"error": ...} object; false otherwise. @req REQ-MCP-019
Version
2.1.0

Definition at line 127 of file tool_result_classify.cpp.

◆ starts_with_json_error()

bool entropic::mcp::starts_with_json_error ( std::string_view  trimmed)
inline

True if input begins with a JSON top-level "error" key.

Deliberately shallow — a leading '{' plus an "error" key inside the first 32 bytes — so a nested "error" deep in a large payload does not reclassify an otherwise successful result.

Parameters
trimmedLeft-trimmed tool result content.
Returns
true for a {"error": ...}-shaped object, false otherwise. @req REQ-MCP-019
Version
2.1.0

Definition at line 80 of file tool_result_classify.cpp.

◆ truncate_to_cap()

void entropic::mcp::truncate_to_cap ( std::string &  content,
int  cap 
)

Truncate tool-result content in place when it exceeds cap.

Truncate content in place when it exceeds the byte cap.

Demo ask #6 (v2.1.0). When cap is 0, no-op. When content size exceeds cap, the content is shrunk to cap - tail.size() bytes followed by a trailing \\n[... truncated, N more bytes] marker so downstream consumers (the model, classification, the duplicate cache) see the bounded form with a clear signal that bytes were lost. Final size is ≤ cap.

Parameters
contentMutable string; truncated in place when exceeded.
capMaximum byte length. 0 disables. @utility
Version
2.1.1-rc1

Applied at the inbound boundary, BEFORE classification, duplicate recording and history, so the model, the classifier and the dedup cache all see the same bounded form and can tell bytes were lost.

Parameters
contentResult content, truncated in place.
capMaximum bytes; a cap of 0 (or negative) disables truncation.
Returns
Nothing — content is left untouched when it is already within cap, otherwise resized to at most cap bytes ending in a [... truncated, N more bytes] marker. @req REQ-MCP-019
Version
2.1.1-rc1

Definition at line 102 of file tool_result_classify.cpp.