Agentic AI - Series 3

                                                       

In this blog we will see how to build a simple agent without using any LLM model.

Simple flow of an agent:

Agent takes input -> Based on the input, it decides which tool to use -> Performs operation and send the output back to the user.

An AI agent framework is a set of tools, libraries, and structures that simplifies building, deploying, and managing autonomous AI agents.

But, here we are going to build an agent without using any framework and LLM's.

Agent functionality is to perform "Addition" and "Subtraction".

Agent uses 2 python functions (Tools) to perform addition and subtraction operations.

Finally, it send the output to the user.

We are going to implement the above discussed functionality via Python.

Tool for performing math operations:

def add(x,y):
    return x+y

def subtract(x,y):
    return x-y

Tool for processing user input:

def extract_numbers(text):
    return [int(s) for s in text.split() if s.isdigit()]

Finally our agent definition:

def simple_agent(user_input: str):
    """
    Very basic rule-based agent
    """
    user_input = user_input.lower()
    # Decide action
    if "add" in user_input or "+" in user_input:
        numbers = extract_numbers(user_input)
        return add(numbers[0], numbers[1])

    elif "subtract" in user_input or "-" in user_input:
        numbers = extract_numbers(user_input)
        return subtract(numbers[0], numbers[1])

    else:
        return "I don't know how to help with that."

1) Agent takes user input.

2) Decides what action to perform (add) or (sub) from the input.

3) Extract the numbers from the given the input.

4) Based on the action, respective tool (function) will be invoked.

5) Return the results to the user.

print(simple_agent("add 5 and 7"))
print(simple_agent("10 - 3"))
print(simple_agent("multiply 4 and 5"))

######## Output ########
12
7
I don't know how to help with that.


In the next series, we will see how to build an agent using a famous framework called "Langchain".

Comments

Popular posts from this blog

K8s - ETCD

SRE Interview Questions and Answers - Part II

K8s - Deployment and HPA replicas