Overview
Call track_agent_response after the LLM returns its completion. This event captures the output text, token counts, and optional cost, and links back to the originating track_agent_call event via the shared messageId / message_id.
Required fields
Node.js / Python SDK: distinctId / distinct_id is also required. Browser SDK: optional if the user has already called Trodo.identify() in the session.
| Field (Node / Browser) | Field (Python) | Type | Description |
|---|
agentId | agent_id | string | The registered agent ID — e.g. 'agt_abc12345' |
conversationId | conversation_id | string | Stable ID for the conversation thread |
messageId | message_id | string | Unique ID for this specific message turn |
distinctId | distinct_id | string | Links the event to a Trodo user (required in Node/Python; optional in Browser if identify() was called) |
Optional fields
| Field (Node / Browser) | Field (Python) | Type | Description |
|---|
output | output | string | The LLM’s text output (optional — may be large) |
model | model | string | LLM identifier — e.g. 'gpt-4o', 'claude-3-5-sonnet' |
inputTokens | input_tokens | number | Prompt / input token count |
outputTokens | output_tokens | number | Completion / output token count |
cost | cost | number | Total cost in USD for this response |
timestamp | timestamp | ISO 8601 string | Override event time |
Examples
Trodo.track_agent_response({
agentId: 'agt_abc12345',
conversationId: 'conv_9kx2m7pq',
messageId: 'msg_01jf3t8r',
output: 'Your last invoice (inv_4421) for $149.00 was paid on March 12.',
model: 'gpt-4o',
inputTokens: 312,
outputTokens: 28,
cost: 0.00137,
});
// response = await openai.chat.completions.create(...)
await trodo.track_agent_response({
agentId: 'agt_abc12345',
conversationId: 'conv_9kx2m7pq',
messageId: 'msg_01jf3t8r',
distinctId: 'user_7hq29zal',
output: response.choices[0].message.content,
model: response.model,
inputTokens: response.usage.prompt_tokens,
outputTokens: response.usage.completion_tokens,
// cost = (prompt_tokens * 0.000003) + (completion_tokens * 0.000015)
cost:
response.usage.prompt_tokens * 0.000003 +
response.usage.completion_tokens * 0.000015,
});
# response = await anthropic_client.messages.create(...)
# cost = (input_tokens * 0.000003) + (output_tokens * 0.000015)
cost = (
response.usage.input_tokens * 0.000003
+ response.usage.output_tokens * 0.000015
)
await trodo.track_agent_response(
AgentResponseProps(
agent_id='agt_abc12345',
conversation_id='conv_9kx2m7pq',
message_id='msg_01jf3t8r',
distinct_id='user_7hq29zal',
output=response.content[0].text,
model=response.model,
input_tokens=response.usage.input_tokens,
output_tokens=response.usage.output_tokens,
cost=cost,
)
)