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: Pydantic for 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

  1. Autonomous Tool Calling - LangChain agent autonomously decides which tools to invoke based on user query, demonstrating AI reasoning capabilities.
  2. Web Search Integration - DuckDuckGo tool fetches current information from the web for queries requiring real-time data.
  3. Knowledge Retrieval - Wikipedia API wrapper provides structured lookups with configurable result limits and character constraints.
  4. Structured Output - Pydantic schema enforces consistent response format with topic, summary, sources, and tools used.
  5. File Operations - Custom tool saves research outputs to timestamped text files with automatic filename handling.
  6. 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

  1. New Technologies: LangChain, OpenAI API, AI agent orchestration
  2. Agent Design: Understanding when agents should use tools vs. relying on base knowledge
  3. Structured Output: Using Pydantic for type-safe, predictable AI responses
  4. 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



Technologies: Python · LangChain · OpenAI · GPT-4o-mini · Pydantic · DuckDuckGo API · Wikipedia API · AI Agents