๐Ÿค–

AI Agents

๐Ÿ‘จโ€๐Ÿณ๐Ÿ‘‘ Master Chef

Autonomous AI Agents

An agent = LLM + tools + reasoning loop to complete complex tasks.


Agent vs Chatbot

ChatbotAgent
One responseMultiple steps
No toolsUses tools
ReactiveProactive
You controlIt decides

Agent architecture

              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚            AGENT                โ”‚
              โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
              โ”‚  โ”‚       Reasoning         โ”‚    โ”‚
   Task  โ”€โ”€โ”€โ†’ โ”‚  โ”‚  (ReAct, CoT, ToT)      โ”‚ โ”€โ”€โ”€โ†’ Result
              โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
              โ”‚              โ†“                  โ”‚
              โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
              โ”‚  โ”‚        Tools            โ”‚    โ”‚
              โ”‚  โ”‚  [Web] [Code] [Files]   โ”‚    โ”‚
              โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

ReAct pattern

Thought: I need to search Madrid's weather
Action: search_weather("Madrid")
Observation: 22ยฐC, sunny
Thought: I have the info now
Action: respond("The weather in Madrid is 22ยฐC...")

Common tools

ToolUse
web_searchSearch information
read_fileRead documents
write_fileCreate files
run_codeExecute Python
ask_userRequest clarification

Basic agent with OpenAI

tools = [
    {
        "type": "function",
        "function": {
            "name": "search",
            "description": "Search the web",
            "parameters": {
                "type": "object",
                "properties": {
                    "query": {"type": "string"}
                }
            }
        }
    }
]

# Agent loop
while True:
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=messages,
        tools=tools
    )

    if response.choices[0].finish_reason == "tool_calls":
        # Execute tool
        tool_call = response.choices[0].message.tool_calls[0]
        result = execute_tool(tool_call)
        messages.append({"role": "tool", "content": result})
    else:
        # Final response
        break

Agent frameworks

FrameworkFocus
LangChainChains and agents
LangGraphState graphs
CrewAIMulti-agent
AutoGenConversation
Claude CodeCoding agent

๐Ÿฆ Real Case: Bank Reconciliation Agent

Agents excel at financial tasks requiring multiple steps and decisions.

Example: Reconciliation Agent

tools = [
    {"name": "fetch_bank_transactions", "description": "Get transactions from bank"},
    {"name": "fetch_internal_records", "description": "Get internal records"},
    {"name": "compare_records", "description": "Compare and find differences"},
    {"name": "generate_report", "description": "Create reconciliation report"},
    {"name": "flag_discrepancy", "description": "Flag discrepancy for review"},
]

# The agent decides what to do
system_prompt = """
You are a bank reconciliation agent. Your job:
1. Get bank transactions (last 24h)
2. Get internal records for the same period
3. Compare and find discrepancies
4. If differences > $100, flag for human review
5. Generate final report

Be meticulous. An error here costs real money.
"""

Agent Flow

Task: "Reconcile yesterday's transactions"
    โ†“
Thought: First I get bank transactions
Action: fetch_bank_transactions("2024-01-15")
Observation: 847 transactions, total $1,234,567
    โ†“
Thought: Now internal records
Action: fetch_internal_records("2024-01-15")
Observation: 845 transactions, total $1,234,123
    โ†“
Thought: There's a difference. Compare in detail
Action: compare_records(bank, internal)
Observation: 2 missing transactions, difference $444
    โ†“
Thought: Difference > $100, flag for review
Action: flag_discrepancy({amount: 444, txns: [...]})
    โ†“
Action: generate_report() โ†’ โœ… Report sent

Other Fintech Use Cases

CaseToolsValue
Risk analysisCredit bureau APIs, calculatorsAutomated credit decision
Fraud detectionDatabases, rules, MLReal-time blocking
KYC onboardingOCR, verification, PEP databasesHours โ†’ minutes
Customer supportCRM, knowledge baseResolution without humans

๐Ÿ’ก Agents are ideal when the task has multiple steps and requires intermediate decisions.


Practice

โ†’ Autonomous AI Agent