Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/agents-core/src/runImplementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,11 @@ export async function executeToolsAndSideEffects<TContext>(
);
}

if (!processedResponse.hasToolsOrApprovalsToRun()) {
const hasPendingToolsOrApprovals = functionResults.some(
(result) => result.type !== 'function_output',
);

if (!hasPendingToolsOrApprovals) {
if (agent.outputType === 'text') {
return new SingleStepResult(
originalInput,
Expand Down
14 changes: 10 additions & 4 deletions packages/agents-core/test/runImplementation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ describe('executeToolsAndSideEffects', () => {
state = new RunState(new RunContext(), 'test input', TEST_AGENT, 1);
});

it('continues execution when text agent has tools pending', async () => {
it('returns final output for text agent once tools finish in the same turn', async () => {
const textAgent = new Agent({ name: 'TextAgent', outputType: 'text' });
const processedResponse = processModelResponse(
TEST_MODEL_RESPONSE_WITH_FUNCTION,
Expand All @@ -901,10 +901,13 @@ describe('executeToolsAndSideEffects', () => {
),
);

expect(result.nextStep.type).toBe('next_step_run_again');
expect(result.nextStep.type).toBe('next_step_final_output');
if (result.nextStep.type === 'next_step_final_output') {
expect(result.nextStep.output).toBe('Hello World');
}
});

it('continues execution when structured agent has tools pending', async () => {
it('returns final output for structured agent once tools finish in the same turn', async () => {
const structuredAgent = new Agent({
name: 'StructuredAgent',
outputType: z.object({
Expand Down Expand Up @@ -948,7 +951,10 @@ describe('executeToolsAndSideEffects', () => {
),
);

expect(result.nextStep.type).toBe('next_step_run_again');
expect(result.nextStep.type).toBe('next_step_final_output');
if (result.nextStep.type === 'next_step_final_output') {
expect(result.nextStep.output).toBe('{"foo":"bar"}');
}
});

it('returns final output when text agent has no tools pending', async () => {
Expand Down