Entropic 2.11.1
Local-first agentic inference engine
Loading...
Searching...
No Matches
final_text.h File Reference

Operator-visible final-text extraction for the external bridge. More...

#include <nlohmann/json.hpp>
#include <string>
Include dependency graph for final_text.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::string facade_text::extract_final_text (const char *result_json)
 Extract the answer text from a serialized conversation.
 
std::string facade_text::no_response_reason (const char *result_json)
 Explain why no answer text could be extracted (gh#130).
 
std::string facade_text::final_text_or_reason (const char *result_json)
 Final answer text, or a diagnostic when there is none.
 

Detailed Description

Operator-visible final-text extraction for the external bridge.

Private facade header. Extracted from external_bridge.cpp in v2.10.2 so the selection rule is directly unit-testable — gh#130 was a one-line scanning bug in a static helper with no test reachable to it.

Version
2.10.2

Definition in file final_text.h.

Function Documentation

◆ extract_final_text()

std::string facade_text::extract_final_text ( const char *  result_json)
inline

Extract the answer text from a serialized conversation.

Scans backwards for the most recent assistant message that actually has content, skipping empty ones.

Why empties must be skipped (gh#130)
A turn that ends without entropic.complete — e.g. anti-spiral rejects the lead's tool call and the next generation comes back finish=stop, 0 tool calls, 0 chars — leaves a trailing empty assistant message. Returning that empty content and stopping made the bridge answer "(no response)" while the real answer sat one or two messages earlier.

The worst case was a completed sub-tier delegation: fold_delegation_summary (gh#119, v2.9.17) already folds a child's summary into the lead's empty assistant turn precisely so this function can find it — but a later terminal empty assistant turn shadowed it, and the operator lost an answer the engine had correctly produced.

Why earlier user-role messages are NOT a fallback
Tool and delegation results are injected as role: "user" (tool_executor.cpp), and serialize_messages emits only {role, content} — so at this layer a delegation summary is indistinguishable from the operator's own prompt. Falling back to the last user message would echo the operator's question back as the answer, which is worse than admitting there is none. Delegation summaries reach us via the assistant-turn fold above, not by sniffing user messages.
Parameters
result_jsonSerialized conversation JSON array.
Returns
Most recent non-empty assistant content, or empty if there is none. @req REQ-API-012
Version
2.10.2

Definition at line 55 of file final_text.h.

◆ final_text_or_reason()

std::string facade_text::final_text_or_reason ( const char *  result_json)
inline

Final answer text, or a diagnostic when there is none.

Parameters
result_jsonSerialized conversation JSON array.
Returns
Answer text, else the reason there is none. @req REQ-API-012
Version
2.10.2

Definition at line 122 of file final_text.h.

◆ no_response_reason()

std::string facade_text::no_response_reason ( const char *  result_json)
inline

Explain why no answer text could be extracted (gh#130).

The bare "(no response)" the bridge used to return could not distinguish an engine failure from a model that simply stalled, which the consumer reported as its own diagnostic dead end. The returned strings keep "(no response" as their leading substring so prefix/substring matching on the old sentinel still fires; exact-equality matching does not.

Deliberately reports only what the conversation itself proves. Iteration counts and the specific precondition that fired (anti-spiral, budget) are not present in this JSON, so they are not invented here.

Parameters
result_jsonSerialized conversation JSON array.
Returns
Human-readable diagnostic for the empty-answer case. @req REQ-API-012
Version
2.10.2

Definition at line 93 of file final_text.h.