Created
August 9, 2025 20:41
-
-
Save mrbungie/1ad77fb9b8e2375075172d967f56a0d1 to your computer and use it in GitHub Desktop.
Llama4 with ToolOutput using PydanticAI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Either AWS credentials (AWS_SECRET_KEY or AWS_ACCESS_KEY_ID must be set before hand) | |
# OR also, you can use AWS_BEARER_TOKEN_BEDROCK | |
from pydantic import BaseModel | |
from pydantic_ai import Agent, ToolOutput | |
from pydantic_ai.providers.bedrock import BedrockModelProfile, BedrockProvider | |
from pydantic_ai.models.bedrock import BedrockConverseModel | |
MODEL_NAME = 'us.meta.llama4-scout-17b-instruct-v1:0' | |
class Fruit(BaseModel): | |
name: str | |
color: str | |
class Vehicle(BaseModel): | |
name: str | |
wheels: int | |
model = BedrockConverseModel( | |
model_name=MODEL_NAME, | |
profile=BedrockModelProfile(bedrock_supports_tool_choice=False) | |
) | |
agent = Agent( | |
model, | |
output_type=[ | |
ToolOutput(Fruit, name='return_fruit'), | |
ToolOutput(Vehicle, name='return_fruit') | |
] | |
) | |
result = await agent.run('What is a banana?') | |
result | |
result = await agent.run('What is a 4-wheeled ATV?') | |
result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment