Skip to content

📬 feat: Report Tool Results Per Call via onResult Channel#13698

Merged
danny-avila merged 4 commits into
devfrom
feat/per-call-tool-result-emission
Jun 12, 2026
Merged

📬 feat: Report Tool Results Per Call via onResult Channel#13698
danny-avila merged 4 commits into
devfrom
feat/per-call-tool-result-emission

Conversation

@danny-avila

Copy link
Copy Markdown
Owner

Summary

I wired the tool-execution handler to report each result to the agent graph as it settles, instead of only delivering the full batch at the end. The handler already runs tool batches in parallel (Promise.all over the calls), but the ON_TOOL_EXECUTE contract previously exposed only the single resolve(results[]) channel — so a 1-second tool's completion event waited for the slowest call in the same batch. The agents SDK now accepts an optional per-call onResult callback (agents#239) and emits that call's completed run step immediately when invoked; this PR is the host half.

  • Pulled the optional onResult callback off the batch request with a forward-compatible cast, so this compiles against the currently installed SDK typings and activates automatically once the release containing agents#239 lands; until then onResult is undefined and the optional chain makes this a no-op.
  • Wrapped both mapper exit points (direct execution and the file-authoring queue path) in a reportResult helper, so every result shape — success, error, host-tool, queued — is reported exactly once as it settles; resolve(results) remains the authoritative batch outcome and is unchanged.
  • Guarded the callback invocation so a throwing listener can never break batch resolution.

The SDK side gates the fast-path on no-hooks/no-HITL configurations and dedupes against batch-time emission, so no changes are needed here for those cases — when the SDK withholds onResult, this code path is simply inert.

Change Type

  • New feature (non-breaking change which adds functionality)

Testing

  • Added three specs to packages/api/src/agents/handlers.spec.ts: a gated slow tool proves the fast call is reported before the batch resolves (and before the slow tool finishes); a throwing onResult listener doesn't prevent resolve; behavior without onResult is unchanged. Full handlers.spec.ts passes (78 tests).
  • tsc reports no errors in the touched files.

Test Configuration:

  • Node 24, jest via packages/api.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila danny-avila changed the base branch from main to dev June 11, 2026 23:43
@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: ❌ deploy failed

The deploy failed — the previous index (if any) continues to be served.
Deploy run

Tool batches already execute in parallel here, but results were only
delivered to the agent graph through the single resolve(results[])
call — so a fast tool's completion event waited on the slowest call
in the batch. Report each result through the optional onResult channel
(agents SDK > 3.2.33) as it settles, letting the graph emit that
call's completion immediately. resolve remains the authoritative batch
outcome; the callback is optional-chained, so this is a no-op until
the SDK release lands and remains backward compatible after.
@danny-avila danny-avila force-pushed the feat/per-call-tool-result-emission branch from 0a9241e to 3fa2dbd Compare June 12, 2026 00:32
@danny-avila danny-avila changed the title 📬 feat: Report Tool Results Per Call via onResult Channel 📬 feat: Report Tool Results Per Call via onResult Channel Jun 12, 2026
@danny-avila danny-avila merged commit a8a6360 into dev Jun 12, 2026
19 checks passed
@danny-avila danny-avila deleted the feat/per-call-tool-result-emission branch June 12, 2026 00:38
fuuuzzy pushed a commit to fuuuzzy/LibreChat that referenced this pull request Jun 18, 2026
…ila#13698)

* 📬 feat: Report Tool Results Per Call via onResult Channel

Tool batches already execute in parallel here, but results were only
delivered to the agent graph through the single resolve(results[])
call — so a fast tool's completion event waited on the slowest call
in the batch. Report each result through the optional onResult channel
(agents SDK > 3.2.33) as it settles, letting the graph emit that
call's completion immediately. resolve remains the authoritative batch
outcome; the callback is optional-chained, so this is a no-op until
the SDK release lands and remains backward compatible after.

* 🧹 chore: Prettier Formatting in onResult Spec

* 🧹 chore: Sort Imports in handlers.ts

* 🔧 chore: Update @librechat/agents dependency to version 3.2.34 in package-lock.json and related package.json files
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.

1 participant