Getting access to the last message off an AI Agent

Describe the problem/error/question

I want to get access to the last message my AI Agent generated (gemini model) in a variable that i can proceed working with.

Is there any way to get this access?

{{ $json.output }} is normally your output

Yes, it’s in the output field of the AI Agent node’s JSON output, no matter which chat model is plugged into it.

Accessing it

The node right after AI Agent
Anywhere further downstream

Turning it into a reusable variable

  1. Add a Set (Edit Fields) node directly after the AI Agent node
  2. Create a field e.g. agentMessage
  3. Set its value to {{ $json.output }}
  4. From here on, reference {{ $json.agentMessage }} (or {{ $('Edit Fields').item.json.agentMessage }} from further away) instead of the raw agent output

To Check If It Is Not Working

  • Structured Output Parser enabled? If “Require Specific Output Format” is on, the response won’t be plain text in output anymore it’ll be whatever fields your schema defines instead.
  • Need token usage / model metadata, not just the text? That’s not in output, it only carries the final message. Pulling cost/token data requires a separate setup, since the Agent node doesn’t expose the raw Gemini response by default.