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
1 change: 1 addition & 0 deletions apps/api/src/app/agents/agents.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export class AgentsController {
identifier,
name: body.name,
description: body.description,
behavior: body.behavior,
})
);
}
Expand Down
9 changes: 9 additions & 0 deletions apps/api/src/app/agents/dtos/agent-behavior.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsBoolean, IsOptional } from 'class-validator';

export class AgentBehaviorDto {
@ApiPropertyOptional({ description: 'Show a "Thinking..." indicator while the agent is processing a message' })
@IsBoolean()
@IsOptional()
thinkingIndicatorEnabled?: boolean;
}
4 changes: 4 additions & 0 deletions apps/api/src/app/agents/dtos/agent-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

import { AgentBehaviorDto } from './agent-behavior.dto';
import { AgentIntegrationSummaryDto } from './agent-integration-summary.dto';

export class AgentResponseDto {
Expand All @@ -15,6 +16,9 @@ export class AgentResponseDto {
@ApiPropertyOptional()
description?: string;

@ApiPropertyOptional({ type: AgentBehaviorDto })
behavior?: AgentBehaviorDto;

@ApiProperty()
_environmentId: string;

Expand Down
1 change: 1 addition & 0 deletions apps/api/src/app/agents/dtos/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './add-agent-integration-request.dto';
export * from './agent-behavior.dto';
export * from './agent-integration-summary.dto';
export * from './agent-integration-response.dto';
export * from './agent-response.dto';
Expand Down
11 changes: 10 additions & 1 deletion apps/api/src/app/agents/dtos/update-agent-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsString } from 'class-validator';
import { IsOptional, IsString, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';

import { AgentBehaviorDto } from './agent-behavior.dto';

export class UpdateAgentRequestDto {
@ApiPropertyOptional()
Expand All @@ -11,4 +14,10 @@ export class UpdateAgentRequestDto {
@IsString()
@IsOptional()
description?: string;

@ApiPropertyOptional({ type: AgentBehaviorDto })
@ValidateNested()
@Type(() => AgentBehaviorDto)
@IsOptional()
behavior?: AgentBehaviorDto;
}
33 changes: 33 additions & 0 deletions apps/api/src/app/agents/e2e/agents.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,39 @@ describe('Agents API - /agents #novu-v2', () => {
expect(afterDelete.status).to.equal(404);
});

it('should update and return agent behavior settings', async () => {
const identifier = `e2e-behavior-${Date.now()}`;

const createRes = await session.testAgent.post('/v1/agents').send({
name: 'Behavior Agent',
identifier,
});

expect(createRes.status).to.equal(201);
expect(createRes.body.data.behavior).to.equal(undefined);

const patchRes = await session.testAgent.patch(`/v1/agents/${encodeURIComponent(identifier)}`).send({
behavior: { thinkingIndicatorEnabled: false },
});

expect(patchRes.status).to.equal(200);
expect(patchRes.body.data.behavior).to.deep.equal({ thinkingIndicatorEnabled: false });

const getRes = await session.testAgent.get(`/v1/agents/${encodeURIComponent(identifier)}`);

expect(getRes.status).to.equal(200);
expect(getRes.body.data.behavior.thinkingIndicatorEnabled).to.equal(false);

const reEnableRes = await session.testAgent.patch(`/v1/agents/${encodeURIComponent(identifier)}`).send({
behavior: { thinkingIndicatorEnabled: true },
});

expect(reEnableRes.status).to.equal(200);
expect(reEnableRes.body.data.behavior.thinkingIndicatorEnabled).to.equal(true);
Comment on lines +79 to +96
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Use typingIndicatorEnabled instead of thinkingIndicatorEnabled in this E2E flow.

The test currently validates a different field name than the feature contract in the PR objective, which can mask a real API mismatch.

✅ Suggested fix
-    const patchRes = await session.testAgent.patch(`/v1/agents/${encodeURIComponent(identifier)}`).send({
-      behavior: { thinkingIndicatorEnabled: false },
-    });
+    const patchRes = await session.testAgent.patch(`/v1/agents/${encodeURIComponent(identifier)}`).send({
+      behavior: { typingIndicatorEnabled: false },
+    });

     expect(patchRes.status).to.equal(200);
-    expect(patchRes.body.data.behavior).to.deep.equal({ thinkingIndicatorEnabled: false });
+    expect(patchRes.body.data.behavior).to.deep.equal({ typingIndicatorEnabled: false });

     const getRes = await session.testAgent.get(`/v1/agents/${encodeURIComponent(identifier)}`);

     expect(getRes.status).to.equal(200);
-    expect(getRes.body.data.behavior.thinkingIndicatorEnabled).to.equal(false);
+    expect(getRes.body.data.behavior.typingIndicatorEnabled).to.equal(false);

     const reEnableRes = await session.testAgent.patch(`/v1/agents/${encodeURIComponent(identifier)}`).send({
-      behavior: { thinkingIndicatorEnabled: true },
+      behavior: { typingIndicatorEnabled: true },
     });

     expect(reEnableRes.status).to.equal(200);
-    expect(reEnableRes.body.data.behavior.thinkingIndicatorEnabled).to.equal(true);
+    expect(reEnableRes.body.data.behavior.typingIndicatorEnabled).to.equal(true);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const patchRes = await session.testAgent.patch(`/v1/agents/${encodeURIComponent(identifier)}`).send({
behavior: { thinkingIndicatorEnabled: false },
});
expect(patchRes.status).to.equal(200);
expect(patchRes.body.data.behavior).to.deep.equal({ thinkingIndicatorEnabled: false });
const getRes = await session.testAgent.get(`/v1/agents/${encodeURIComponent(identifier)}`);
expect(getRes.status).to.equal(200);
expect(getRes.body.data.behavior.thinkingIndicatorEnabled).to.equal(false);
const reEnableRes = await session.testAgent.patch(`/v1/agents/${encodeURIComponent(identifier)}`).send({
behavior: { thinkingIndicatorEnabled: true },
});
expect(reEnableRes.status).to.equal(200);
expect(reEnableRes.body.data.behavior.thinkingIndicatorEnabled).to.equal(true);
const patchRes = await session.testAgent.patch(`/v1/agents/${encodeURIComponent(identifier)}`).send({
behavior: { typingIndicatorEnabled: false },
});
expect(patchRes.status).to.equal(200);
expect(patchRes.body.data.behavior).to.deep.equal({ typingIndicatorEnabled: false });
const getRes = await session.testAgent.get(`/v1/agents/${encodeURIComponent(identifier)}`);
expect(getRes.status).to.equal(200);
expect(getRes.body.data.behavior.typingIndicatorEnabled).to.equal(false);
const reEnableRes = await session.testAgent.patch(`/v1/agents/${encodeURIComponent(identifier)}`).send({
behavior: { typingIndicatorEnabled: true },
});
expect(reEnableRes.status).to.equal(200);
expect(reEnableRes.body.data.behavior.typingIndicatorEnabled).to.equal(true);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/api/src/app/agents/e2e/agents.e2e.ts` around lines 79 - 96, The E2E test
uses the wrong field name: replace all occurrences of thinkingIndicatorEnabled
with typingIndicatorEnabled in the requests and assertions for the agent update
flow (update calls made via
session.testAgent.patch(`/v1/agents/${encodeURIComponent(identifier)}`), the
subsequent GET via
session.testAgent.get(`/v1/agents/${encodeURIComponent(identifier)}`), and the
response checks on patchRes.body.data.behavior, getRes.body.data.behavior, and
reEnableRes.body.data.behavior) so the PATCH payloads and expect(...) checks
validate typingIndicatorEnabled instead of thinkingIndicatorEnabled.


await session.testAgent.delete(`/v1/agents/${encodeURIComponent(identifier)}`);
});

it('should return 422 when identifier is not a valid slug', async () => {
const res = await session.testAgent.post('/v1/agents').send({
name: 'Invalid Slug Agent',
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/app/agents/mappers/agent-response.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function toAgentResponse(agent: AgentEntity): AgentResponseDto {
name: agent.name,
identifier: agent.identifier,
description: agent.description,
behavior: agent.behavior,
_environmentId: agent._environmentId,
_organizationId: agent._organizationId,
createdAt: agent.createdAt,
Expand Down
6 changes: 6 additions & 0 deletions apps/api/src/app/agents/services/agent-credential.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export interface ResolvedPlatformConfig {
agentIdentifier: string;
integrationIdentifier: string;
integrationId: string;
thinkingIndicatorEnabled: boolean;
}

function resolveThinkingIndicator(agent: { behavior?: { thinkingIndicatorEnabled?: boolean } }): boolean {
return agent.behavior?.thinkingIndicatorEnabled !== false;
}

@Injectable()
Expand Down Expand Up @@ -100,6 +105,7 @@ export class AgentCredentialService {
agentIdentifier: agent.identifier,
integrationIdentifier,
integrationId: integration._id,
thinkingIndicatorEnabled: resolveThinkingIndicator(agent),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export class AgentInboundHandler {
organizationId: config.organizationId,
});

await thread.startTyping();
if (config.thinkingIndicatorEnabled) {
await thread.startTyping('Thinking...');
}

const serializedThread = thread.toJSON() as unknown as Record<string, unknown>;
await this.conversationService.updateChannelThread(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { IsNotEmpty, IsOptional, IsString, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';

import { EnvironmentWithUserCommand } from '../../../shared/commands/project.command';
import { AgentBehaviorDto } from '../../dtos/agent-behavior.dto';

export class UpdateAgentCommand extends EnvironmentWithUserCommand {
@IsString()
Expand All @@ -14,4 +16,9 @@ export class UpdateAgentCommand extends EnvironmentWithUserCommand {
@IsString()
@IsOptional()
description?: string;

@ValidateNested()
@Type(() => AgentBehaviorDto)
@IsOptional()
behavior?: AgentBehaviorDto;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export class UpdateAgent {
constructor(private readonly agentRepository: AgentRepository) {}

async execute(command: UpdateAgentCommand): Promise<AgentResponseDto> {
if (command.name === undefined && command.description === undefined) {
throw new BadRequestException('At least one of name or description must be provided.');
if (command.name === undefined && command.description === undefined && command.behavior === undefined) {
throw new BadRequestException('At least one of name, description, or behavior must be provided.');
}

const existing = await this.agentRepository.findOne(
Expand All @@ -27,7 +27,7 @@ export class UpdateAgent {
throw new NotFoundException(`Agent with identifier "${command.identifier}" was not found.`);
}

const $set: Record<string, string> = {};
const $set: Record<string, unknown> = {};

if (command.name !== undefined) {
$set.name = command.name;
Expand All @@ -37,6 +37,12 @@ export class UpdateAgent {
$set.description = command.description;
}

if (command.behavior !== undefined) {
if (command.behavior.thinkingIndicatorEnabled !== undefined) {
$set['behavior.thinkingIndicatorEnabled'] = command.behavior.thinkingIndicatorEnabled;
}
}

await this.agentRepository.updateOne(
{
_id: existing._id,
Expand Down
6 changes: 6 additions & 0 deletions libs/dal/src/repositories/agent/agent.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import type { ChangePropsValueType } from '../../types/helpers';
import type { EnvironmentId } from '../environment';
import type { OrganizationId } from '../organization';

export interface AgentBehavior {
thinkingIndicatorEnabled?: boolean;
}

export class AgentEntity {
_id: string;

Expand All @@ -11,6 +15,8 @@ export class AgentEntity {

description?: string;

behavior?: AgentBehavior;

_environmentId: EnvironmentId;

_organizationId: OrganizationId;
Expand Down
3 changes: 3 additions & 0 deletions libs/dal/src/repositories/agent/agent.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const agentSchema = new Schema<AgentDBModel>(
required: true,
},
description: Schema.Types.String,
behavior: {
thinkingIndicatorEnabled: Schema.Types.Boolean,
},
_organizationId: {
type: Schema.Types.ObjectId,
ref: 'Organization',
Expand Down
Loading