Replies: 1 comment
-
Hello, @akmaldira! I'm here to assist you with any bugs, questions, or contributions while we wait for a human maintainer. To get token usage for each step in an Here is a code snippet that demonstrates how you can track token usage for each step: import { AgentExecutor, CallbackManagerForChainRun } from "@langchain/core";
// Assuming you have an instance of AgentExecutor and inputs
const agentExecutor = new AgentExecutor({
agent: yourAgent,
tools: yourTools,
returnIntermediateSteps: true,
});
const runManager = new CallbackManagerForChainRun();
const result = await agentExecutor._call(inputs, runManager);
const tokenUsage = runManager.getTokenUsage();
console.log("Token usage for each step:", tokenUsage); In this example, For more detailed information on tracking token usage, you can refer to the LangChain documentation [1][2]. |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
how to get token usage for each step in an Agent Executor?
on event name OpenAIFunctionsAgent, RunnableAssign, RunnableMap and RunnableLambda is returning same usage_metadata
System Info
"@langchain/openai": "^0.2.1",
"@langchain/community": "^0.2.9",
"langchain": "^0.2.8"
Beta Was this translation helpful? Give feedback.
All reactions