đ§ The Agent's Brain: Teaching A Multimodal AI To Think And Search The Web
In Part 1, we laid the groundwork. We architected a robust pipeline capable of handling video uploads, navigating the complexities of Google's asynchronous File API, and optimizing performance with smart caching. We built the "eyes" and "hands" of our system, but now it's time to build its "brain."
A data pipeline is only as good as the intelligence that uses it. The real challenge was transforming our functional pipeline into an intelligent agent that could reason, analyze, and autonomously use tools to answer complex questions. This is the story of how I crafted the agent's logic, battled with prompt engineering, and refined the user experience to create a truly useful AI tool.
The Core Challenge: Teaching an AI to Think
With the video processing pipeline in place, the next step was to get the agent to perform the analysis. My first attempt was simple. I gave the agent a basic instruction: "Summarize this video."
The results were... underwhelming. The summaries were often generic, inconsistent, and completely missed the user's intent. Sometimes they were too technical, other times too vague. It became clear that the agent needed more than a simple command; it needed a detailed set of instructionsâa carefully engineered prompt.
This led me to the most critical part of the project: prompt engineering. The prompt is the bridge between the user's goal and the AI's capabilities. A good prompt doesn't just ask a question; it provides context, sets constraints, and guides the model's reasoning process.
After dozens of iterations, I landed on a multi-part prompt structure that gave the Gemini model the clarity it needed.
# In app.py, inside the 'if st.button("Analyze Video")' block...
user_query = st.text_area(
"What insights are you seeking from the video?",
placeholder="Ask anything about the video content..."
)
# The final, engineered prompt that guides the agent
analysis_prompt = f"""
Analyze the uploaded video's content and context in detail.
Respond to the following query: "{user_query}"
Base your answer on insights from the video and supplement
it with web research using your available tools.
Provide a detailed, user-friendly, and well-structured response.
"""
Let's break down why this prompt is effective:
- Clear Role: It starts with a direct command: "Analyze the uploaded video's content and context in detail."
- Dynamic Input: It dynamically injects the
user_queryso the analysis is always tailored to the user's specific question. - Explicit Tool Instruction: This is the key. The line, "...supplement it with web research using your available tools," explicitly encourages the
Agnoagent to use theDuckDuckGoToolswe gave it during initialization. Without this instruction, the agent might not realize it's allowed to search the web. - Format Guidance: The final instruction, "Provide a detailed, user-friendly, and well-structured response," guides the model to produce output that is readable and actionable, not just a raw data dump.
The Magic of Agentic Execution
With a well-crafted prompt and a ready video file, triggering the entire complex workflow comes down to a single, elegant line of code, thanks to the Agno framework.
# In app.py
# ... after the polling loop confirms the video is 'ACTIVE' ...
# The agent takes the prompt and the video, and handles all the complexity.
response = multimodal_agent.run(
analysis_prompt,
videos=[{"filepath": video_path}], # Pass the video file path
)
# Display the final, formatted result to the user.
st.subheader("Analysis Result")
st.markdown(response.content)
This .run() method is where the magic happens. The Agno framework takes our prompt, the video, and the available tools, and orchestrates the entire process:
- It sends the video and prompt to the Gemini model.
- Gemini analyzes the content and determines if it needs more information to answer the
user_query. - If needed, the agent autonomously calls the DuckDuckGo tool to perform a web search.
- Finally, it synthesizes all the informationâfrom the video and the webâinto a single, coherent response.
Refining the User Experience
A powerful backend is useless if the frontend is confusing. As I tested the application, I realized that user experience (UX) was just as important as the AI logic. I focused on three key areas:
- Clear Instructions: The initial UI was minimal. I added a
placeholderandhelptext to thest.text_areato guide users toward asking specific, effective questions. - Managing Expectations: AI processing takes time. The
st.spinnerand status messages (st.write) we built in Part 1 are crucial for letting the user know the system is working and hasn't crash - Readable Output: The agent was configured with
markdown=True. This ensures the final output is well-formatted with headings, lists, and links, making the analysis easy to read and digest.
Key Takeaways from the Journey
This project was a profound learning experience that went far beyond writing code. It provided several key insights into modern AI development.
AI Development is System Integration: The most powerful AI applications often come from orchestrating multiple, specialized components. The magic wasn't in building a new model, but in making a vision model, a language model, and a search tool work together as a single, intelligent agent.
Embrace Asynchronicity: Many advanced AI APIs (for video, audio, or large-scale processing) are asynchronous. Building robust applications requires a shift in mindsetâfrom expecting immediate responses to designing patient, resilient polling and state-management workflows.
Prompt Engineering is a Core Skill: A great AI model with a poor prompt will produce poor results. Crafting clear, contextual, and well-structured prompts is not an afterthought; it is a central part of the development process that directly determines the quality of the final output.
Engineering Fundamentals Still Reign Supreme: The most impressive AI logic will fail if it's built on a shaky foundation. Principles like secure key management, robust error handling (
try...finally), and performance optimization (caching) are what elevate a cool prototype into a reliable, production-ready application.
The journey of building this application taught me that success in AI requires a blend of technical expertise, user empathy, and the persistence to debug the weird, unexpected issues that arise when working on the cutting edge.
Want to see how it all came together? You can find the entire project, including the final app.py and a detailed README, on my GitHub repository.