UnicornSpaceUI

Agents

Agents are LLMs equipped with external tools that let them perform actions beyond text generation. They become active problem-solvers rather than passive responders.

When AI Gains Tools to Act,

The movement when LLM's become agents are when they have been given access to tools or external function.

These tools are like add-ons and utilities as they give them the abilities and capabilities which they lacked previously just beyond text generation.

Think of an LLM as a brilliant consultant with perfect textbook knowledge but no real-world access. Agents give them:

  1. A phone (to call APIs)
  2. A browser (for live search)
  3. A calculator (for precise math)
  4. Keys to your data vault (DB access)

Eg: LLM's don't know the current realtime date and time, because they have a So now we'll give it a function(tool) that they can call/use when required and get the realtime data and show to user.

Real-World Agent Examples

1. Personal Finance Assistant

Problem: "How much did I spend on dining last month?"

  • Tools Used:
    • Calendar tool (get date range)
    • Banking API (fetch transactions)
    • Calculator (sum amounts)
  • Action Flow:
    Get dates → Query transactions → Filter "dining" → Sum → Generate report

2. Medical Research Agent

Problem: "Latest pancreatic cancer treatments?"

  • Tools Used:
    • PubMed search tool
    • Clinical trial database
    • PDF analyzer (for research papers)
  • Action Flow:
    Search recent studies → Check trials → Summarize findings → Warn about outdated knowledge cutoff

3. Supply Chain Agent

Problem: "Why is shipment #123 delayed?"

  • Tools Used:
    • Logistics DB query
    • Weather API
    • Vendor contact system
  • Action Flow:
    Check shipment status → Verify weather at hub → Contact vendor → Draft customer email

System Prompt for Agents

You are an AI agent with tool access. Your workflow:

1. Analyze user request
2. Select tools if needed (prioritize minimal tool usage)
3. Output STRICTLY in this JSON format:
{
  "thoughts": "<step-by-step reasoning>",
  "tool": "<tool_name> | null",
  "parameters": { ... } | null
}

# Available Tools
• current_datetime: No params. Returns ISO string.
• web_search: { "query": "string" } → Returns top 3 results
• db_query: { "sql": "SELECT ..." } → Returns JSON data

# Rules
- Use tools ONLY when necessary
- Never invent tool parameters
- If no tool needed, respond directly

Real-World Implementation Flow

Golden Rule: Agents should augment human capabilities, not replace human judgment. Always include "I don't know" fallbacks and verification steps.

Code implementation

# Weather agent that takes real time wheather
import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
    model="claude-3-7-sonnet-20250219",
    max_tokens=1024,
    tools=[
        {
            "name": "get_weather",
            "description": "Get the current weather in a given location",
            "input_schema": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city and state, e.g. San Francisco, CA",
                    }
                },
                "required": ["location"],

            },

        }
    ],
    messages=[
        {"role": "user", "content": "What's the weather like in San Francisco?"}],

)


# Tools
def get_weather(location):
    # do an actual whether call
    return 32


# running the tools
for a in message.content:
    if(a.type == "text"):
        print(a.text)
    elif(a.type == "tool_use"):
        if(a.name == "get_weather"):
            result = get_weather(a.input["location"])
            print(f"Weather {result} degree")

https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview