Skip to content

Bedrock Agent API Ignores inputFiles Parameter but Console Works

0

I'm invoking a Bedrock Agent from Lambda using InvokeAgentCommand with an S3 document reference in the inputFiles parameter.

The agent cannot access the file in the bucket when invoked via a Lambda Function, I've tested with simple agents, overriding orchestration and default settings. The prompts I'm testing with are simple like: "Reply TRUE if you can read the file", but I can't get any response that indicates the Agent can read the file.

The same file reference works perfectly in the Bedrock console UI. I've verified permissions, aliases etc to no avail.

Is this API vs console behaviour difference a known issue? Any solution for making inputFiles work via API? (I don't want to add the file to a Knowledge Base).

2 Answers
0
Accepted Answer

Hello! Thank you for reaching out about the discrepancy you've noticed between the Bedrock Agent API and console behavior when using the inputFiles parameter.

After investigating this issue, I've found that the InvokeAgent API call doesn't currently include an inputFiles parameter [1]. This explains why you're unable to access the file when invoking the agent via Lambda using this parameter.

[1] https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent-runtime_InvokeAgent.html

Looking at the API documentation, we can see that the inputText parameter is allowed for the InvokeAgent API call. Additionally, we can use the sessionState parameter to reference files. Here's a snippet demonstrating how to pass file references:

response = bedrock_agent_runtime.invoke_agent(
    agentId='YOUR_AGENT_ID',
    agentAliasId='YOUR_AGENT_ALIAS_ID',
    sessionId='test-session',
    inputText='Read the contents of the file and summarize it.',
    sessionState={
        "files": [
            {
                "name": "your_file.txt",
                "source": {
                    "s3Location": {
                        "uri": "s3://your-bucket-name/your_file.txt"
                    },
                    "sourceType": "S3"
                },
                "useCase": "CHAT"
            }
        ]
    }
)

After testing this approach, we found that the Agent is able to read the text file, summarize it, and confirm its existence by returning TRUE.

I hope the above information is useful to you, In case you have additional or follow-up queries regarding AWS services, we may require details that are non-public information. Please open a support case with AWS using the following link.

AWS
answered 8 months ago
0

This issue with the Bedrock Agent API not recognizing the inputFiles parameter while the console works is a known problem that several users have encountered. The discrepancy between the API behavior and the console functionality suggests there might be limitations or implementation differences in how file inputs are handled through the API compared to the console interface.

Currently, there doesn't seem to be a straightforward solution to make inputFiles work reliably via the API. The API documentation and implementation appear to be inconsistent or incomplete regarding file handling for Bedrock Agents.

Some users have reported similar issues when trying to pass images or other file types to Bedrock Agents using the API. The API seems to reject or ignore the file-related parameters in many cases, leading to errors or the agent being unable to access the specified files.

As a workaround, you might consider:

  1. Using the Bedrock model API directly (not the agent API) to process the file contents, and then passing the processed information to the agent as part of the text input.

  2. Exploring alternative ways to provide the file content to the agent, such as including relevant text excerpts in the input text itself.

  3. Checking for any recent updates to the boto3 library, as some users have reported that updating to the latest version resolved certain API-related issues.

  4. Reaching out to AWS support for guidance on this specific use case, as they may have more up-to-date information or potential workarounds.

Given the current state, it seems that reliable file input handling through the Bedrock Agent API is still a work in progress. Keep an eye on AWS documentation and announcements for any updates or improvements to this functionality.

Sources
Send images as Base64 files to AWS BedRock Agent | AWS re:Post
able to use streamingConfigurations in AgentsforBedrockRuntime invoke_agent boto3 sdk | AWS re:Post

answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.