diff --git a/core/src/agents/llm_agent.ts b/core/src/agents/llm_agent.ts index f5e29d4..8b14689 100644 --- a/core/src/agents/llm_agent.ts +++ b/core/src/agents/llm_agent.ts @@ -1498,13 +1498,17 @@ export class LlmAgent extends BaseAgent { ): AsyncGenerator { while (true) { let lastEvent: Event|undefined = undefined; + let hasFunctionResponse = false; for await (const event of this.runOneStepAsync(context)) { lastEvent = event; + if (getFunctionResponses(event).length > 0) { + hasFunctionResponse = true; + } this.maybeSaveOutputToState(event); yield event; } - if (!lastEvent || isFinalResponse(lastEvent)) { + if (!lastEvent || (isFinalResponse(lastEvent) && !hasFunctionResponse)) { break; } if (lastEvent.partial) { diff --git a/core/src/utils/model_name.ts b/core/src/utils/model_name.ts index 43e9acb..9ae7ecf 100644 --- a/core/src/utils/model_name.ts +++ b/core/src/utils/model_name.ts @@ -5,7 +5,7 @@ */ const MODEL_NAME_PATTERN = - '^projects/[^/]+/locations/[^/]+/publishers/[^/]+/models/(.+)$'; + '^projects/[^/]+/locations/[^/]+/publishers/[^/]+/models/(.+)$'; /** * Extract the actual model name from either simple or path-based format.