Skip to content

Conversation

denis-domanskii
Copy link
Contributor

@denis-domanskii denis-domanskii commented Jul 4, 2025

The existing fact-retrieval strategy in history compression doesn't work because of LLM hallucination issues (tldr: after ~200 tool call messages and with old System message, LLM ignores "now summarize previous history" request and continues to do the original task).

To fix the issue, several changes were made:

  • Update fact extraction messages
  • Replace original System message with the fact extractor one
  • Combine all history into one free-format message to avoid implicit few-shot learning
  • Compression feature now using a structured outputs for extracted facts
  • Unit test added

Also I performed manual checks - looks fine.


Type of the change

  • New feature
  • Bug fix
  • Documentation fix

Checklist for all pull requests

  • The pull request has a description of the proposed change
  • I read the Contributing Guidelines before opening the pull request
  • The pull request uses develop as the base branch
  • Tests for the changes have been added
  • All new and existing tests passed
Additional steps for pull requests adding a new feature
  • An issue describing the proposed change exists
  • The pull request includes a link to the issue
  • The change was discussed and approved in the issue
  • Docs have been added / updated

Copy link

github-actions bot commented Jul 4, 2025

Qodana for JVM

178 new problems were found

Inspection name Severity Problems
Check Kotlin and Java source code coverage 🔶 Warning 148
Missing KDoc for public API declaration 🔶 Warning 17
Unused import directive 🔶 Warning 9
Vulnerable imported dependency 🔶 Warning 4
@@ Code coverage @@
+ 56% total lines covered
6090 lines analyzed, 3447 lines covered
# Calculated according to the filters of your coverage tool

☁️ View the detailed Qodana report

Detected 204 dependencies

Third-party software list

This page lists the third-party software dependencies used in koog-agents

