Skip to content

Conversation

@DroopyTersen
Copy link

@DroopyTersen DroopyTersen commented Jun 8, 2025

Description

Agent Loop Continuation: Prevents premature agent termination when models return both text output and tool calls

Problem

Some models (Claude Sonnet 4) return both text and tool calls in their responses. Previously, if there was any potential final output (text), the agent would terminate even if there were pending function results or computer results to process. This caused the agent to stop prematurely before completing all requested tool operations.

Solution

  • Modified the condition in executeToolsAndSideEffects to continue the agent loop when there are function results or computer results present, regardless of text output

Testing

  • Built project successfully with pnpm build (had to futz with some types to get build working after initial fork, not sure if it was a setup issue on my side)
  • All tests pass with CI=1 pnpm test
  • Linting passes with pnpm lint
  • Verified fix prevents premature agent termination when models return both text and tool calls

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

…ool calls

- Continue agent loop when function results or computer results are present
- Ensures agent continues processing when models return both text and tool calls
- Add comment explaining the logic for future maintainers
@changeset-bot
Copy link

changeset-bot bot commented Jun 8, 2025

🦋 Changeset detected

Latest commit: 5ff8027

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

…o fix/agents-core-prevent-premature-termination
- they fixed local build but broke CI build
@dkundel-openai
Copy link
Collaborator

Thank you for your contribution @DroopyTersen! Looking at this and #62 I'm going to be looking at merging that one to be closer to the Python implementation but we appreciate your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants