Skip to content

fit(agent): double time parsing#532

Merged
samchon merged 1 commit intomainfrom
fix/parse-onece-more
Mar 4, 2026
Merged

fit(agent): double time parsing#532
samchon merged 1 commit intomainfrom
fix/parse-onece-more

Conversation

@samchon
Copy link
Member

@samchon samchon commented Mar 4, 2026

This pull request introduces an improvement to the parse function in JsonUtil.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:

  • Enhanced the parse function in JsonUtil.ts to automatically re-parse values when the initial result is a string and parameters are provided, supporting nested or stringified JSON scenarios.

@samchon samchon self-assigned this Mar 4, 2026
@samchon samchon added the bug Something isn't working label Mar 4, 2026
Copilot AI review requested due to automatic review settings March 4, 2026 15:44
@samchon samchon added the enhancement New feature or request label Mar 4, 2026
@samchon samchon added this to WrtnLabs Mar 4, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 4, 2026

Open in StackBlitz

@agentica/benchmark

npm i https://pkg.pr.new/@agentica/benchmark@532

@agentica/chat

npm i https://pkg.pr.new/@agentica/chat@532

agentica

npm i https://pkg.pr.new/agentica@532

@agentica/core

npm i https://pkg.pr.new/@agentica/core@532

create-agentica

npm i https://pkg.pr.new/create-agentica@532

@agentica/rpc

npm i https://pkg.pr.new/@agentica/rpc@532

@agentica/vector-selector

npm i https://pkg.pr.new/@agentica/vector-selector@532

commit: 3414ca3

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.parse result handling to conditionally attempt a second parse when the parsed value is a string and parameters is 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.

Comment on lines +21 to +30
const output: any = (() => {
const value = JSON.parse(str);
if (typeof value === "string" && parameters !== undefined) {
try {
return parse(value);
}
catch {}
}
return value;
})();
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +27
const output: any = (() => {
const value = JSON.parse(str);
if (typeof value === "string" && parameters !== undefined) {
try {
return parse(value);
}
catch {}
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@samchon samchon merged commit 0b302d5 into main Mar 4, 2026
17 checks passed
@samchon samchon deleted the fix/parse-onece-more branch March 4, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants