Skip to content

feat(agent): add support for agent collab, orch and FM in prompt #1011

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

Merged
merged 11 commits into from
Mar 17, 2025

Conversation

krokoko
Copy link
Collaborator

@krokoko krokoko commented Mar 4, 2025

Fixes #998 and #999 and #1011

  • Add support for multi agent collaboration
  • Add support for custom orchestration
  • Add support for foundation model in prompt override configuration
  • Update documentation for guradrails

See comments in the PR below to get output of tests


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

@krokoko
Copy link
Collaborator Author

krokoko commented Mar 4, 2025

The following code snippet:

const customerSupportAgent = new bedrock.Agent(this, 'CustomerSupportAgent', {
      foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
      instruction: 'You specialize in answering customer support questions about our products.',
      userInputEnabled: true,
      shouldPrepareAgent:true
    });

    const customerSupportAlias = new bedrock.AgentAlias(this, 'CustomerSupportAlias', {
      agent: customerSupportAgent,
      aliasName: 'production',
    });

    const mainAgent = new bedrock.Agent(this, 'MainAgent', {
      name: 'MainAgent',
      instruction: 'You are a helpful assistant that can answer general questions and route specialized customer support questions to the customer support agent.',
      foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
      agentCollaboration: bedrock.AgentCollaboratorType.SUPERVISOR,
      agentCollaborators: [
        new bedrock.AgentCollaborator({
          agentDescriptor: { aliasArn: customerSupportAlias.aliasArn },
          collaborationInstruction: 'Route customer support questions to this agent.',
          collaboratorName: 'CustomerSupport',
          relayConversationHistory: bedrock.RelayConversationHistoryType.TO_COLLABORATOR,
        }),
      ],
    });

Deploys correctly:
image
Screenshot 2025-03-04 at 3 19 57 PM
Screenshot 2025-03-04 at 3 23 10 PM
Screenshot 2025-03-04 at 3 20 04 PM

@krokoko krokoko requested a review from aws-rafams March 4, 2025 21:26
@krokoko krokoko changed the title feat(agent): add support for collab, orch and FM in prompt feat(agent): add support for agent collab, orch and FM in prompt Mar 4, 2025
Copy link
Contributor

@aws-rafams aws-rafams left a comment

Choose a reason for hiding this comment

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

Overall, the interfaces appear well-designed and intuitive. My only suggestion pertains to the Agent Descriptor. In my opinion, it would be more consistent and clear to replace it with IAgentAlias. This aligns better the naming convention used in the console, which features a simple Agent Alias and makes no mention of AgentDescriptor.
Apart from this minor adjustment, the work is pretty neat. Great job!
Screenshot 2025-03-05 at 09 52 46

@trey-rosius
Copy link

Hi folks, will this PR be merged anytime soon ?

@ztanruan
Copy link

any update on this request ?

@krokoko
Copy link
Collaborator Author

krokoko commented Mar 15, 2025

Testing with the a collaborator agent, working as expected:

image

@krokoko
Copy link
Collaborator Author

krokoko commented Mar 15, 2025

Testing with 2 collaborators:
image
Requests are properly routed:
image

image

@krokoko
Copy link
Collaborator Author

krokoko commented Mar 15, 2025

Testing custom orchestration:

with the following code snippet (lambda code from here:

 // Create a Lambda function for custom orchestration
    const orchestrationFunction = new lambda.Function(this, 'OrchestrationFunction', {
      runtime: lambda.Runtime.PYTHON_3_10,
      handler: 'index.handler',
      code: lambda.Code.fromAsset(path.join(__dirname, '../lambda/orchestration')),
    });

    // Create an agent with custom orchestration
    const agent = new bedrock.Agent(this, 'CustomOrchestrationAgent', {
      name: 'CustomOrchestrationAgent',
      instruction: 'You are a helpful assistant with custom orchestration logic.',
      foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
      orchestrationType: bedrock.OrchestrationType.CUSTOM_ORCHESTRATION,
      customOrchestration: {
        executor: bedrock.OrchestrationExecutor.fromlambdaFunction(orchestrationFunction),
      },
    });

The stack deploys correctly and custom orchestration is correctly applied:

image

Custom logic is correctly invoked:

image

@krokoko
Copy link
Collaborator Author

krokoko commented Mar 15, 2025

Testing prompt override foundation model:

const customerSupportAgent = new bedrock.Agent(this, 'CustomerSupportAgent', {
      foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
      instruction: 'You specialize in answering customer support questions about our products.',
      userInputEnabled: true,
      shouldPrepareAgent:true
    });

    const customerSupportAlias = new bedrock.AgentAlias(this, 'CustomerSupportAlias', {
      agent: customerSupportAgent,
      aliasName: 'production',
    });

    const agent = new bedrock.Agent(this, 'Agent', {
      foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1,
      instruction: 'You are a helpful and friendly agent that answers questions about literature.',
      userInputEnabled: true,
      codeInterpreterEnabled: false,
      shouldPrepareAgent:true,
      agentCollaboration: bedrock.AgentCollaboratorType.SUPERVISOR_ROUTER,
      agentCollaborators: [
        new bedrock.AgentCollaborator({
          agentAlias: customerSupportAlias,
          collaborationInstruction: 'Route customer support questions to this agent.',
          collaboratorName: 'CustomerSupport',
          relayConversationHistory: true,
        }),
      ],
      promptOverrideConfiguration: bedrock.PromptOverrideConfiguration.fromSteps(
        [
          {
            stepType: bedrock.AgentStepType.ROUTING_CLASSIFIER,
            stepEnabled: true,
            foundationModel: bedrock.BedrockFoundationModel.AMAZON_NOVA_LITE_V1
          }
        ]
      )
    });   

Stack deploys correctly. Collaborator routing is correctly configured to the new model:

image Screenshot 2025-03-15 at 6 28 12 PM

@krokoko krokoko self-assigned this Mar 15, 2025
@krokoko krokoko marked this pull request as ready for review March 15, 2025 23:29
@krokoko krokoko requested a review from a team as a code owner March 15, 2025 23:29
@krokoko krokoko enabled auto-merge (squash) March 15, 2025 23:33
@krokoko
Copy link
Collaborator Author

krokoko commented Mar 15, 2025

any update on this request ?

PR is open now, once reviewed it will be in

Copy link
Contributor

@MichaelWalker-git MichaelWalker-git left a comment

Choose a reason for hiding this comment

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

LGTM

@krokoko krokoko merged commit 91db9e4 into awslabs:main Mar 17, 2025
12 of 13 checks passed
@krokoko krokoko moved this from In Progress to Done in AWS Generative AI Constructs Backlog Apr 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

feat(bedrock): Agent Custom Orchestration feat(bedrock): Agent Collaboration
7 participants