Welcome to building document assistant using Amazon Bedrock Agents.
- Summarize: given a document, return its summary
- Retrieve info: question-answer based on a document
- Analyze data: simple quantitative data analysis
- Generate plot: based on the document data
- Make changes: adjust content formats
- AWS services: integrate with various services, ex. Textract, Translate, etc.
- Complex pipelines: accomplish multi-step changes and tasks
- Knowledge bases: RAG-based search across documents
Agents for Amazon Bedrock helps you accelerate generative artificial intelligence (AI) application development by orchestrating multistep tasks. They can make different API calls. Agents extend FMs to understand user requests, break down complex tasks into multiple steps, carry on a conversation to collect additional information, and take actions to fulfill the request.
Prerequisites: we will use Amazon Nova Lite v1 as model, make sure that you have access to it in your account.
- Go to Bedrock console, select
Agentsin the left navigation panel, then click on theCreate Agentbutton - Provide
agent-for-document-processingas Agent name, provide a description (optional). Click on theCreatebutton.
- You can now open the
Agent builder, the place where you can access and edit the overall configuration of an agent. We will selectAmazon Nova Lite v1as model (Pricing) [Note: If you face any issues with the model, try change it to Claude family models];
Paste the following text as Instructions for the Agent:
You are a document processing agent skilled at extracting key information from documents, translating content, summarizing text, and manipulating data formats.
Your tasks include finding key points in documents, locating documents in Amazon S3 and querying them, altering date formats in Excel files, summarizing long documents,
parsing PDFs with Amazon Textract and saving results to Amazon DynamoDB, and translating documents to required languages.
Use your capabilities to assist users with efficiently processing and analyzing document data.- In Additional settings, select
Enabledfor Code Interpreter
Leave all the rest as default. Then, choose Save and Exit to update the configuration of the agent.
In the test chat, click Prepare to update the agent.
π Append sample-company-report.docx (can be found inside example-documents) and ask:
what are the next crucial action items?π Append sales_data.xlsx (can be found inside example-documents) TO THE CODE EDITOR and ask:
alter sales dates to american format: instead of using YYYY-MM-DD, use YYYY-DD-MM, output updated file- Go to S3 console and click on the
Create bucketbutton - Give your bucket a unique name, for example
bucket-for-documents-NUMBER. ClickCreate bucket. - Select your created bucket, click on the
Uploadbutton. - You can drag and drop
invoice.pdfandcontrato-servicios.pdffiles (can be found insideexample-documents) and then click on theUploadbutton
- Navigate to the DynamoDB console and click on
Create table. - Enter
invoices-parsedasTable nameanddoc-nameasPartition key. Click on theCreate tablebutton. - Once the table is created, we don't need to add values. Agent will add values there.
Let's create one more table:
- Go to
Tablesand click onCreate table. - Enter
foreign-docsasTable nameanddoc-nameasPartition key. Click on theCreate tablebutton. - Click on the created table, then click on the
Actionsbutton and selectCreate itemfrom the drop-down list. - Paste
contrato-serviciosasdoc-name - Click on the
Add new attributebutton and selectString. Pastedocument_pathas Attribute name ands3://bucket-for-documents-NUMBER/contrato-servicios.pdfas value. - Click on the
Add new attributebutton and selectString. Pastelanguageas Attribute name andesas value. - Finally, click on the
Create itembutton.
Lambda Function will manage the logic required for complex actions. Code contains set of APIs that Bedrock agent will call. The function will then format the response and send it back to the agent.
- Navigate to the Lambda Console and click on
Create functionbutton. - Paste
document-agent-action-group-lambdaas a function name and choosePython 3.11as a runtime - Click on
Create functionbutton in the bottom of the page
Update permissions:
- Once the function is created, click on the Configuration Tab in the same page and Choose
Permissionsfrom the left side panel - Click on
Add permissionsbutton in Resource-based policy statement section to provide the permission to invoke lambda functions from Bedrock - Select
AWS service,Otheras Service, provide any valid Statement Id. Providebedrock.amazonaws.comas Principal, your agent ARN as Source ARN, and Action aslambda:InvokeFunction. ClickSave.
- Under the Execution role, click on the role link. Under Permission policies, click on
Add permissionsbutton, selectAttach policies. - Search for
TranslateReadOnly, then click onAdd permissions. Now Lambda can call Translate. - Under Permission policies, click on
Add permissionsbutton, selectCreate inline policy. - Click on
JSON, then paste JSON from thelambda-policy/DocumentLambdaServicePolicy.json. - Click
Next, name the policyDocumentLambdaServicePolicyand click onCreate policy. Now your Lambda has required access to Textract, S3, DynamoDB.
Adjust the timeout:
- Choose
General configurationfrom the left side panel - Click on the
Editbutton - Modify
Timeoutby increasing it to 3 minutes 30 seconds to make sure your Lambda won't fail while waiting for document parsing. - Click on the
Savebutton
Add code:
- Now you can go back to the Lambda function, click on the
Codetab in the same page - Copy the code from
lambda_function.pyand replace the code in code editor. - Click on the
Deploybutton.
Test your Lambda:
Since our Lambda contains a set of APIs, you may want to create several test events to test each API.
- Click on the
Testtab near the top of the page. - Fill in
Event name:extract-text - Paste the code from
lambda-payloads/extract-text.jsoninEvent JSONwindow. DON'T FORGET TO CHANGE S3 BUCKET NAME! This will be a test event for theextract_text_from_pdfAPI that matches how the Agent will send a request. - Click on
Saveand thenTestto execute the Lambda function. You should see the results of the successful function invocation.
- Click on
Create new eventbutton and repeat steps 2-4 to add one more test event (you can find JSON payload in thelambda-payloads/translate-test.json)
An action group is a toolbox that defines actions the agent can help the user perform.
One agent can have up to 20 action groups - see Bedrock quotas.
To create Action group: in the Agent builder choose Add in the Action groups section.
Use extract-and-translate-action-group as Action group name.
Use the following description:
The action group contains tools that parse PDFs with Amazon Textract and save results to Amazon DynamoDB, and translate documents to required languages.In the Action group type section, select Define with function details.
In the Action group invocation section, select Select an existing Lambda function and select document-agent-action-group-lambda as Lambda function.

