|
| 1 | +"""Example: Multi-Modal RAG & Image Agent |
| 2 | +
|
| 3 | +An agent that uses Llama 4 for multi-modal RAG and OpenAITools to create a visual, step-by-step image manual for a recipe. |
| 4 | +
|
| 5 | +Run: `pip install openai agno groq cohere` to install the dependencies |
| 6 | +""" |
| 7 | + |
| 8 | +from pathlib import Path |
| 9 | + |
| 10 | +from agno.agent import Agent |
| 11 | +from agno.embedder.cohere import CohereEmbedder |
| 12 | +from agno.knowledge.pdf_url import PDFUrlKnowledgeBase |
| 13 | +from agno.models.groq import Groq |
| 14 | +from agno.tools.openai import OpenAITools |
| 15 | +from agno.utils.media import download_image |
| 16 | +from agno.vectordb.pgvector import PgVector |
| 17 | + |
| 18 | +knowledge_base = PDFUrlKnowledgeBase( |
| 19 | + urls=["https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"], |
| 20 | + vector_db=PgVector( |
| 21 | + db_url="postgresql+psycopg://ai:ai@localhost:5532/ai", |
| 22 | + table_name="embed_vision_documents", |
| 23 | + embedder=CohereEmbedder( |
| 24 | + id="embed-v4.0", |
| 25 | + ), |
| 26 | + ), |
| 27 | +) |
| 28 | + |
| 29 | +knowledge_base.load() |
| 30 | + |
| 31 | +agent = Agent( |
| 32 | + name="EmbedVisionRAGAgent", |
| 33 | + model=Groq(id="meta-llama/llama-4-scout-17b-16e-instruct"), |
| 34 | + tools=[OpenAITools()], |
| 35 | + knowledge=knowledge_base, |
| 36 | + instructions=[ |
| 37 | + "You are a specialized recipe assistant.", |
| 38 | + "When asked for a recipe:", |
| 39 | + "1. Search the knowledge base to retrieve the relevant recipe details.", |
| 40 | + "2. Analyze the retrieved recipe steps carefully.", |
| 41 | + "3. Use the `generate_image` tool to create a visual, step-by-step image manual for the recipe.", |
| 42 | + "4. Present the recipe text clearly and mention that you have generated an accompanying image manual. Add instructions while generating the image.", |
| 43 | + ], |
| 44 | + markdown=True, |
| 45 | + debug_mode=True, |
| 46 | +) |
| 47 | + |
| 48 | +agent.print_response( |
| 49 | + "What is the recipe for a Thai curry?", |
| 50 | +) |
| 51 | + |
| 52 | +response = agent.run_response |
| 53 | +if response.images: |
| 54 | + download_image(response.images[0].url, Path("tmp/recipe_image.png")) |
0 commit comments