Autonomous AI Agents
An agent = LLM + tools + reasoning loop to complete complex tasks.
Agent vs Chatbot
| Chatbot | Agent |
|---|
| One response | Multiple steps |
| No tools | Uses tools |
| Reactive | Proactive |
| You control | It 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
| Tool | Use |
|---|
| web_search | Search information |
| read_file | Read documents |
| write_file | Create files |
| run_code | Execute Python |
| ask_user | Request 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
| Framework | Focus |
|---|
| LangChain | Chains and agents |
| LangGraph | State graphs |
| CrewAI | Multi-agent |
| AutoGen | Conversation |
| Claude Code | Coding 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
| Case | Tools | Value |
|---|
| Risk analysis | Credit bureau APIs, calculators | Automated credit decision |
| Fraud detection | Databases, rules, ML | Real-time blocking |
| KYC onboarding | OCR, verification, PEP databases | Hours โ minutes |
| Customer support | CRM, knowledge base | Resolution without humans |
๐ก Agents are ideal when the task has multiple steps and requires intermediate decisions.
Practice
โ Autonomous AI Agent