# Code examples from: AI Agents and Tool Calling Explained (With a 20-Line Example)
# https://www.atulvij.com/ai-agents-tool-calling-explained
# Review and adapt before running; examples use sample values.

# ---- Example 1 (python) ----
def get_rate(frm, to):
    return {"USD->INR": 83.2}.get(f"{frm}->{to}")    # call a real API here

TOOLS = {"get_rate": get_rate}
messages = [{"role": "user", "content": "How much is 250 USD in rupees?"}]

for _ in range(5):                                  # hard limit on steps
    reply = llm_chat(messages, tools=TOOL_SCHEMAS)  # your provider's chat API
    messages.append(reply)
    call = reply.get("tool_call")
    if not call:
        print(reply["content"])
        break
    result = TOOLS[call["name"]](**call["arguments"])
    messages.append({"role": "tool", "name": call["name"], "content": str(result)})

