pdf_agent_bytes.py
"""
Aws Pdf Agent Bytes
===================
Cookbook example for `aws/bedrock/pdf_agent_bytes.py`.
"""
from pathlib import Path
from agno.agent import Agent
from agno.media import File
from agno.models.aws import AwsBedrock
from agno.utils.media import download_file
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
pdf_path = Path(__file__).parent.joinpath("ThaiRecipes.pdf")
download_file(
"https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf", str(pdf_path)
)
agent = Agent(
model=AwsBedrock(id="amazon.nova-pro-v1:0"),
markdown=True,
)
pdf_bytes = pdf_path.read_bytes()
agent.print_response(
"Give the recipe of Gaeng Kiew Wan Goong",
files=[File(content=pdf_bytes, format="pdf", name="Thai Recipes")],
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
pass
Run the Example
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno aioboto3 boto3
3
Export environment variables
export AWS_ACCESS_KEY_ID="your_aws_access_key_id_here"
export AWS_REGION="your_aws_region_here"
export AWS_SECRET_ACCESS_KEY="your_aws_secret_access_key_here"
$Env:AWS_ACCESS_KEY_ID="your_aws_access_key_id_here"
$Env:AWS_REGION="your_aws_region_here"
$Env:AWS_SECRET_ACCESS_KEY="your_aws_secret_access_key_here"
4
Run the example
Save the code above as
pdf_agent_bytes.py, then run:python pdf_agent_bytes.py