Dependency Version Licenses
annotations 13.0 Apache-2.0
annotations 23.0.0 Apache-2.0
atomicfu-js 0.26.1 Apache-2.0
atomicfu-js 0.27.0 Apache-2.0
atomicfu-wasm-js 0.26.1 Apache-2.0
atomicfu-wasm-js 0.27.0 Apache-2.0
classmate 1.7.0 Apache-2.0
config 1.4.3 Apache-2.0
dokka-core 2.0.0 Apache-2.0
dokka-gradle-plugin 2.0.0 Apache-2.0
fus-statistics-gradle-plugin 2.1.21 Apache-2.0
jackson-annotations 2.12.7 Apache-2.0
jackson-annotations 2.19.1 Apache-2.0
jackson-core 2.12.7 Apache-2.0
jackson-core 2.19.1 Apache-2.0
jackson-databind 2.12.7.1 Apache-2.0
jackson-databind 2.19.1 Apache-2.0
jackson-dataformat-xml 2.12.7 Apache-2.0
jackson-datatype-jdk8 2.19.1 Apache-2.0
jackson-datatype-jsr310 2.19.1 Apache-2.0
jackson-module-jaxb-annotations 2.12.7 Apache-2.0
jackson-module-kotlin 2.12.7 Apache-2.0
jackson-module-kotlin 2.19.1 Apache-2.0
jackson-module-parameter-names 2.19.1 Apache-2.0
jakarta.activation-api 1.2.1 BSD-3-Clause
jakarta.annotation-api 2.1.1 Classpath-exception-2.0
EPL-2.0
GPL-2.0-only
jakarta.validation-api 3.0.2 Apache-2.0
jakarta.xml.bind-api 2.3.2 BSD-3-Clause
jboss-logging 3.6.1.final Apache-2.0
jet-sign 45.47 Apache-2.0
jul-to-slf4j 2.0.17 MIT
kotlin-dom-api-compat 2.1.21 Apache-2.0
kotlin-gradle-plugin-api 2.1.21 Apache-2.0
kotlin-gradle-plugin-model 2.1.21 Apache-2.0
kotlin-gradle-plugin 2.1.21 Apache-2.0
kotlin-logging-js 7.0.7 Apache-2.0
kotlin-logging-jvm 7.0.7 Apache-2.0
kotlin-logging-wasm-js 7.0.7 Apache-2.0
kotlin-logging 7.0.7 Apache-2.0
kotlin-reflect 2.0.21 Apache-2.0
kotlin-reflect 2.1.20 Apache-2.0
kotlin-reflect 2.1.21 Apache-2.0
kotlin-sdk-jvm 0.5.0 MIT
kotlin-stdlib-js 2.1.21 Apache-2.0
kotlin-stdlib-wasm-js 2.1.21 Apache-2.0
kotlin-stdlib 2.0.21 Apache-2.0
kotlin-stdlib 2.1.21 Apache-2.0
kotlinx-coroutines-core-js 1.10.2 Apache-2.0
kotlinx-coroutines-core-jvm 1.10.2 Apache-2.0
kotlinx-coroutines-core-jvm 1.8.0 Apache-2.0
kotlinx-coroutines-core-wasm-js 1.10.2 Apache-2.0
kotlinx-coroutines-core 1.10.2 Apache-2.0
kotlinx-coroutines-reactive 1.10.2 Apache-2.0
kotlinx-coroutines-slf4j 1.10.2 Apache-2.0
kotlinx-datetime-js 0.6.2 Apache-2.0
kotlinx-datetime-jvm 0.6.2 Apache-2.0
kotlinx-datetime-wasm-js 0.6.2 Apache-2.0
kotlinx-datetime 0.6.2 Apache-2.0
kotlinx-io-bytestring-js 0.7.0 Apache-2.0
kotlinx-io-bytestring-jvm 0.7.0 Apache-2.0
kotlinx-io-bytestring-wasm-js 0.7.0 Apache-2.0
kotlinx-io-bytestring 0.7.0 Apache-2.0
kotlinx-io-core-js 0.7.0 Apache-2.0
kotlinx-io-core-jvm 0.7.0 Apache-2.0
kotlinx-io-core-wasm-js 0.7.0 Apache-2.0
kotlinx-io-core 0.7.0 Apache-2.0
kotlinx-serialization-core-js 1.8.1 Apache-2.0
kotlinx-serialization-core-jvm 1.8.1 Apache-2.0
kotlinx-serialization-core-wasm-js 1.8.1 Apache-2.0
kotlinx-serialization-core 1.8.1 Apache-2.0
kotlinx-serialization-json-io-js 1.8.1 Apache-2.0
kotlinx-serialization-json-io-jvm 1.8.1 Apache-2.0
kotlinx-serialization-json-io-wasm-js 1.8.1 Apache-2.0
kotlinx-serialization-json-io 1.8.1 Apache-2.0
kotlinx-serialization-json-js 1.8.1 Apache-2.0
kotlinx-serialization-json-jvm 1.8.1 Apache-2.0
kotlinx-serialization-json-wasm-js 1.8.1 Apache-2.0
kotlinx-serialization-json 1.8.1 Apache-2.0
ktor-client-cio-js 3.1.3 Apache-2.0
ktor-client-cio-jvm 3.1.3 Apache-2.0
ktor-client-cio-wasm-js 3.1.3 Apache-2.0
ktor-client-cio 3.1.3 Apache-2.0
ktor-client-content-negotiation-js 3.1.3 Apache-2.0
ktor-client-content-negotiation-jvm 3.1.3 Apache-2.0
ktor-client-content-negotiation-wasm-js 3.1.3 Apache-2.0
ktor-client-content-negotiation 3.1.3 Apache-2.0
ktor-client-core-js 3.1.3 Apache-2.0
ktor-client-core-jvm 3.1.3 Apache-2.0
ktor-client-core-wasm-js 3.1.3 Apache-2.0
ktor-client-core 3.1.3 Apache-2.0
ktor-client-js-js 3.1.3 Apache-2.0
ktor-client-logging-js 3.1.3 Apache-2.0
ktor-client-logging-jvm 3.1.3 Apache-2.0
ktor-client-logging-wasm-js 3.1.3 Apache-2.0
ktor-client-logging 3.1.3 Apache-2.0
ktor-events-js 3.1.3 Apache-2.0
ktor-events-jvm 3.1.3 Apache-2.0
ktor-events-wasm-js 3.1.3 Apache-2.0
ktor-events 3.1.3 Apache-2.0
ktor-http-cio-js 3.1.3 Apache-2.0
ktor-http-cio-jvm 3.1.3 Apache-2.0
ktor-http-cio-wasm-js 3.1.3 Apache-2.0
ktor-http-cio 3.1.3 Apache-2.0
ktor-http-js 3.1.3 Apache-2.0
ktor-http-jvm 3.1.3 Apache-2.0
ktor-http-wasm-js 3.1.3 Apache-2.0
ktor-http 3.1.3 Apache-2.0
ktor-io-js 3.1.3 Apache-2.0
ktor-io-jvm 3.1.3 Apache-2.0
ktor-io-wasm-js 3.1.3 Apache-2.0
ktor-io 3.1.3 Apache-2.0
ktor-network-js 3.1.3 Apache-2.0
ktor-network-jvm 3.1.3 Apache-2.0
ktor-network-tls-js 3.1.3 Apache-2.0
ktor-network-tls-jvm 3.1.3 Apache-2.0
ktor-network-tls-wasm-js 3.1.3 Apache-2.0
ktor-network-tls 3.1.3 Apache-2.0
ktor-network-wasm-js 3.1.3 Apache-2.0
ktor-network 3.1.3 Apache-2.0
ktor-serialization-js 3.1.3 Apache-2.0
ktor-serialization-jvm 3.1.3 Apache-2.0
ktor-serialization-kotlinx-js 3.1.3 Apache-2.0
ktor-serialization-kotlinx-json-js 3.1.3 Apache-2.0
ktor-serialization-kotlinx-json-jvm 3.1.3 Apache-2.0
ktor-serialization-kotlinx-json-wasm-js 3.1.3 Apache-2.0
ktor-serialization-kotlinx-json 3.1.3 Apache-2.0
ktor-serialization-kotlinx-jvm 3.1.3 Apache-2.0
ktor-serialization-kotlinx-wasm-js 3.1.3 Apache-2.0
ktor-serialization-kotlinx 3.1.3 Apache-2.0
ktor-serialization-wasm-js 3.1.3 Apache-2.0
ktor-serialization 3.1.3 Apache-2.0
ktor-server-cio-jvm 3.1.3 Apache-2.0
ktor-server-cio 3.1.3 Apache-2.0
ktor-server-core-jvm 3.1.3 Apache-2.0
ktor-server-core 3.1.3 Apache-2.0
ktor-server-sse-jvm 3.1.3 Apache-2.0
ktor-server-sse 3.1.3 Apache-2.0
ktor-server-websockets-jvm 3.0.2 Apache-2.0
ktor-sse-js 3.1.3 Apache-2.0
ktor-sse-jvm 3.1.3 Apache-2.0
ktor-sse-wasm-js 3.1.3 Apache-2.0
ktor-sse 3.1.3 Apache-2.0
ktor-utils-js 3.1.3 Apache-2.0
ktor-utils-jvm 3.1.3 Apache-2.0
ktor-utils-wasm-js 3.1.3 Apache-2.0
ktor-utils 3.1.3 Apache-2.0
ktor-websocket-serialization-js 3.1.3 Apache-2.0
ktor-websocket-serialization-jvm 3.1.3 Apache-2.0
ktor-websocket-serialization-wasm-js 3.1.3 Apache-2.0
ktor-websocket-serialization 3.1.3 Apache-2.0
ktor-websockets-js 3.1.3 Apache-2.0
ktor-websockets-jvm 3.1.3 Apache-2.0
ktor-websockets-wasm-js 3.1.3 Apache-2.0
ktor-websockets 3.1.3 Apache-2.0
lettuce-core 6.5.5.release MIT
log4j-api 2.24.3 Apache-2.0
log4j-to-slf4j 2.24.3 Apache-2.0
logback-classic 1.5.13 EPL-1.0
LGPL-2.0-or-later
logback-classic 1.5.18 EPL-1.0
LGPL-2.0-or-later
logback-core 1.5.13 EPL-1.0
LGPL-2.0-or-later
logback-core 1.5.18 EPL-1.0
LGPL-2.0-or-later
micrometer-commons 1.15.1 Apache-2.0
micrometer-core 1.15.1 Apache-2.0
micrometer-jakarta9 1.15.1 Apache-2.0
micrometer-observation 1.15.1 Apache-2.0
netty-common 4.1.118.final Apache-2.0
reactive-streams 1.0.4 MIT-0
reactor-core 3.6.6 Apache-2.0
reactor-kotlin-extensions 1.2.3 Apache-2.0
reactor-netty-core 1.2.7 Apache-2.0
reactor-netty-http 1.2.7 Apache-2.0
slf4j-api 2.0.16 MIT
snakeyaml 2.4 Apache-2.0
spring-aop 6.2.8 Apache-2.0
spring-beans 6.2.8 Apache-2.0
spring-boot-actuator-autoconfigure 3.5.3 Apache-2.0
spring-boot-actuator 3.5.3 Apache-2.0
spring-boot-autoconfigure 3.5.3 Apache-2.0
spring-boot-configuration-processor 3.5.3 Apache-2.0
spring-boot-starter-actuator 3.5.3 Apache-2.0
spring-boot-starter-json 3.5.3 Apache-2.0
spring-boot-starter-logging 3.5.3 Apache-2.0
spring-boot-starter-reactor-netty 3.5.3 Apache-2.0
spring-boot-starter-security 3.5.3 Apache-2.0
spring-boot-starter-tomcat 3.5.3 Apache-2.0
spring-boot-starter-validation 3.5.3 Apache-2.0
spring-boot-starter-web 3.5.3 Apache-2.0
spring-boot-starter-webflux 3.5.3 Apache-2.0
spring-boot-starter 3.5.3 Apache-2.0
spring-boot 3.5.3 Apache-2.0
spring-context 6.2.8 Apache-2.0
spring-core 6.2.8 Apache-2.0
spring-expression 6.2.8 Apache-2.0
spring-security-config 6.5.1 Apache-2.0
spring-security-core 6.5.1 Apache-2.0
spring-security-web 6.5.1 Apache-2.0
spring-web 6.2.8 Apache-2.0
spring-webflux 6.2.8 Apache-2.0
spring-webmvc 6.2.8 Apache-2.0
stax2-api 4.2.1 BSD-2-Clause
BSD-3-Clause
tomcat-embed-core 10.1.42 Apache-2.0
CDDL-1.0
PROPRIETARY-LICENSE
tomcat-embed-el 10.1.42 Apache-2.0
tomcat-embed-websocket 10.1.42 Apache-2.0
woodstox-core 6.2.4 Apache-2.0
Contact Qodana team

Contact us at [email protected]

@Ololoshechkin Ololoshechkin requested a review from tiginamaria July 4, 2025 21:40
append("<${MemoryPrompts.historyWrapperTag}>\n")
oldPrompt.messages.forEach { message ->
when (message) {
is Message.System -> append("<user>\n${message.content}\n</user>\n")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ: Is the "system" message converted to a "user" message intentionally? Do we ever need to preserve a system message in the history snippett?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was done intentionally to reduce its influence to LLM behavior. But we decided to keep it as user, because it may contain important context and task details to consider.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kpavlov without this change, LLM was following the system message instructions instead of summarization

Copy link
Collaborator

@Ololoshechkin Ololoshechkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much @denis-domanskii for working on this and for finding this problem!

Copy link
Collaborator

@tiginamaria tiginamaria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks super reasonable! Thank you for improvement!

@denis-domanskii denis-domanskii merged commit a522bcb into develop Jul 7, 2025
5 checks passed
@denis-domanskii denis-domanskii deleted the JBAI-13880-improve-compression-history-2 branch July 7, 2025 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants