Currently, tool input decoding and output encoding is using the global Json serialization configuration.
This configuration, by default, uses ignoreUnknownKeys = true in Json serialization, which is useful when the provider, like OpenAI, returns unknown keys that are not supported yet. However, on tools, it provokes swallowing decoding errors of non-strict tool inputs, and can lead to unexpected results. When not swallowing this error, the assistant can recover from this kind of problems by trying again.
Also, by default it uses explicitNulls = false, so the assistant sometimes interprets that the absence of the key means that there is not value. This leads to the assistant not calling a Tool, which not happens so often when we pass a pattern of { key: null }, so the assistant interprets that it has to call a Tool to recover that information.
This PR
In any case, this PR makes the tool decoding and encoding to use a separate Json serialization configuration object, which can be specified per tool, and is by default Json.Default. Allowing to override the Json configuration per tool based on the consumer needs.
In future, we could improve the input encoding by adding the strict: true parameter per tool, as supported in OpenAI.
Background
Currently, tool input decoding and output encoding is using the global Json serialization configuration.
This configuration, by default, uses
ignoreUnknownKeys = true
in Json serialization, which is useful when the provider, like OpenAI, returns unknown keys that are not supported yet. However, on tools, it provokes swallowing decoding errors of non-strict tool inputs, and can lead to unexpected results. When not swallowing this error, the assistant can recover from this kind of problems by trying again.Also, by default it uses
explicitNulls = false
, so the assistant sometimes interprets that the absence of the key means that there is not value. This leads to the assistant not calling a Tool, which not happens so often when we pass a pattern of{ key: null }
, so the assistant interprets that it has to call a Tool to recover that information.This PR
In any case, this PR makes the tool decoding and encoding to use a separate Json serialization configuration object, which can be specified per tool, and is by default
Json.Default
. Allowing to override the Json configuration per tool based on the consumer needs.In future, we could improve the input encoding by adding the
strict: true
parameter per tool, as supported in OpenAI.