π Pydantic AI Agents: Making AI Work for You (Without the Sci-Fi Apocalypse) π€
Welcome, future AI overlords (or at least enthusiastic learners)! Today, we're diving into Pydantic AI Agents, a magical blend of Python, automation, and artificial intelligence that makes your life easier (and way cooler). Whether you need an assistant, a web search ninja, or a chatbot buddy, these AI agents have your back. Let's explore three awesome use cases!
1οΈβ£ The Basic Agent β Your AI Sidekick π¦ΈββοΈ
Ever wished for a personal assistant who never complains, never asks for a raise, and always has an answer? Meet our Basic AI Agent, powered by Llama 3.2!
π Code:
from agno.agent import Agent, RunResponse
from agno.models.ollama import Ollama
agent = Agent(
model=Ollama(id="llama3.2"),
markdown=True
)
# Ask the AI about government stuff (or anything else!)
agent.print_response("What is the Ministry of Corporate Affairs in India? What does it do?")
π‘ What Does It Do?
- Reads your mind (not really, but it does understand your questions).
- Processes your input using Llama 3.2 (a powerful AI model).
- Prints intelligent responses without an attitude.
Response:
π Real-Life Use Case: Use this agent to automate research for your projects, emails, or just settle arguments in group chats.
2οΈβ£ The Web Search Agent β Your AI Detective π
Tired of Googling everything and getting lost in clickbait articles? Enter the Web Search Agent, which fetches the latest news, trends, and research papers faster than your conspiracy-theory-loving uncle.
π Code:
# Install the tools first: pip install phidata duckduckgo-search arxiv
from agno.agent import Agent
from agno.models.ollama import Ollama
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.arxiv import ArxivTools
agent = Agent(
model=Ollama(id="llama3.2"),
tools=[DuckDuckGoTools(), ArxivTools()], # Internet searching powers activated!
show_tool_calls=True,
markdown=True
)
# Let's dig into Reinforcement Learning research!
agent.print_response("Search arXiv for 'Reinforcement Learning'")
π‘ What Does It Do?
- Ducks into DuckDuckGo (for the latest web news).
- Raids ArXiv (for cutting-edge research papers).
- Finds answers instantly, without opening 100+ browser tabs.
Response:
π Real-Life Use Case: Perfect for students, researchers, and news junkies who want real-time updates on tech, finance, or cat videos (we wonβt judge).
3οΈβ£ The Chat Agent β Your AI BFF (That Never Ignores You) π¬
Why text real people when you can chat with an AI that actually listens? The Chat Agent is a conversational AI that responds in real-time through a slick Streamlit UI.
π Code (chatAgent.py
):
# Install dependencies: pip install pydantic requests streamlit ollama
import streamlit as st
from pydantic import BaseModel
import ollama
# π Meet your new AI buddy!
class AIAgent(BaseModel):
name: str = "OllamaBot"
version: str = "1.0"
description: str = "A chatbot powered by Ollama LLM."
agent = AIAgent()
# π οΈ Streamlit UI
st.title("π€ iMMSS LLM for Legal Assistance")
st.write("Ask me anything! (Type 'exit' to stop)")
# π€ Keep chat history alive!
if "messages" not in st.session_state:
st.session_state.messages = []
# π Show chat history
for msg in st.session_state.messages:
st.write(msg)
# π€ Accept user input
user_query = st.text_input("You:", "")
# π§ AI Response Function
def get_ai_response(question: str):
response = ollama.chat(model="llama3.2", messages=[{"role": "user", "content": question}])
return response["message"]["content"]
# π Processing user input
if user_query:
if user_query.lower() == "exit":
st.write("π Chatbot: Goodbye! Shutting down...")
st.stop()
# Generate response
ai_answer = get_ai_response(user_query)
# Save chat history
st.session_state.messages.append(f"**You:** {user_query}")
st.session_state.messages.append(f"**{agent.name}:** {ai_answer}")
# Display AI response
st.write(f"**{agent.name}:** {ai_answer}")
π‘ What Does It Do?
- Listens to you like a good friend (no ghosting).
- Answers your questions instantly using Llama 3.2.
- Keeps the conversation going (until you type "exit").
π Real-Life Use Case: Use it for legal help, customer support, or just for fun chats when your friends are too busy watching Netflix.
π Wrapping Up: Why Pydantic AI Agents?
These AI agents make your life easier, more fun, and way more productive by automating tasks, searching the web, and chatting in real time.
π€ What You Can Build Next?
- AI-powered customer support chatbots.
- Real-time finance & stock market trackers.
- Automated legal advisors (because lawyers are expensive).
- A meme generator (because why not?).
π Ready to start? Run the code, break things, and let AI do the boring work while you relax! π