Expose and add default Json serialization to ToolConfig #778
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.