Skip to content

[Bug]: Issue with Bedrock AG2 implementationΒ #2218

@DanCorvesor

Description

@DanCorvesor

Describe the bug

We need to switch to using bedrock from open ai but we have encountered a key bug in the bedrock implementation:

We have a tool that looks like
def submit_website( url: Annotated[str | None, 'The website url to verify or None'], context_variables: ContextVariables,

This causes an error when the agent tries to call the tool
File "/mnt/custom-file-systems/efs/fs-05689f8a5c69a46ea_fsap-00a09c29c552bba70/c620-application/osint-agent/.venv/lib/python3.12/site-packages/autogen/oai/bedrock.py", line 549, in format_tools "type": prop_details["type"], ~~~~~~~~~~~~^^^^^^^^ KeyError: 'type' The reason for this is in line ~549 in autogen/oai/bedrock.py you have this line for prop_name, prop_details in function["parameters"]["properties"].items(): converted_tool["toolSpec"]["inputSchema"]["json"]["properties"][prop_name] = { "type": prop_details["type"], "description": prop_details.get("description", ""), }

When you have a Union annotation here, this prop_details is actually a nested dict {anyOf: {type: str, type: None}} so it can't find this key. The solution looks something like:

for prop_name, prop_details in function["parameters"]["properties"].items(): if "type" in prop_details.keys(): converted_tool["toolSpec"]["inputSchema"]["json"]["properties"][prop_name] = { "type": prop_details["type"], "description": prop_details.get("description", ""), } else: converted_tool["toolSpec"]["inputSchema"]["json"]["properties"][prop_name] = { "anyOf": prop_details["anyOf"], "description": prop_details.get("description", ""), } (edited)

Steps to reproduce

No response

Model Used

No response

Expected Behavior

No response

Screenshots and logs

No response

Additional Information

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions