Skip to content

Add tool_calls to the /chat turn summary - #45

Open
Kornél Felföldi (xenophobentx) wants to merge 4 commits into
microsoft:mainfrom
xenophobentx:chat-tool-calls
Open

Kornél Felföldi (xenophobentx) wants to merge 4 commits into
microsoft:mainfrom
xenophobentx:chat-tool-calls

Conversation

@xenophobentx

@xenophobentx Kornél Felföldi (xenophobentx) commented Sep 25, 2026 •

Copy link
Copy Markdown

Summary

The agenticruntime stream sends a toolCall entity when a tool starts and when it completes, with the parameters the model filled in, the result and the duration. The /chat summary only kept the activity text (Calling X..., X completed). This adds a tool_calls array to the default JSON output and lists the calls in --pretty.

Fixes #43.

Changes

  • scripts/src/response-format.js: collectToolCalls merges the entities into one record per toolCallId: { id, name, category, status, filledParameters, unfilledParameters, durationMs, result, error }.
    • A repeated started entity can't undo a later status or overwrite anything set after it.
    • An error is dropped when the call moves to a new status without one.
    • An empty filledParameters object doesn't overwrite real values.
    • Results over 2000 characters are cut, with resultTruncated and resultLength.
    • error/errorMessage is kept if the runtime sends one.
    • Entities without a toolCallId each get their own record, with an anon:<name>#<n> id.
  • scripts/src/chat-with-agent.js: tool_calls in the default JSON output.
  • scripts/src/terminal-render.js: --pretty lists each call with status, duration and inputs (inputs capped at 300 characters); nameless calls fall back to the id.
  • commands/chat.md: documents the field, including that a failed flow can still show up as completed with an empty result.
  • scripts/test/response-format.test.js: 21 tests for the merge logic.

The first commit only rebuilds chat-with-agent.bundle.js with esbuild 0.28.1 (pinned since #27; the committed bundle was built with 0.24.2), so the feature commit's bundle diff is just the new code. Both bundles are byte-identical to a fresh npm run build:chat-with-agent.

Testing

  • npm test in scripts/: 71 passing.
  • Ran the rebuilt bundle against a published CLI agent with a flow tool, in default and --pretty mode. tool_calls had the right name, status, filled parameters, duration and result.

No source change. The committed bundle was built with esbuild 0.24.2,
while package.json pins 0.28.1 since microsoft#27, so any rebuild produces this
diff. Keeping it separate makes the next change reviewable.
The agenticruntime stream sends a toolCall entity when a tool starts and
when it completes, with the parameters the model filled in, the result
and the duration. The summary only kept the activity text.

collectToolCalls merges those entities into one record per toolCallId,
keeping the runtime's field names. A repeated "started" entity can't undo
"completed", empty parameter objects don't overwrite real ones, results
over 2000 characters are truncated with their full length recorded, and
an error field is kept if the runtime sends one. The default JSON output
includes tool_calls and --pretty lists the calls with their inputs.

Fixes microsoft#43
Copilot AI lite review requested due to automatic review settings September 25, 2026 19:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Two moderate issues in tool-call identity handling and error preservation must be addressed.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds merged tool_calls details to /chat JSON and --pretty output.

Changes:

  • Aggregates tool-call entities with parameters, status, duration, results, and errors.
  • Adds truncation, documentation, tests, and rebuilt bundle.
  • Renders tool-call summaries in pretty mode.

Review findings:

  • Anonymous calls can collide with explicit runtime IDs.
  • A populated errorMessage can be lost when error is empty.
File Description
scripts/​test/​response-format.test.js Tests tool-call merging behavior.
scripts/​src/​terminal-render.js Renders tool-call summaries.
scripts/​src/​response-format.js Aggregates tool-call entities.
scripts/​src/​chat-with-agent.js Adds tool_calls to JSON output.
scripts/​chat-with-agent.bundle.js Rebuilt bundled CLI.
commands/​chat.md Documents the new output field.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread scripts/src/response-format.js Outdated
Comment thread scripts/src/response-format.js Outdated
Anonymous toolCall entities used a fallback id as the map key, which
could collide with a real toolCallId of the same shape. They now use
their own key space. An empty error field no longer hides a non-empty
errorMessage.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Clear stale resultTruncated and resultLength metadata when a later result is not truncated.

Review effort: Lite
Findings: None

Resolved since last review (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Clear stale truncation metadata when replacing with a short result

scripts/​src/​response-format.js:115

If the same call emits a long result and a later entity updates it with a result at or below 2000 characters, this branch replaces result but leaves the previous resultTruncated and resultLength fields. The summary then claims the current result is truncated and reports the old length; clear those fields when storing a non-truncated result.

…ities

- A later short result clears resultTruncated/resultLength.
- A repeated "started" entity after a later status no longer overwrites
  parameters, duration or anything else; it can only fill gaps.
- An error is dropped when the call moves to a new status without one.
- --pretty falls back to the id for nameless calls and skips empty meta.
- chat.md documents the anon: id and the {} result of a failed flow.
Copilot AI review requested due to automatic review settings September 25, 2026 20:30
@xenophobentx

Copy link
Copy Markdown
Author

Addressed the "previously missed" note from the last automated review in d43970d: a later short result now clears resultTruncated/resultLength. The same commit also stops a repeated started entity from overwriting parameters set by a later status, and drops an error when the call moves to a new status without one. Tests cover each case (71 passing).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Fix stale-error handling in tool-call merging and regenerate the committed bundle.

Review effort: Lite
Findings: None

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.

/chat summary omits toolCall parameters, results, and duration

2 participants