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

SDK doesn't handle return of control for agent actions #6592

Open
3 of 4 tasks
v-giorgetti opened this issue Oct 28, 2024 · 4 comments
Open
3 of 4 tasks

SDK doesn't handle return of control for agent actions #6592

v-giorgetti opened this issue Oct 28, 2024 · 4 comments
Assignees
Labels
bug This issue is a bug. p3 This is a minor priority issue

Comments

@v-giorgetti
Copy link

v-giorgetti commented Oct 28, 2024

Checkboxes for prior research

Describe the bug

Hi, I'm currently implementing a chatbot to help our customers execute actions, and I've setup a test agent in AWS with a single action (defined in a group action) that is triggered when the customer asks to open a ticket.
This action is defined with the option return of control, which means I should get the payload so I can handle the action the user is trying to achieve.
Though I couldn't find any documentation that is providing the ability to do that, except in Python where the SDK provides a field in the InvokeAgent command response.

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.15.0

Reproduction Steps

import { InvokeAgentCommand } from '@aws-sdk/client-bedrock-agent-runtime';
import { getClient } from '../client';
import { AGENT_CONFIG } from '../config';

export const askAgent = async (prompt: string, sessionId: string) => {
    const client = getClient();

    const command = new InvokeAgentCommand({
        agentId: AGENT_CONFIG.agentId,
        agentAliasId: AGENT_CONFIG.agentAlias,
        sessionId: sessionId + '-bedrock',
        inputText: prompt
    });

    try {
        let completion = '';

        const response = await client.send(command);

        // ? There is no field in the response that provide the payload of the action that is triggered

        for await (const chunkEvent of response.completion) {
            const chunk = chunkEvent.chunk;
            console.log(chunk);
            const decodedResponse = new TextDecoder('utf-8').decode(chunk.bytes);
            completion += decodedResponse;
        }
        return { sessionId: sessionId, completion };
    } catch (err) {
        console.error(err);
    }
};

Observed Behavior

There is no field in the response that provide the payload of the action that is triggered
Response type is :

export interface InvokeAgentResponse {
    /**
     * <p>The agent's response to the user prompt.</p>
     * @public
     */
    completion: AsyncIterable<ResponseStream> | undefined;
    /**
     * <p>The MIME type of the input data in the request. The default value is <code>application/json</code>.</p>
     * @public
     */
    contentType: string | undefined;
    /**
     * <p>The unique identifier of the session with the agent.</p>
     * @public
     */
    sessionId: string | undefined;
    /**
     * <p>The unique identifier of the agent memory.</p>
     * @public
     */
    memoryId?: string;
}

Expected Behavior

We should have a nullable returnControl field like the python library does

Possible Solution

No response

Additional Information/Context

No response

@v-giorgetti v-giorgetti added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 28, 2024
@aBurmeseDev aBurmeseDev self-assigned this Oct 31, 2024
@aBurmeseDev
Copy link
Member

Hi @v-giorgetti - thanks for reaching out.

It sounds like returnControlPayload is missing in your response. I was able to return it in my response and you can see the code in model file here. Can you share your response? Also when you say Python library, are you referring to boto3?

@aBurmeseDev aBurmeseDev added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Nov 1, 2024
@v-giorgetti
Copy link
Author

Hey @aBurmeseDev, thanks for answering.
I do not get the returnControlPayload when invoking agent, here's the response of the agent when it should have executed my action:

{
  "$metadata": {
    "httpStatusCode": 200,
    "requestId": "c905440f-0e00-45e0-b3b6-7f3f94e81006",
    "attempts": 1,
    "totalRetryDelay": 0
  },
  "contentType": "application/json",
  "sessionId": "playground_user",
  "completion": {
    "options": {
      "messageStream": {
        "options": {
          "inputStream": {},
          "decoder": {
            "headerMarshaller": {},
            "messageBuffer": [],
            "isEndOfStream": false
          }
        }
      }
    }
  }
}

Here is my InvokeAgent input :

let options: InvokeAgentCommandInput = {
  agentId: AGENT_CONFIG.agentId,
  agentAliasId: AGENT_CONFIG.agentAlias,
  sessionId: sessionId,
  inputText: "bla bla bla"
};

const command = new InvokeAgentCommand(options);
const response: InvokeAgentCommandOutput = await client.send(command);

Am I missing something?

I'm also adding my action configuration

image

@v-giorgetti
Copy link
Author

And yes, by Python library I’m referring to boto3

@v-giorgetti
Copy link
Author

Ok nvm, I was able to get the return control by extracting it from the response.completion, here's the snippet:

const response: InvokeAgentCommandOutput = await client.send(command);

if (!response || !response.completion) {
  return { sessionId: sessionId, completion: '' };
}

for await (const chunkEvent of response.completion) {

  if (chunkEvent.returnControl) {
    console.log('returnControl', chunkEvent.returnControl);
  } else {
    const chunk = chunkEvent.chunk;
    const decodedResponse = new TextDecoder('utf-8').decode(chunk.bytes);
    completion += decodedResponse;
  }
}

I was expecting to get it from the response as boto3 does, silly me!

You may close the ticket.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

2 participants