How to integrate AWS Bedrock Models like NOVA etc using Autogen ? #6449
Replies: 1 comment
|
Thanks for laying out the Azure + AWS requirement so clearly, and for following up with the concrete Nova traces in #6479 and #6480. That made it easy to test the exact path you are on. There is no generic Bedrock client in What I ran (autogen
pip install "autogen-agentchat" "autogen-ext[semantic-kernel-aws]"import asyncio
import boto3
from autogen_agentchat.agents import AssistantAgent
from autogen_core.models import ModelFamily
from autogen_ext.models.semantic_kernel import SKChatCompletionAdapter
from semantic_kernel import Kernel
from semantic_kernel.connectors.ai.bedrock import BedrockChatCompletion, BedrockChatPromptExecutionSettings
def get_weather(city: str) -> str:
"""Get the weather for a city."""
return f"The weather in {city} is 75 degrees."
async def main() -> None:
region = "us-east-1" # boto3 uses its normal credential chain (profile, env vars, Bedrock API key)
sk_client = BedrockChatCompletion(
model_id="us.amazon.nova-lite-v1:0",
runtime_client=boto3.client("bedrock-runtime", region_name=region),
client=boto3.client("bedrock", region_name=region),
)
model_client = SKChatCompletionAdapter(
sk_client,
kernel=Kernel(),
prompt_settings=BedrockChatPromptExecutionSettings(temperature=0.0, max_tokens=512),
model_info={"function_calling": True, "json_output": False, "vision": True, "family": ModelFamily.UNKNOWN, "structured_output": False},
)
agent = AssistantAgent("assistant", model_client=model_client, tools=[get_weather])
result = await agent.run(task="What is the weather in Paris?")
print(result.messages[-1].content)
asyncio.run(main())Why tool calls break on stock diff --git a/python/packages/autogen-ext/src/autogen_ext/tools/semantic_kernel/_kernel_function_from_tool.py b/python/packages/autogen-ext/src/autogen_ext/tools/semantic_kernel/_kernel_function_from_tool.py
index 1149195..5b8cb0e 100644
--- a/python/packages/autogen-ext/src/autogen_ext/tools/semantic_kernel/_kernel_function_from_tool.py
+++ b/python/packages/autogen-ext/src/autogen_ext/tools/semantic_kernel/_kernel_function_from_tool.py
@@ -70,17 +70,32 @@ async def tool_method(**kwargs: dict[str, Any]) -> Any:
self._tool = tool
+# JSON Schema type names -> type names SK's KernelJsonSchemaBuilder.build_from_type_name understands.
+_JSON_TYPE_TO_SK_TYPE = {
+ "string": "str",
+ "integer": "int",
+ "number": "float",
+ "boolean": "bool",
+ "array": "list",
+ "object": "dict",
+}
+
+
class KernelFunctionFromToolSchema(KernelFunctionFromPrompt):
def __init__(self, tool_schema: ToolSchema, plugin_name: str | None = None):
- properties = tool_schema.get("parameters", {}).get("properties", {})
- required = properties.get("required", [])
+ parameters = tool_schema.get("parameters", {})
+ properties = parameters.get("properties", {})
+ required = parameters.get("required", [])
prompt_template_config = PromptTemplateConfig(
name=tool_schema.get("name", ""),
description=tool_schema.get("description", ""),
input_variables=[
InputVariable(
- name=prop_name, description=prop_info.get("description", ""), is_required=prop_name in required
+ name=prop_name,
+ description=prop_info.get("description", ""),
+ is_required=prop_name in required,
+ json_schema=_JSON_TYPE_TO_SK_TYPE.get(prop_info.get("type", "string"), "dict"),
)
for prop_name, prop_info in properties.items()
],Raw outputs and notesAdapter parameter metadata, offline (no network), before and after the patch: Agent run on stock
|
Uh oh!
There was an error while loading. Please reload this page.
Hi ,
I want to keep Autogen as common multi agent framework in my agentic application who can supports both Azure and AWS models ? I see that there is no dedicated AWSBedrockChatCompletionClient like AzureOpenAI, AzureAI etc.
is it not supported yet? any workaround?
Thanks,
Amardeep
All reactions