Hi @manueltnc I got some confirmation from @oleg here - unfortunately it’s not possible to reference the execution data of sub-nodes at this point. There isn’t a simple way to do this currently
It’s possible to use n8n node to retrieve full execution data which also contains the sub-nodes data like tokenUsage, but that cannot be done in the same execution(as you need the executionId to retrieve already finished execution).
I’m going to move this over to the feature request forum for you, and hopefully that workaround will help you in the meantime!
Quick edit - this wouldn’t be necessarily a “pretty” way to do it, but this should do what you need for past executions:
I found myself trying to the exactly the same but in my case using Basic LLM Chain and I’m not managing to do so. My runData only contains the following:
Hi @Luciano_Penafiel Just to be sure we’re on the same page, you’re looking at the full execution data of a workflow and you’re getting that? If so, I wouldn’t know - but @oleg might
Is there any way to make this work with an AI Agent node?
The Code node for “Extract Token Usage” doesn’t connect with the Chat Model in an AI Agent node.
I’d like to track token usage in an AI Agent, which it shows in the Chat Model sub-node, but it doesn’t display in the AI Agent main-node and I can’t find any way of extracting it from the sub-node.
I believe this is a Bug. 3 of the AI Agents have a hardcoded list of input nodes, which not include the Langchain Code Node. Those are: “conversationalAgent”, “toolsAgent” and “openAiFunctionsAgent”. You can check the relevant code here:
I believe there is some reason for that, but “Langchain Code” should be on that filter list.
I actually found a simple workaround. You could select any other of the Agents types, such as SQL Agent, connect to the Langchain Code, and then change back to the AI Agent type you were using. The verification is not done this way, and the Token Usage Count works just fine. Or you could simply copy the workflow below:
If you remove the connection between the nodes, you can’t connect it back without changing the AI type.