Conversation
@agentica/benchmark
@agentica/chat
agentica
@agentica/core
create-agentica
@agentica/rpc
@agentica/vector-selector
commit: |
There was a problem hiding this comment.
Pull request overview
This PR improves JsonUtil.parse to better handle tool-call argument payloads that arrive as JSON-encoded strings (i.e., where the first JSON.parse returns a string containing further JSON), enabling a second parse attempt when parameters are provided.
Changes:
- Wrap initial
JSON.parseresult handling to conditionally attempt a second parse when the parsed value is a string andparametersis provided. - Preserve existing schema-driven post-processing via
decompose(parameters, output)after parsing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const output: any = (() => { | ||
| const value = JSON.parse(str); | ||
| if (typeof value === "string" && parameters !== undefined) { | ||
| try { | ||
| return parse(value); | ||
| } | ||
| catch {} | ||
| } | ||
| return value; | ||
| })(); |
There was a problem hiding this comment.
The new “re-parse if output is a string” logic is implemented via a recursive parse(value) call with parameters intentionally dropped, which makes the behavior (max 1 extra parse) non-obvious and harder to maintain. Consider replacing this with an explicit second-pass parse (or a small loop with a max depth constant) and document the intended depth/conditions so future changes don’t accidentally change the parse depth semantics.
| const output: any = (() => { | ||
| const value = JSON.parse(str); | ||
| if (typeof value === "string" && parameters !== undefined) { | ||
| try { | ||
| return parse(value); | ||
| } | ||
| catch {} |
There was a problem hiding this comment.
This change alters JsonUtil.parse behavior for tool-call argument parsing (it may now successfully parse double-encoded JSON when parameters is provided), but there are no unit tests covering JsonUtil.parse. Please add a Vitest spec that covers at least: (1) plain JSON object, (2) stringified JSON object (e.g., ""{\"a\":1}""), and (3) a JSON string that is not JSON (should remain a string) to lock in the intended behavior.
This pull request introduces an improvement to the
parsefunction inJsonUtil.ts, enhancing its ability to handle cases where the parsed JSON is a string containing further JSON. This helps ensure that nested or stringified JSON values are correctly parsed.Improvements to JSON parsing robustness:
parsefunction inJsonUtil.tsto automatically re-parse values when the initial result is a string and parameters are provided, supporting nested or stringified JSON scenarios.