Skip to content

[Enhancement]: add bedrock-agent-runtime example for InvokeFlow command #6731

@danielgolub

Description

@danielgolub

Background story

confusing responseStream in JS sdk instead of the invocation result
most commands return the actual body of the documented response, but this command returns a responseStream which is not a regular js stream (that you can not do .on('finish') at)

I know that prompt flow is a preview feature, but a code example would be very beneficial for onboarding to it in my opinion.

What does this example accomplish?

invoke a prompt flow

Which AWS service(s)?

BedRock

Which AWS SDKs or tools?

  • All languages
  • .NET
  • C++
  • Go (v2)
  • Java
  • Java (v2)
  • JavaScript
  • JavaScript (v3)
  • Kotlin
  • PHP
  • Python
  • Ruby
  • Rust
  • Swift
  • Not applicable

Are there existing code examples to leverage?

no

Do you have any reference code?

const client = new BedrockAgentRuntimeClient();
  const command = new InvokeFlowCommand({
    flowIdentifier: '{ARN}',
    flowAliasIdentifier: '{ARN}',
    inputs: [
      {
        content: {
          document: "{PROMPT}",
        },
        nodeName: 'FlowInputNode',
        nodeOutputName: 'document',
      },
    ],
  });
  try {
    const response = await client.send(command);

    let responseJson;
    for await (const chunkEvent of response.responseStream) {
      const { document } = chunkEvent.flowOutputEvent.content;
      responseJson = JSON.parse(document);
      break;
    }

    console.info('extracted output from BedRock prompt flow', {
      prompt,
      responseJson,
    });

    return responseJson;
  } catch (error) {
    logger.error('error while querying bedrock', error);
  }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions