AI Agent Tools
Multi-tool AI agent with web search and research capabilities
An AI research assistant that autonomously uses multiple tools to gather information, combining web search, Wikipedia lookups, and file operations. This gave me exposure to LangChain, AI agents and tools implementation.
Tech Stack
- AI Framework:
LangChain - LLM:
OpenAI GPT-4o-mini - Tools: DuckDuckGo Search, Wikipedia API, File I/O, Dad Jokes API
- Output Parsing:
Pydanticfor structured responses - Language:
Python 3.8+
Architecture
User Query
│
▼
┌─────────────────────┐
│ LangChain Agent │
│ (GPT-4o-mini) │
└──────────┬──────────┘
│
│ (decides which tools to use)
│
┌──────┴──────┬──────────┬──────────┐
▼ ▼ ▼ ▼
┌────────┐ ┌─────────┐ ┌──────┐ ┌──────┐
│ Search │ │ Wiki │ │ Save │ │ Joke │
│ Tool │ │ Tool │ │ Tool │ │ Tool │
└────────┘ └─────────┘ └──────┘ └──────┘
│ │ │ │
└─────────────┴──────────┴──────────┘
│
▼
┌──────────────────┐
│ Structured Output│
│ (Pydantic) │
└──────────────────┘
Key Features & Implementation
- Autonomous Tool Calling -
LangChainagent autonomously decides which tools to invoke based on user query, demonstrating AI reasoning capabilities. - Web Search Integration - DuckDuckGo tool fetches current information from the web for queries requiring real-time data.
- Knowledge Retrieval - Wikipedia API wrapper provides structured lookups with configurable result limits and character constraints.
- Structured Output -
Pydanticschema enforces consistent response format with topic, summary, sources, and tools used. - File Operations - Custom tool saves research outputs to timestamped text files with automatic filename handling.
- Dad Jokes Tool - Implemented a custom tool that called an external API to get dad jokes.
Tool Implementation
Custom Get Dad Jokes Tool:
def get_dad_joke(input_text: str = "") -> str:
url = "https://icanhazdadjoke.com/"
headers = {"Accept": "application/json"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
joke = response.json().get("joke", "No joke found.")
return joke
else:
return "Failed to fetch a joke."
dad_joke_tool = Tool(
name="get_dad_joke",
func=get_dad_joke,
description="Returns a random dad joke from the API. Input can be any string (not used)."
)
Agent Configuration:
llm = ChatOpenAI(model="gpt-4o-mini")
tools = [search_tool, wiki_tool, save_tool, dad_joke_tool]
agent = create_tool_calling_agent(llm=llm, prompt=prompt, tools=tools)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
Output Schema
The agent returns structured data using Pydantic:
class ResearchResponse(BaseModel):
topic: str
summary: str
sources: list[str]
tools_used: list[str]
dad_joke: str # Optional
Example Output:
{
"topic": "Recent AI developments",
"summary": "Latest advancements in large language models...",
"sources": ["https://example.com/ai-news", "Wikipedia: Artificial Intelligence"],
"tools_used": ["search", "wiki_tool", "save_to_txt_file"],
"dad_joke": ""
}
Learnings
- New Technologies:
LangChain,OpenAI API, AI agent orchestration - Agent Design: Understanding when agents should use tools vs. relying on base knowledge
- Structured Output: Using
Pydanticfor type-safe, predictable AI responses - Tool Integration: Creating custom tools that called an external API get data jokes. It integrated seamlessly with LangChain framework
Demo
Click to watch demo video showing the agent in action
Links
- GitHub Repository: ctheara/ai-agent-tools
- Demo Video: Watch on Loom
Technologies: Python · LangChain · OpenAI · GPT-4o-mini · Pydantic · DuckDuckGo API · Wikipedia API · AI Agents