Invoke your agent - Amazon Bedrock

Invoke your agent


The AWS CLI doesn't support InvokeAgent.

To interact with your agent, send an InvokeAgent request using a Amazon Bedrock Agent runtime endpoint ( Use TSTALIASID as the agentAliasId to invoke the draft version of your agent.

  • Specify the user input to provide the agent in the inputText field.

  • Set enableTrace to true to return the trace in the response. By default, the trace is disabled. For more information, see Trace events.

  • If you reuse a sessionId, you continue an existing session with the agent if the value you set for the idle session timeout hasn't been exceeded.

  • Set endSession to true to end the session with the agent.

  • In the sessionState object, you can set the following attributes.

    • Attributes for the prompt in the promptSessionAttributes object. You can define key-value attributes that which contains sessions attributes that go to the prompt.

    • Attributes for the session in the sessionAttributes object, which contains session attributes that are passed through attributes that are passed to the action group.

The response returns the following objects. If there is an error, the response returns an exception. For more information, see InvokeAgent Errors.

  • chunk – The bytes field contains the response to the user as a base-64 encoded binary object. If a knowledge base was queried, an attribution object with a list of citations is returned.

    • The retrievedReferences object contains the exact text in the chunk relevant to the query alongside the S3 location of the data source the text belongs to.

    • The generatedResponsePart object contains the text generated by the model based on the information from the text in the retrievedReferences.

  • trace – Use the trace to track the agent's reasoning process for carrying out action groups, querying knowledge bases, and its responses to customers. For information about the fields in the trace object, see Trace events. The trace is only returned if enableTrace was set as true in the request.