We will add 2 action group functions.
Click on the Add action group function, then select JSON Editor and paste the following:
{
"name": "extract_text_from_pdf",
"description": "Parse a PDF with Amazon Textract and save results to DynamoDB",
"parameters": {
"s3_path": {
"description": "The path to the PDF file",
"required": "True",
"type": "String"
},
"table_name": {
"description": "The DynamoDB table name to save results to",
"required": "True",
"type": "String"
}
},
"requireConfirmation": "DISABLED"
}Next, click on the Add action group function, then select JSON Editor and paste the following:
{
"name": "translate_document",
"description": "Retrieve a PDF document by its name, check its language, translate if needed, save and update DynamoDB.",
"parameters": {
"document_name": {
"description": "PDF document name",
"required": "True",
"type": "String"
},
"table_name": {
"description": "The DynamoDB table name to save results to",
"required": "True",
"type": "String"
}
},
"requireConfirmation": "DISABLED"
}Click on Save and exit to exit from Action group editing.
Next, click on Save and exit to exit from the Agent builder.
In the test chat, click Prepare to update the agent.
π Go to the chat with agent and ask:
translate the contrato-servicios document, you can find it in foreign-docs tableπ Go to the chat with agent and ask (DON'T FORGET TO CHANGE THE BUCKET NAME!):
extract text from file s3://bucket-for-documents-NUMBER/invoice.pdf and update the invoices-parsed table- Go to S3 console and click on the
Create bucketbutton - Give your bucket a unique name, for example
knowledge-base-NUMBER. ClickCreate bucket. - Select your created bucket, click on the
Uploadbutton. - You can drag and drop
how-many-days-to-pay.docxandpo-creation.docxfiles (can be found insideknowledge-base-docs) and then click on theUploadbutton
- Go to Bedrock console, choose Builder tools -> Knowledge Bases from the navigation pane.
- Click on
Createand selectKnowledge base with vector store - Specify
knowledge-base-internal-docsas name, selectAmazon S3as data source, clickNext.
- Add 2 data sources: these should be .docx files that you uploaded to the
knowledge-base-NUMBERS3 bucket. Specify S3 URI locations for each of them, leave the rest as default. ClickNext
- Specify any embedding model (make sure you have enabled access to it). Select
Quick create a new vector storeandAmazon OpenSearch Serverless, clickNext. - After you review and create your knowledge base, make sure to Sync data sources and select a model to test.
- In the chat, write:
days to pay for USto make sure your Knowledge base works.
- Go back to your agent, open
Agent builder. Under theKnowledge bases, clickAdd - Select
knowledge-base-internal-docsand provide for Instructions:
Search in knowledge base information that is specific to a company or certain country- Click
Add. You can add up to 2 Knowledge bases per agent. - In the test chat, click
Prepareto update the agent.
π Go to the chat with agent and ask:
purchase order number generationTo resolve: Enable Code Editor
To resolve: add a resource-based policy statement on the Lambda
To resolve: Check Lambda output format

















