Skip to content

✅ Finalization Path (No Tool Calls)

_handle_no_tool_calls()

When the LLM produces a user-facing message (no more tools): When the model finishes without requesting tools, we run a fast “quality gate + polish” step to finalize the answer.

  1. Evaluations (quality gate) To catch issues with the produced message and inform the user about these. Typical checks is the hallucination detection. The EvaluationManager runs the checklist from ToolManager against the loop_response and latest assistant message. If any fail, we log a warning (future: retry with corrective instructions).
  2. Postprocessors Add additional information on top of the Message generated by the orchestrator. For example to add follow-up questions or attach stock ticker plots to the message

Code:

    async def _handle_no_tool_calls(
          self, loop_response: LanguageModelStreamResponse
    ) -> bool:
        """Handle the case where no tool calls are returned."""
        selected_evaluation_names = (
              self._tool_manager.get_evaluation_check_list()
        )
        evaluation_results = await self._evaluation_manager.run_evaluations(
              selected_evaluation_names, loop_response, self._latest_assistant_id
        )

        await self._postprocessor_manager.run_postprocessors(loop_response)

        if not all(result.is_positive for result in evaluation_results):
            self._logger.warning(
                  "we should add here the retry counter add an instruction and retry the loop for now we just exit the loop"
            )  # TODO: add retry counter and instruction

        return True