Skip to content

Conversation

@meganetaaan
Copy link
Contributor

This fixes #61.

There is an inconsistency between the Python and TypeScript implementations of the final output logic in the agent runner. The Python version correctly checks if tools are running before treating the output as final, while the TypeScript version does not.

Python

elif (
    not output_schema or output_schema.is_plain_text()
) and not processed_response.has_tools_or_approvals_to_run():
    # Only treat as final output if NO tools are running
    return await cls.execute_final_output(...)

TypeScript

if (agent.outputType === 'text') {
  // Missing check for hasToolsOrApprovalsToRun()
  return new SingleStepResult(/* next_step_final_output */);
}

The TypeScript version lacks the crucial hasToolsOrApprovalsToRun() check, causing any text output to be treated as final even when tools are present.

Fix Implemented

Added missing hasToolsOrApprovalsToRun() method to ProcessedResponse and updated final output logic:

if (agent.outputType === 'text' && !processedResponse.hasToolsOrApprovalsToRun()) {
  return new SingleStepResult(/* next_step_final_output */);
}

This aligns the TypeScript implementation with the Python version, allowing streams to continue after tool execution when appropriate.

@DroopyTersen
Copy link

I think this might be related to #57

@dkundel-openai
Copy link
Collaborator

Hey @meganetaaan thank you for your PR! Looking at this PR and @DroopyTersen PR (thank you for that), I think this aligns closer to the internal Python Agents SDK so I'd like to merge this. Could you please run pnpm changeset to add a patch change to this PR? Also any additional tests would be helpful. Thank you

meganetaaan and others added 2 commits June 10, 2025 08:00
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Jun 9, 2025

🦋 Changeset detected

Latest commit: b53cfd9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@openai/agents-core Patch
@openai/agents-openai Patch
@openai/agents-realtime Patch
@openai/agents Patch
@openai/agents-extensions Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@meganetaaan
Copy link
Contributor Author

Thanks for the feedback! I've addressed both requests:

  • Added pnpm changeset (patch change for @openai/agents-core)
  • Added comprehensive tests for the executeToolsAndSideEffects behavior and
    hasToolsOrApprovalsToRun method

The tests verify that text agents continue execution when tools are pending and return final output
when no tools are pending, which covers the core functionality of this fix.

@dkundel-openai dkundel-openai merged commit 544ed4b into openai:main Jun 10, 2025
5 checks passed
@seratch seratch added package:agents-core bug Something isn't working labels Jun 10, 2025
dkundel-openai pushed a commit that referenced this pull request Jun 10, 2025
* Continue agent execution when function calls are pending

* Add tests

* Add changeset for tool execution fix

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix mock object

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working package:agents-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stream terminates after tool execution with explanatory text

4 participants