Skip to content
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

Bug: TypeError: (0 , MGt.setCredentialFeature) is not a function #70

Closed
Arun4you opened this issue Oct 20, 2024 · 1 comment
Closed
Labels
bug Something isn't working triage

Comments

@Arun4you
Copy link

Arun4you commented Oct 20, 2024

Expected Behaviour

https://awslabs.github.io/multi-agent-orchestrator/agents/built-in/lambda-agent/

Following instruction from this link should work.

Current Behaviour

import { MultiAgentOrchestrator } from "multi-agent-orchestrator";
const orchestrator = new MultiAgentOrchestrator();
orchestrator.addAgent(agent);
const response = await orchestrator.routeRequest(
"I need help with my order",
"user123",
"session456"
);

processing request: TypeError: (0 , MGt.setCredentialFeature) is not a function
at /var/task/index.js:12:34655
at e (/var/task/index.js:35:243)
at /var/task/index.js:1:38819
at coalesceProvider (/var/task/index.js:1:38997)
at /var/task/index.js:1:39199
at /var/task/node_modules/@smithy/core/dist-cjs/index.js:82:23
at async /var/task/index.js:1:7657
at async Oee.processRequest (/var/task/index.js:158:4342)
at async Oee.classify (/var/task/index.js:157:76)
at async o1e.routeRequest (/var/task/index.js:249:5168)

Code snippet

import {
  MultiAgentOrchestrator,
  LambdaAgent,
} from "multi-agent-orchestrator";
this.multiAgentOrchestrator = new MultiAgentOrchestrator();
   const lambdaAgents = [ {
        name: "system-generator",
        description: `
        An AI System Generator Agent to analyze business requirements and generate high-level system blueprints, breaking down complex processes into interconnected workflows.
        `,
        functionName: "system-generator",
        functionRegion: "ap-south-1",
      },
      {
        name: "workflow-generator",
        description: `
        An AI workflow Generator Agent to generate comprehensive, well-structured workflows based on given business cases or requirements.
       
        functionName: "ai-workflow-generator",
        functionRegion: "ap-south-1",
      },
    ];

    lambdaAgents.forEach((agentConfig) => {
      const agent = new LambdaAgent(agentConfig);
      this.multiAgentOrchestrator.addAgent(agent);
    });

  async processRequest(request: OrchestratorRequest): Promise<any> {
    const { input, userId, sessionId } = request;
    console.log('processRequest input, userId, sessionId:', input, userId, sessionId);

    try {
      const agentResponse = await this.multiAgentOrchestrator.routeRequest(
        "HR team manage their organization’s recruitment process",
        "user123",
        "session456"
      );
      console.log("agentResponse in AI Orchestrator:", agentResponse);

      return {
        result: "Request processed successfully",
        agentResponse,
      };
    } catch (error) {
      console.error("Error in AI Orchestrator:", error);
      throw error;
    }
  }

CDK code:
const aiOrchestrator = (
  scope: Construct,
  context: CDKContext,
  layers: lambda.ILayerVersion[]
) => {
  const handlerName = context.lambda.aiOrchestrator.name;
  const entryPath = join(
    __dirname,
    `/../../src/lambda/${handlerName}/src/index.js`
  );
  return createNodeJsFunction(
    scope,
    handlerName,
    context,
    entryPath,
    {
      layers: [...layers],
      memorySize: 512,
      environment: {
        ACCOUNT_NUMBER: context.accountNumber,
        REGION: context.region,
      },
      timeout: Duration.minutes(3),
    },
    {
      externalModulesArray: [
        // "@aws-lambda-powertools/logger",
        // "@aws-lambda-powertools/parameters",
      ],
      nodeModulesArray: [
        "@aws-sdk/client-cognito-identity-provider",
        "@aws-sdk/client-sso",
        "@aws-sdk/client-sts",
        "@smithy/core",
        "@aws-sdk/core",
      ],
    }
  );
};

export const createNodeJsFunction = (
  scope: Construct,
  handlerName: string,
  context: CDKContext,
  entry: string,
  props: NodejsFunctionProps | undefined,
  dependencies: Dependencies
): NodejsFunction => {
  console.log(
    "lambda path: ",
    __dirname,
    join(__dirname, `/../../src/lambda/${handlerName}/index.ts`)
  );
  return new NodejsFunction(scope, handlerName, {
    entry: join(entry),
    handler: "handler",
    // functionName: `${handlerName}-${context.appName}-${context.environment}`,
    functionName: `${handlerName}-${context.appName}`,
    runtime: Runtime.NODEJS_16_X,
    timeout: Duration.minutes(3),
    bundling: {
      externalModules: [...dependencies.externalModulesArray],
      nodeModules: [...dependencies.nodeModulesArray], // Bundle AWS SDK v3 modules
      minify: true, // Optional: Minimizes code
      // target: "node18", // Set target as Node.js 18
      // externalModules: [...externalModulesArray]
    },
    ...props,
  });
};

Bedrock Permission:
  const bedrockPolicy = new iam.PolicyStatement({
    actions: ["bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream"], // Allow invocation of Bedrock models
    //arn:aws:bedrock:ap-south-1::foundation-model/anthropic.claude-3-haiku-20240307-v1:0
    resources: [`arn:aws:bedrock:${context.region}::foundation-model/*`], // Adjust the region, account ID, and model as needed
    // resources: [`arn:aws:bedrock:${context.region}:${context.accountNumber}:model/*`], // Adjust the region, account ID, and model as needed
  });


Package.json:
{
  "name": "ai-orchestration-making",
  "version": "1.0.0",
  "description": "AI orchestration Lambda",
  "main": "index.js",
  "scripts": {
    "test": "jest"
  },
  "dependencies": {
    "@aws-sdk/client-cognito-identity-provider": "^3.675.0",
    "@aws-sdk/client-sso": "^3.675.0",
    "@aws-sdk/client-sts": "^3.675.0",
    "@aws-sdk/core": "^3.666.0",
    "@smithy/core": "^2.4.8",
    "aws-lambda": "^1.0.7",
    "multi-agent-orchestrator": "0.0.17"
  },
  "devDependencies": {
    "@types/aws-lambda": "8.10.145",
    "@types/jest": "^29.5.12",
    "jest": "^29.7.0",
    "ts-jest": "^29.1.2"
  }
}

Possible Solution

No response

Steps to Reproduce

try to run the code in a lambda runtime.
Tried in both node16 and 18. Both have same issues.

@Arun4you Arun4you added the bug Something isn't working label Oct 20, 2024
@Arun4you
Copy link
Author

"@aws-sdk/core": "3.666.0",
"@aws-sdk/client-ssm": "3.675.0",
"esbuild": "^0.24.0"

Adding these libraries to CDK package.json fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

1 participant