Adjust AI reasoning and output

Alan AI provides a human-in-the-loop capability, enabling you to directly intervene in the AI decision-making and fine-tune the AI reasoning process. You can adjust how the AI system arrives at its conclusions, generates code and produces data outputs. This way, you can make sure that the AI agent produces responses that are more accurate, relevant and contextually appropriate.

Note

This exercise covers basic cases of adjusting AI reasoning and output. For advanced cases, see Transforms.

Use case

As a developer, you can review the AI agent reasoning process and manually refine its logic. You can:

Prerequisites

To successfully follow this exercise, make sure the following prerequisites are met:

Adjust AI reasoning

When Alan AI generates code, you can review and adjust the code snippets for accuracy and relevance.

  1. In the Debugging Chat in Alan AI Studio, ask a question: Show all stopped VMs.

    ../../_images/incorrect-reasoning.png
  2. Use the reasoning graph to identify the cause of the problem. In this case, the AI agent generates the code that requires fine-tuning.

    ../../_images/incorrect-reasoning-graph.png
  3. In the code editor, open the infrastructure_queries transform. In the top right corner, click History.

  4. To the right of the Show all stopped VMs query, click the Plus icon to add the example to the transform examples list.

    ../../_images/add-query.png
  5. In the added example, click the Magnifying glass icon in the top left corner of any cell to zoom into the example data.

    ../../_images/example-preview-mode.png
  6. Review the code generated by the AI system. To test the code, in the top right corner of the Result pane, click the Run button.

    ../../_images/incorrect-code.png
  7. In the <thinking></thinking> block, adjust the AI reasoning in natural language. In this example, to fix the problem, you need to point the AI system to the correct data node. Then, remove the code below and click the Generate result button at the top of the pane.

    Alan AI will generate the correct code snippet using the instructions in the <thinking></thinking> block.

    ../../_images/correct-code.png
  8. To test the code, in the top right corner of the Result pane, click the Run button.

    ../../_images/correct-code-test.png
  9. Save the transform and test the same query in the Debugging Chat:

    ../../_images/correct-code-test-debug.png
  10. In the Debugging Chat, try similar queries, for example: Show all running VMs. Alan AI will apply the added example to provide correct responses for similar queries:

    ../../_images/correct-code-apply.png

Adjust the format of data output

Using instructions and examples in transforms, you can adjust the format of data output both for static and dynamic corpuses.

In this exercise, we will change the way the AI agent displays the infrastructure objects data. For more examples, see Transform instructions and examples.

  1. In the Dynamic corpus dialog script, update the corpus() function to add an output transform:

    Dialog script
    corpus({
        title: `Infrastructure requests`,
        query: transforms.infrastructure_queries,
        // Output transform
        transform: transforms.infrastructure_output,
        priority: 2
    });
    
  2. Under Transforms in the left pane, click Add to add a new transform named infrastructure_output.

  3. In the Instruction field, provide general instructions on how to format dynamic data:

    Transform instructions
    Highlight all infrastructure object names bold. Present all object data as a table including all object values.
    
    ../../_images/output-transform.png
  4. In the Debugging Chat, test the Show all running VMs query:

    ../../_images/output-transform-apply.png
  5. Open the infrastructure_output transform. In the top right corner, click History.

  6. To the right of the Show all running VMs query, click the Plus icon to add the example to the transform examples list. Then, zoom into the example data:

    ../../_images/output-transform-result.png
  7. At the top of the Result field, change the data format to response.

  8. Adjust the Full answer data, for example, change the leading phrase. Then save the transform.

    ../../_images/output-transform-result-fixed.png

Validation

Test the Show all running VMs query and similar queries in the Debugging Chat:

../../_images/output-transform-result-test.png

See also

Transforms