Skip to content

Commit cb53c34

Browse files
authored
Add additionalInfo field to ResponseMetaInfo (#367)
1 parent 95eb747 commit cb53c34

File tree

2 files changed

+14
-10
lines changed
  • agents/agents-features/agents-features-event-handler/src/jvmTest/kotlin/ai/koog/agents/features/eventHandler/feature
  • prompt/prompt-model/src/commonMain/kotlin/ai/koog/prompt/message

2 files changed

+14
-10
lines changed

agents/agents-features/agents-features-event-handler/src/jvmTest/kotlin/ai/koog/agents/features/eventHandler/feature/EventHandlerFeatureTest.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ class EventHandlerTest {
8484
"OnBeforeNode (node: __start__, input: ${agentInput})",
8585
"OnAfterNode (node: __start__, input: ${agentInput}, output: ${agentInput})",
8686
"OnBeforeNode (node: test LLM call, input: Test LLM call prompt)",
87-
"OnBeforeLLMCall (prompt: [System(content=Test system message, metaInfo=RequestMetaInfo(timestamp=$ts)), User(content=Test user message, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[]), Assistant(content=Test assistant response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null), attachment=null, finishReason=null), User(content=Test LLM call prompt, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[])], tools: [])",
87+
"OnBeforeLLMCall (prompt: [System(content=Test system message, metaInfo=RequestMetaInfo(timestamp=$ts)), User(content=Test user message, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[]), Assistant(content=Test assistant response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null, additionalInfo={}), attachment=null, finishReason=null), User(content=Test LLM call prompt, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[])], tools: [])",
8888
"OnAfterLLMCall (responses: [Assistant: Default test response])",
89-
"OnAfterNode (node: test LLM call, input: Test LLM call prompt, output: Assistant(content=Default test response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null), attachment=null, finishReason=null))",
89+
"OnAfterNode (node: test LLM call, input: Test LLM call prompt, output: Assistant(content=Default test response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null, additionalInfo={}), attachment=null, finishReason=null))",
9090
"OnStrategyFinished (strategy: $strategyName, result: $agentResult)",
9191
"OnAgentFinished (strategy: $strategyName, result: $agentResult)",
9292
)
@@ -128,9 +128,9 @@ class EventHandlerTest {
128128
"OnBeforeNode (node: __start__, input: ${agentInput})",
129129
"OnAfterNode (node: __start__, input: ${agentInput}, output: ${agentInput})",
130130
"OnBeforeNode (node: test LLM call, input: Test LLM call prompt)",
131-
"OnBeforeLLMCall (prompt: [System(content=Test system message, metaInfo=RequestMetaInfo(timestamp=$ts)), User(content=Test user message, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[]), Assistant(content=Test assistant response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null), attachment=null, finishReason=null), User(content=Test LLM call prompt, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[])], tools: [dummy])",
131+
"OnBeforeLLMCall (prompt: [System(content=Test system message, metaInfo=RequestMetaInfo(timestamp=$ts)), User(content=Test user message, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[]), Assistant(content=Test assistant response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null, additionalInfo={}), attachment=null, finishReason=null), User(content=Test LLM call prompt, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[])], tools: [dummy])",
132132
"OnAfterLLMCall (responses: [Assistant: Default test response])",
133-
"OnAfterNode (node: test LLM call, input: Test LLM call prompt, output: Assistant(content=Default test response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null), attachment=null, finishReason=null))",
133+
"OnAfterNode (node: test LLM call, input: Test LLM call prompt, output: Assistant(content=Default test response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null, additionalInfo={}), attachment=null, finishReason=null))",
134134
"OnStrategyFinished (strategy: $strategyName, result: $agentResult)",
135135
"OnAgentFinished (strategy: $strategyName, result: $agentResult)",
136136
)
@@ -174,13 +174,13 @@ class EventHandlerTest {
174174
"OnBeforeNode (node: __start__, input: ${agentInput})",
175175
"OnAfterNode (node: __start__, input: ${agentInput}, output: ${agentInput})",
176176
"OnBeforeNode (node: test LLM call, input: Test LLM call prompt)",
177-
"OnBeforeLLMCall (prompt: [System(content=Test system message, metaInfo=RequestMetaInfo(timestamp=$ts)), User(content=Test user message, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[]), Assistant(content=Test assistant response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null), attachment=null, finishReason=null), User(content=Test LLM call prompt, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[])], tools: [dummy])",
177+
"OnBeforeLLMCall (prompt: [System(content=Test system message, metaInfo=RequestMetaInfo(timestamp=$ts)), User(content=Test user message, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[]), Assistant(content=Test assistant response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null, additionalInfo={}), attachment=null, finishReason=null), User(content=Test LLM call prompt, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[])], tools: [dummy])",
178178
"OnAfterLLMCall (responses: [Assistant: Default test response])",
179-
"OnAfterNode (node: test LLM call, input: Test LLM call prompt, output: Assistant(content=Default test response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null), attachment=null, finishReason=null))",
179+
"OnAfterNode (node: test LLM call, input: Test LLM call prompt, output: Assistant(content=Default test response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null, additionalInfo={}), attachment=null, finishReason=null))",
180180
"OnBeforeNode (node: test LLM call with tools, input: Test LLM call with tools prompt)",
181-
"OnBeforeLLMCall (prompt: [System(content=Test system message, metaInfo=RequestMetaInfo(timestamp=$ts)), User(content=Test user message, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[]), Assistant(content=Test assistant response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null), attachment=null, finishReason=null), User(content=Test LLM call prompt, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[]), Assistant(content=Default test response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null), attachment=null, finishReason=null), User(content=Test LLM call with tools prompt, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[])], tools: [dummy])",
181+
"OnBeforeLLMCall (prompt: [System(content=Test system message, metaInfo=RequestMetaInfo(timestamp=$ts)), User(content=Test user message, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[]), Assistant(content=Test assistant response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null, additionalInfo={}), attachment=null, finishReason=null), User(content=Test LLM call prompt, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[]), Assistant(content=Default test response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null, additionalInfo={}), attachment=null, finishReason=null), User(content=Test LLM call with tools prompt, metaInfo=RequestMetaInfo(timestamp=$ts), attachments=[])], tools: [dummy])",
182182
"OnAfterLLMCall (responses: [Assistant: Default test response])",
183-
"OnAfterNode (node: test LLM call with tools, input: Test LLM call with tools prompt, output: Assistant(content=Default test response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null), attachment=null, finishReason=null))",
183+
"OnAfterNode (node: test LLM call with tools, input: Test LLM call with tools prompt, output: Assistant(content=Default test response, metaInfo=ResponseMetaInfo(timestamp=$ts, totalTokensCount=null, inputTokensCount=null, outputTokensCount=null, additionalInfo={}), attachment=null, finishReason=null))",
184184
"OnStrategyFinished (strategy: $strategyName, result: $agentResult)",
185185
"OnAgentFinished (strategy: $strategyName, result: $agentResult)",
186186
)

prompt/prompt-model/src/commonMain/kotlin/ai/koog/prompt/message/Message.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ public data class RequestMetaInfo(
246246
* @property totalTokensCount The total number of tokens involved in the response, including both input and output tokens, or null if not available.
247247
* @property inputTokensCount The number of tokens used in the input, or null if not available.
248248
* @property outputTokensCount The number of tokens generated in the output, or null if not available.
249+
* @property additionalInfo Additional metadata as a map of string keys to string values.
250+
* This can be used to store custom metadata that doesn't fit into the standard fields.
249251
* @property timestamp The timestamp indicating when the response was created.
250252
* Defaults to the current system time if not explicitly set.
251253
*/
@@ -255,6 +257,7 @@ public data class ResponseMetaInfo(
255257
public val totalTokensCount: Int? = null,
256258
public val inputTokensCount: Int? = null,
257259
public val outputTokensCount: Int? = null,
260+
public val additionalInfo: Map<String, String> = emptyMap(),
258261
) : MessageMetaInfo {
259262
/**
260263
* Companion object for the ResponseMetaInfo class.
@@ -272,8 +275,9 @@ public data class ResponseMetaInfo(
272275
clock: Clock,
273276
totalTokensCount: Int? = null,
274277
inputTokensCount: Int? = null,
275-
outputTokensCount: Int? = null
278+
outputTokensCount: Int? = null,
279+
additionalInfo: Map<String, String> = emptyMap()
276280
): ResponseMetaInfo =
277-
ResponseMetaInfo(clock.now(), totalTokensCount, inputTokensCount, outputTokensCount)
281+
ResponseMetaInfo(clock.now(), totalTokensCount, inputTokensCount, outputTokensCount, additionalInfo)
278282
}
279283
}

0 commit comments

Comments
 (0)