DEV Community

Jesse Ni
Jesse Ni

Posted on

ELI5 - What is agentic AI?

Currently, mainstream agentic AI systems include closed source platforms such as Claude Code, Codex, Cursor, and open source platforms such as Opencode or Kilocode. How do these systems work then?

Standard LLM APIs

This is what happens what you directly use LLM APIs for requests:

"Hey Claude, what is the current weather in Beijing?"
Claude would probably say something like
"As an LLM, I do not have access to information about the latest weather...."

But even if you've used ChatGPT or any other AI, even in the webpage, you've probably seen it output correct information. So how does this work?

Tools

SYSTEM:
"Claude, if you want to search a query in google, just include a <\tool-call> token in front if a formatted json. Here is an example:

{
    "query" : "Weather in Toronto",
    "limit" : 5
}
Enter fullscreen mode Exit fullscreen mode

"
USER:
"Hi, what is the weather in Beijing?"
CLAUDE:"
<\tool-call>

{
    "query" : "Weather in Beijing",
    "limit" : 5
}
Enter fullscreen mode Exit fullscreen mode

"
TOOL_RESULT:
"The weather in Beijing for Jun 26 is ...."

There is no special framework towards tool use. Its just as simple as that. All you need to do is make a simple python script that, when sees tool-call tokens, automatically executes the tool, and automatically returns the result.

Agentic Loop

Essentially, there is a loop going on - the model gives its response, the hard-coded system detects if tool calls exist, if so, it executes the tool, and sends the response back to the LLM. We call this the Agentic Loop. Information gets looped between the LLM and the tools, and when the LLM finally decides to not call any tools, you get to see its final outputs.

What if the tool has an error, or the json formatting is incorrect? In such cases, we need automatic responses to tell the LLM "Hey, this json is not what the tool expected", so it can autocorrect its tool call.

Simplistic Calculator Tool Example

import json, re
LLM.append('......To use a tool, include JSON like {"tool": "calc", "expr": "2 + 3"} somewhere in your reply......')

msg = "What is 47 * 89 + 12?"
while True:
    reply = LLM.append(msg)
    LLM.send()
    match = re.search(r'\{.*"calc".*\}', reply) #Finds json blocks
    if match:
        expr = json.loads(match.group())["expr"]
        msg = "The calc result is: " + str(eval(expr))
    else:
        break
print(reply)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)