Return control to the agent developer by sending elicited information in an InvokeAgent response
Rather than sending the information that your agent has elicited from the user to a Lambda function for fulfillment, you can instead choose to return control to the agent developer by sending the information in the InvokeAgent response. You can configure return of control to the agent developer when creating or updating an action group. Through the API, you specify RETURN_CONTROL as the customControl value in the actionGroupExecutor object in a CreateAgentActionGroup or UpdateAgentActionGroup request. For more information, see Add an action group to your agent in Amazon Bedrock.
If you configure return of control for an action group, and if the agent determines that it should call an action in this action group, the API or function details elicited from the user will be returned in the invocationInputs field in the InvokeAgent response, alongside a unique invocationId. You can then do the following:
-
Set up your application to invoke the API or function that you defined, provided the information returned in the
invocationInputs. -
Send the results from your application's invocation in another InvokeAgent request, in the
sessionStatefield, to provide context to the agent. You must use the sameinvocationIdandactionGroupthat were returned in the InvokeAgent response. This information can be used as context for further orchestration, sent to post-processing for the agent to format a response, or used directly in the agent's response to the user.Note
If you include
returnControlInvocationResultsin thesessionStatefield, theinputTextfield will be ignored.
To learn how to configure return of control to the agent developer while creating the action group, see Add an action group to your agent in Amazon Bedrock.
Example for returning control to the agent developer
For example, you might have the following action groups:
-
A
PlanTripaction group with asuggestActivitiesaction that helps your users find activities to do during a trip. Thedescriptionfor this action saysThis action suggests activities based on retrieved weather information. -
A
WeatherAPIsaction group with agetWeatheraction that helps your user get the weather for a specific location. The action's required parameters arelocationanddate. The action group is configured to return control to the agent developer.
The following is a hypothetical sequence that might occur:
-
The user prompts your agent with the following query:
What should I do today?This query is sent in theinputTextfield of an InvokeAgent request. -
Your agent recognizes that the
suggestActivitiesaction should be invoked, but given the description, predicts that it should first invoke thegetWeatheraction as context for helping to fulfill thesuggestActivitiesaction. -
The agent knows that the current
dateis2024-09-15, but needs thelocationof the user as a required parameter to get the weather. It reprompts the user with the question "Where are you located?" -
The user responds
Seattle. -
The agent returns the parameters for
getWeatherin the following InvokeAgent response (select a tab to see examples for an action group defined with that method): -
Your application is configured to use these parameters to get the weather for
seattlefor the date2024-09-15. The weather is determined to be rainy. -
You send these results in the
sessionStatefield of another InvokeAgent request, using the sameinvocationId,actionGroup, andfunctionas the previous response. Select a tab to see examples for an action group defined with that method: -
The agent predicts that it should call the
suggestActivitiesaction. It uses the context that it's rainy that day and suggests indoor, rather than outdoor, activities for the user in the response.
Example for returning control to the collaborator agent
If you are using multi-agent collaboration and if an agent collaborator chooses to return control by sending the information in the InvokeAgent response, the information is returned in supervisor agent response with additional identifiers agentId and collaboratorName. Select a tab to see examples for an action group defined with that method:
Invoker of supervisor agent sends the results in the sessionState field back to supervisor agent with the corresponding agentId for it to be propagated to the right agent collaborator.