Skip to content

fix(agents-core): prevent premature agent termination with text and function calls #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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
Copy link

changeset-bot bot commented Jun 8, 2025

🦋 Changeset detected

Latest commit: 2c248b9

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

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