#Nest can't resolve dependencies of the TavilyService (?)

5 messages · Page 1 of 1 (latest)

tawdry raven
#

I am having this error:

Nest can't resolve dependencies of the TavilyService (?). Please make sure that the argument Object at index [0] is available in the TavilyModule context.

However the TavilyService is well set as providers in the module:

import { Module } from '@nestjs/common';
import { TavilyService } from './tavily.service';

@Module({
  providers: [TavilyService],
  exports: [TavilyService],
})
export class TavilyModule {}

And the TavilyService well exported:

@Injectable()
export class TavilyService {

Does anyone have an idea in order to solve the issue ?

glacial plinth
lavish pawn
tawdry raven
#
@Injectable()
export class TavilyService {
  agentTools = [new TavilySearchResults({ maxResults: 3 })];
  agentModel = new ChatOpenAI({
    temperature: 0,
  });
  agentCheckopinter = new MemorySaver();

  constructor(
    private agent = createReactAgent({
      llm: this.agentModel,
      tools: this.agentTools,
      checkpointSaver: this.agentCheckopinter,
    }),
  ) {}

@glacial plinth

glacial plinth
# tawdry raven ```typescript @Injectable() export class TavilyService { agentTools = [new Tav...

In this case, I think it'd be fine to move that agent variable assignment into the onModuleInit lifecycle method

Or, just move it into the body of the constructor method.

+import { Injectable, OnModuleInit } from '@nestjs/common';

@Injectable()
-export class TavilyService {
+export class TavilyService implements OnModuleInit {
  agentTools = [new TavilySearchResults({ maxResults: 3 })];
  agentModel = new ChatOpenAI({
    temperature: 0,
  });
  agentCheckopinter = new MemorySaver();
+ agent: any; // TODO: improve the type

- constructor(
+ onModuleInit() {
    private agent = createReactAgent({
      llm: this.agentModel,
      tools: this.agentTools,
      checkpointSaver: this.agentCheckopinter,
    })
- ) {}
+ }