-
Notifications
You must be signed in to change notification settings - Fork 0
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
Update codebase to replace traditional agents by inline agents #478
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @johncordeiro, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
This pull request migrates the agent system from traditional AWS Bedrock Agents to the more flexible Inline Agents implementation. This change removes the need for pre-creating and deploying agents, allowing for faster iteration, runtime configuration, a simplified architecture, improved flexibility, and better support for multi-agent collaboration. The core changes involve removing traditional agent lifecycle management and adding support for configuring and invoking agents inline at runtime, while preserving Lambda function integration for custom actions/skills, maintaining knowledge base and session management, and streamlining IAM permissions and the security model.
Highlights
- Inline Agent Invocation: Introduces
invoke_inline_agent()
andinvoke_inline_agent_stream()
methods in theBedrockFileDatabase
class for direct agent invocation and streaming support. - Lambda Function Integration: Simplifies Lambda function integration by directly attaching them to inline agents, removing the need for complex action group management.
- Session and Knowledge Base Management: Maintains knowledge base and session management capabilities, including the ability to configure knowledge base integration and manage session state.
- IAM Permissions: IAM permissions are updated to allow
bedrock:InvokeInlineAgent
andlambda:InvokeFunction
actions.
Changelog
Click here to see the changelog
- nexus/task_managers/file_database/bedrock.py
- Removes the
update_agent
method. - Adds
invoke_inline_agent
method to invoke an inline agent with specified configurations. - Adds
invoke_inline_agent_stream
method for streaming responses from inline agents, including knowledge base integration and credentials. - Removes methods related to associating sub-agents, attaching knowledge bases, creating agents, and managing agent versions.
- Updates
create_lambda_function
to create a default alias for the function and simplifies the permission management. - Removes methods related to disassociating sub-agents, converting agents to supervisors, deleting agents, and invoking supervisors with streaming.
- Removes
prepare_agent
method. - Updates
_allow_agent_lambda
to allow Bedrock to invoke Lambda functions with inline agents. - Removes
wait_agent_status_update
method. - Removes
update_agent_action_group
and_create_lambda_iam_role
methods.
- Removes the
- nexus/task_managers/tasks_bedrock.py
- Removes
agent_external_id
andagent_version
parameters fromrun_create_lambda_function
andrun_update_lambda_function
tasks. - Updates docstrings for
run_create_lambda_function
andrun_update_lambda_function
to reflect changes in parameters.
- Removes
- nexus/usecases/agents/agents.py
- Removes
BedrockSubAgent
import. - Replaces
UpdateAgentDTO
withInlineAgentDTO
for inline agent configuration. - Removes methods related to assigning agents, creating agents, creating external agents, creating external agent aliases, updating agents to supervisors, creating supervisors, creating agent versions, and deleting agent versions.
- Adds
invoke_inline_agent
method to invoke an inline agent with the provided configuration. - Adds
invoke_inline_agent_stream
method to invoke an inline agent with streaming response. - Removes
agent_external_id
andagent_version
parameters fromcreate_skill
andupdate_skill
methods. - Removes methods related to invoking supervisors with streaming, preparing agents, unassigning agents, updating agents, and creating external supervisors.
- Removes methods related to updating supervisor collaborators and updating multi-agent configurations.
- Adds
validate_inline_agent_dto
method to validate the InlineAgentDTO fields. - Adds
create_dict_to_inline_dto
method to convert a dictionary to an InlineAgentDTO. - Removes methods related to updating dictionaries to DTOs, creating dictionaries to DTOs, handling agent DTOs, getting update fields, processing skill updates, and waiting for agent status updates.
- Removes
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
From agents old to inline new,
Bedrock's power shines anew.
No more waiting, swift and free,
Agents run inline, for you and me.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The code changes introduce inline agents, which is a significant improvement over traditional agents. The implementation is generally well-structured, but there are some areas that could be improved in terms of error handling, security, and configurability.
Summary of Findings
- Missing Error Handling: The code lacks proper error handling for Lambda function creation and updates. This could lead to unhandled exceptions and potential instability. It's important to implement try-except blocks to catch potential errors and handle them gracefully.
- Insecure Lambda Permissions: The Lambda permission policy uses a wildcard resource ARN, which is overly permissive and could pose a security risk. It's recommended to restrict the resource ARN to the specific Lambda functions that the Bedrock agent needs to invoke.
- Hardcoded Values: Several hardcoded values, such as the agent foundation model and session TTL, should be configurable via settings or environment variables to allow for easier customization and deployment.
Merge Readiness
The code changes introduce inline agents, which is a significant improvement over traditional agents. However, there are some areas that need to be addressed before merging, particularly error handling and security. I would recommend addressing these before merging. I am unable to directly approve the pull request, and that users should have others review and approve this code before merging.
self.lambda_client.add_permission( | ||
FunctionName=lambda_function_name, | ||
StatementId=f"allow_bedrock_{agent_id}", | ||
StatementId=f"allow_bedrock_inline_{uuid.uuid4()}", | ||
Action="lambda:InvokeFunction", | ||
Principal="bedrock.amazonaws.com", | ||
SourceArn=f"arn:aws:bedrock:{self.region_name}:{self.account_id}:agent/{agent_id}", | ||
SourceArn=f"arn:aws:bedrock:{self.region_name}:{self.account_id}:*" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This Lambda permission policy uses a wildcard resource ARN, which is overly permissive and could pose a security risk. It's recommended to restrict the resource ARN to the specific Lambda functions that the Bedrock agent needs to invoke.
FunctionName=lambda_function_name,
StatementId=f"allow_bedrock_inline_{uuid.uuid4()}",
Action="lambda:InvokeFunction",
Principal="bedrock.amazonaws.com",
# Restrict the resource ARN to the specific Lambda function
SourceArn=f"arn:aws:lambda:{self.region_name}:{self.account_id}:function:{lambda_function_name}"
except Exception as e: | ||
print(f"Error fetching credentials: {str(e)}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding more specific error handling here. Catching all exceptions might mask important issues. At a minimum, log the exception details.
except Exception as e: | |
print(f"Error fetching credentials: {str(e)}") | |
except Exception as e: | |
print(f"Error fetching credentials: {str(e)}") | |
# Consider logging the error with more details | |
# logging.exception("Error fetching credentials") |
Migrating to AWS Bedrock Inline Agents
This document provides an overview of the migration from traditional AWS Bedrock Agents to the new Inline Agents approach in Nexus AI.
Overview
We've migrated our agent system from traditional AWS Bedrock Agents (which required pre-creating and deploying agents) to the more flexible Inline Agents implementation. This change brings several key benefits:
Implementation Details
Core Changes
Key Components
1.
BedrockFileDatabase
ClassThe core client for interacting with AWS Bedrock services has been updated with:
invoke_inline_agent()
method for direct agent invocationinvoke_inline_agent_stream()
2.
AgentUsecase
ClassThe agent use case layer has been simplified:
invoke_inline_agent()
method3. Lambda Function Integration
Lambda functions are now directly attached to inline agents:
Usage Examples
Basic Agent Invocation
Using Knowledge Base
Streaming Responses
Using Lambda Functions
Best Practices
Session Management
Knowledge Base Integration
Lambda Function Design
Security
IAM Permissions
The inline agent approach requires the following IAM permissions:
Troubleshooting
Common issues and solutions:
Session State Issues
Lambda Function Errors
Response Formatting Problems