Skip to content

Conversation

@WorldOfBasti
Copy link

@WorldOfBasti WorldOfBasti commented Jan 7, 2026

Description

This PR adds robust error handling for tool argument parsing, result serialization, and subgraph tool execution failures. Instead of crashing, the agent should now handle these errors and return failure results.
Issue also described in KG-597 / #1169

Changes

Tool Argument Parsing errors

  • Added error handling when parsing tool call JSON arguments fails
  • Tool calls with invalid JSON now call the onToolValidationFailed callback and return a ToolResultKind.ValidationError with an error message instead of crashing

Tool result serialization errors

  • Catch exceptions when calling decodeResult()
  • Parsing failures now return Result.Failure with an error message

Subgraph finish tool hanlding

  • Ensures parsing/execution failures route back to the LLM for correction

Type of the changes

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tests improvement
  • Refactoring

Checklist

  • 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

@WorldOfBasti WorldOfBasti force-pushed the bastian.aunkofer/fix-serialization-errors branch 2 times, most recently from 6d96ea0 to fd79c50 Compare January 12, 2026 15:15
@WorldOfBasti WorldOfBasti marked this pull request as draft January 12, 2026 20:12
@WorldOfBasti WorldOfBasti force-pushed the bastian.aunkofer/fix-serialization-errors branch from fd79c50 to 9f5bada Compare January 13, 2026 14:10
@WorldOfBasti WorldOfBasti marked this pull request as ready for review January 13, 2026 14:40
Copy link
Collaborator

@EugeneTheDev EugeneTheDev 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, generally looks good, a few comments

Copy link
Collaborator

@EugeneTheDev EugeneTheDev left a comment

Choose a reason for hiding this comment

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

I've also noticed a number of wrong imports, can you please fix these? Other than that looks good

import ai.koog.agents.core.tools.Tool
import ai.koog.prompt.message.ContentPart
import ai.koog.prompt.message.Message
import io.ktor.utils.io.CancellationException
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: wrong CancellationException

Copy link
Author

Choose a reason for hiding this comment

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

Good catch, I missed those. Fixed them in the latest commit!

import ai.koog.agents.core.feature.model.toAgentError
import ai.koog.prompt.message.Message
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.utils.io.CancellationException
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: wrong CancellationException

import ai.koog.prompt.message.Message
import ai.koog.prompt.params.LLMParams
import ai.koog.prompt.processor.ResponseProcessor
import io.ktor.utils.io.CancellationException
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: wrong CancellationException

import ai.koog.agents.snapshot.providers.PersistenceStorageProvider
import ai.koog.prompt.message.Message
import io.github.oshai.kotlinlogging.KotlinLogging
import io.ktor.utils.io.CancellationException
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: wrong CancellationException

import io.ktor.server.engine.EmbeddedServer
import io.ktor.server.engine.EngineConnectorConfig
import io.ktor.server.engine.embeddedServer
import io.ktor.utils.io.CancellationException
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: wrong CancellationException

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.

Unhandled exceptions on LLM‑initiated invalid tool/node calls terminate agent run

2 participants