# History

During each interaction with your agent (through `carter.say()` and `carter.opener()`),`carter-js` will log the interaction to the Carter object's `history` property. This property stores an array of all the interactions with your Carter agent while your program is running, the most recent being at the start of the array. You can access these in a couple of ways.

<pre class="language-javascript"><code class="lang-javascript">// Assuming you have created a Carter object called carter

// Access the latest interaction
<strong>const lastInteraction = carter.history[0]
</strong>// OR
const lastInteraction = carter.latest()

// Access a specific entry
const interaction = carter.history[7]

// Loop through interactions and log the results
for (const interactions of carter.history) {
    console.log(interaction.payload.text) // Your message to carter
    console.log(interaction.outputText) // His response
}
</code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lazylyrics.gitbook.io/carter-js-v4/conversation/history.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
