Dev.to AI 🤖 Ai 👁 2 📖 3 min read

Agent & LLM

Difference Between an Agent and an LLM? An LLM will answer using the knowledge it learned during training. Think of a phonebook containing names and their phone numbers. The LLM is similar to this phonebook because it

Difference Between an Agent and an LLM?

An LLM will answer using the knowledge it learned during training.

Think of a phonebook containing names and their phone numbers. The LLM is similar to this phonebook because it contains learned information that it can use to generate answers.

An LLM cannot independently execute the external tools that we create. We need an orchestrator to interact with the LLM, get the details of which tools need to be called along with their parameters, and execute those tools.

The output of the tool will be passed back to the LLM, usually as a tool result, to generate the final response or decide whether another tool needs to be called.

This orchestration process is part of an Agent.

An Agent can have memory to store the output of the first step in persistent storage and proceed with the remaining steps.

An Agent can also use a vector database to store embeddings of previous queries and their responses. This can help retrieve similar previous queries and responses when needed.

System Prompt

A system prompt is used to set boundary conditions. It defines how the output should be generated, what information or tools should be used, and what should not be used. The LLM follows these instructions and constraints when generating responses.

User Prompting

User prompting can include giving the LLM a persona and asking it to act like a particular person or role. This can be specified for a single conversation or individual request.

Why Do We Need Double Curly Braces in a Prompt?

In some prompt-template systems, curly braces {} are treated as special characters used for variable substitution. If we want to include literal curly braces in the prompt, we need to escape them using double curly braces {{}}.

E.g.

{{"steps": [{{"id": 1, "task": "...", "tool": "..."}}]}}

Chain of Thought

Chain of Thought involves breaking down a problem into intermediate reasoning steps to arrive at an answer.

Tree of Thoughts

Tree of Thoughts explores multiple possible methods of solving a problem, evaluates them, and chooses a suitable path to proceed.

E.g.

We need to travel from Chennai to Coimbatore with a budget of 2,000 rupees.

Analyze all the possible modes of travel, such as bus, train, or car. Considering the budget and other requirements, the LLM or Agent can evaluate the available options and choose a suitable mode of travel.

Agent Planning

With the given tools, ask the Agent to plan the task before executing it.

E.g.

PLANNER_PROMPT = f"""You are a planner for an AI agent.
Break the user's goal into 2-{MAX_STEPS} small, ordered steps.
Each step must use exactly ONE of these tools, or "final_answer" for the last step:
{TOOL_LIST}

Rules:
- Put lookups before calculations.
- Do not invent tools. Do not do the maths yourself.
- Return ONLY JSON in this shape:
{{"steps": [{{"id": 1, "task": "...", "tool": "..."}}]}}"""

So, Agents will provide a suggested plan according to the available tools.

Inspect the Decision

Having an LLM, tools, and a set of questions, check whether the LLM responds using a tool for a particular question if it is related to that tool, or answers using its own knowledge if no tool is required.

Plan and Execute

Plan the entire task by dividing it into steps and execute them one by one.

Reflection

For example, if a task has multiple steps, the Agent will execute the first step, review and critique its output, and then move on to the second step.

If it makes a mistake, it reviews the error and refines the result at each step before moving to the next step.

So, it follows a repeated pattern of execution, evaluation, and refinement.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.