Skip to content

DA-690: AWS Bedrock Agents Demo with Couchbase #35

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

Open
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

teetangh
Copy link
Collaborator

No description provided.

…otebook

- Updated IAM role and policy creation with more robust error handling
- Added bedrock-agent-runtime client for improved agent invocation
- Improved document processing with better logging and error tracking
- Refactored agent invocation to handle streaming responses
- Added error handling for agent interactions
@teetangh teetangh self-assigned this Feb 20, 2025
Copy link

github-actions bot commented Feb 20, 2025

Caution

Notebooks or Frontmatter Files Have Been Modified

  • Please ensure that a frontmatter.md file is accompanying the notebook file, and that the frontmatter is up to date.
  • These changes will be published to the developer portal tutorials only if frontmatter.md is included.
  • Proofread all changes before merging, as changes to notebook and frontmatter content will update the developer tutorial.

3 Notebook Files Modified:

Notebook File Frontmatter Included?
awsbedrock-agents/custom-control-approach/Bedrock_Agents_Custom_Control.ipynb
awsbedrock-agents/lambda-approach/Bedrock_Agents_Lambda.ipynb
awsbedrock-agents/lamda-old/Bedrock_Agents_Lambda.ipynb

3 Frontmatter Files Modified:

Frontmatter File
awsbedrock-agents/custom-control-approach/frontmatter.md
awsbedrock-agents/lambda-approach/frontmatter.md
awsbedrock-agents/lamda-old/frontmatter.md
Note: frontmatter will be checked and tested in the Test Frontmatter workflow.

- Simplified AWS client creation using a single session
- Updated IAM role permissions to be more comprehensive
- Modified document processing to use vector store directly
- Changed default model to Claude 3 Haiku
- Updated file path for documents.json
- Commented out agent-based document processing
…model invocation

- Added robust policy version management in IAM role creation
- Implemented error handling for agent creation process
- Updated default model to Amazon Nova Pro
- Added fallback mechanism for vector store search and direct model invocation
- Improved logging and error tracking for agent interactions
- Updated model from Nova Pro to Claude v2
- Modified model invocation parameters for better text formatting
- Simplified response parsing for formatted research findings
- Removed complex JSON payload in favor of direct prompt-based formatting
- Added support for two agent action group execution strategies:
  1. Custom Control with direct function calls
  2. Lambda function-based execution
- Created Lambda deployment script for agent functions
- Updated multi-agent workflow to demonstrate both approaches
- Added .gitignore entries for Lambda build artifacts
… mechanism

- Added retry logic and exponential backoff for Lambda function deployment
- Implemented error handling for various AWS service exceptions
- Added role readiness wait time to handle IAM role propagation
- Enhanced logging and error tracking during Lambda function packaging and deployment
- Added input validation for AWS account ID
…e and reliability

- Updated Lambda function code to use Claude 3 Sonnet model with new message-based API
- Enhanced Lambda deployment script with:
  * Increased timeouts and memory allocation
  * Improved error handling for large payloads
  * Dependency cleanup to reduce package size
- Added more comprehensive IAM permissions for Bedrock and agent interactions
- Updated requirements.txt to use latest Couchbase library
- Fixed file paths for Lambda deployment and document loading
…dling, and agent preparation

- Added comprehensive logging for agent invocation and tracing
- Implemented search index setup with robust error handling
- Enhanced collection setup with document clearing and improved logging
- Added agent preparation steps for researcher and writer agents
- Updated Lambda function deployment to handle existing functions
- Improved error handling and status tracking for agent action groups
- Added more detailed logging for agent interactions and Lambda deployments
- Removed Lambda function deployment from main workflow
- Updated action group creation to use "customControl" executor
- Simplified action group names and descriptions
- Commented out package cleanup steps in Lambda deployment scripts
- Added dotenv loading to Lambda function scripts
- Removed explicit prompt formatting in writer Lambda function
…handling

- Added comprehensive debugging for agent function invocations
- Implemented dynamic handling of search_documents and format_content functions
- Added detailed logging and error tracing for agent responses
- Updated invoke_agent method to support vector store integration
- Improved error messages and debugging output for agent interactions
- Passed vector_store to both Lambda and Custom Control approaches in main script
…e Integration

- Added comprehensive debugging for agent function invocations
- Enabled trace logging in invoke_agent method for detailed response tracking
- Created .env file generation for Lambda functions with vector store configuration
- Updated researcher and writer Lambda functions to support vector store integration
- Improved error handling and trace information logging
- Added more detailed console output for agent response debugging
@teetangh teetangh requested a review from nithishr March 6, 2025 08:33
@teetangh teetangh marked this pull request as ready for review March 6, 2025 08:34
@nithishr
Copy link
Contributor

@teetangh I see two different notebooks in here. Have you tested this with the developer portal to see if multiple notebooks in a folder are supported?

Also, I see two implementations here in the Python files as well as the Jupyter notebooks. I would like to understand the rationale for this.

  • An alternative for this would be to have the Jupyter notebooks here & move the Python code to a separate repo for easier testing.

@lokesh-couchbase
Copy link
Contributor

lokesh-couchbase commented Mar 17, 2025

Answering Q1:
@nithishr , same folder is right now not supported. Maybe we can change the actions file to support this. I think a parent folder could be added. Then multiple tutorials can be added in seperate folders inside the parent

@teetangh
Copy link
Collaborator Author

@nithishr

Lambda approach creates AWS Lambda functions that serve as the executors for the agent action groups, deploying separate functions for the researcher and writer agents. When the agent needs to perform an action like searching documents, it invokes the corresponding Lambda function which handles the request, performs the vector search, and returns results.
The Custom Control approach instead uses the "RETURN_CONTROL" mechanism where, when the agent needs to perform an action, control is returned to the main application which then directly executes the required functionality such as vector searches.

Both implementations achieve the same end result - allowing Bedrock agents to perform vector searches and format content - but through different architectural patterns.

@teetangh
Copy link
Collaborator Author

@lokesh-couchbase
Copy link
Contributor

tests will pass, however the frontmatter in main build can be wrong.

@teetangh
Copy link
Collaborator Author

@nithishr

  1. have made 2 folders for 2 notebooks.
  2. moved all python files to a seperate repo. kept just the 2 lamda functions.

@teetangh
Copy link
Collaborator Author

teetangh commented Apr 6, 2025

@nithishr added all explanations

@teetangh teetangh requested a review from nithishr April 6, 2025 21:43
Copy link
Contributor

@nithishr nithishr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better but still needs improvement

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Same comments as the other one.
  • Do you need to handle returnControl in the agent invoker?
  • Adding the default localhost in the connection string could cause problems if the user is running it in lambda env as that will never work
  • Why do you need to wait for the collection to be available before querying? That is not a known pattern

MemorySize=1536, # Increased to 1.5GB
Environment={
'Variables': {
'CB_HOST': os.getenv('CB_HOST', 'couchbase://localhost'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting localhost in lambda env?

with open(lambda_env_path, 'w') as f:
f.write(f"CB_HOST={CB_HOST}\n")
f.write(f"CB_USERNAME={CB_USERNAME}\n")
f.write(f"CB_PASSWORD={CB_PASSWORD}\n")

Check failure

Code scanning / CodeQL

Clear-text storage of sensitive information High

This expression stores
sensitive data (password)
as clear text.

Copilot Autofix

AI 7 days ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants