Written By William Bowen
Last updated About 1 month ago
Intro
This doc provides an overview of what Agents is and the key components of building an agent. We start with an overview of Agents vs Knowledge Base sections in Clerk Chat.
Then dive into the specific and technical aspects of building an agent.
👉 Building an Agent is a great follow up doc to see this knowledge in action.
What is an Agent?
An agent is a series of individual AI bots (nodes) that work together to perform tasks.

What is the Knowledge Base?
The knowledge base section is AI v1.0. This was our original AI. It includes the ‘Knowledge base’ section where you upload documents the AI can search and use in its answers and a ‘AI settings’ section where you can give the AI a prompt for its task.

What is the difference between knowledge base and agents?
There is only one AI bot in the Knowledge base. This meant for agent that were a collection of tasks, e.g. answering FAQs and conversing with a user (two separate tasks), it couldn’t handle them well.
With the agents section, we can create two nodes, each of which is a separate AI bot. This means one can be tasked with answering questions, and the other can be tasked with conversing with the user. When we separate tasks like this, the performance of the AI improves.
We still use the Knowledge base section where you upload documents. Nodes from Agents can search this knowledge base to use specific data in their responses.
The AI setting section (below) is no longer in use. The Agents section replaces this.

Key components of an Agent
An agent is made up of Nodes.
What is a node?

A node is one AI bot. When this node is triggered, it takes whatever is in the prompt section, sends it to ChatGPT and the response is returned to us.
There are a few sections to each Node that are important:

Type
AI Bot: Has a prompt section. Sends whatever is in the prompt section to ChatGPT.
Knowledge Base: These nodes can search a team’s knowledge base (in the Knowledge Base section) and output the response as a message so that it can used by other nodes in the pipeline.
AI Bot Tool Runners: These nodes provide tools to the AI Bots. Each tool runner provides one or more tools (e.g searching a calendar or creating calendar event).
Name
The title of the node.
Triggered By
What triggers the node (causes it to activate/run)?
User message: Triggered by a user sending a text message to the line the agent is enabled on.
Scheduled Run: Triggered by a scheduled run (using the follow-up tool).
Unread message from any: Node will be started when any of the upstream nodes in the pipeline sends it a message. I.e. just need one upstream node to send a message to be triggered.
Unread message from all: Node will be started when all of the node upstreams nodes attached have sent it a message. i.e. in the example below, the bottom node won’t trigger until it has received a message from both upstream nodes.
Response Type
JSON Messages: The AI Bots can be instructed to return JSON.
My name is William Bowen, I work at Clerk Chat and I have brown hair.
Name: William Bowen
Company: Clerk Chat
Hair: Brown
User Messages: Regular text (natural language) that will be sent to the user over SMS.
Tip - Something I’ve noticed. If you want to send a message to another AI bot, use JSON message. It forces some structure in the agent.
If you want to send a message back to the user over SMS, use user message.
I try not to use bot message as it means there is less structure to the agent (meaning things are harder to understand and debug down the line)!
Prompt
This is where we give the AI bot its prompt. It is very good to follow a structure for ALL prompts you write. I use the following template:
Example# Role:
---
# Goal:
---
# Context:
---
# Conversation History
{{#conversationHistory}}
{{#isUser}}Client{{/isUser}}{{^isUser}}Clerk_Chat{{/isUser}}: {{content}}
{{/conversationHistory}}
---
# Instructions:
---
# Example input and output:
The ‘Conversation History’ section is a blob of JSON that takes the complete SMS conversation history and injects it into the prompt. If you copy the above prompt with the conversation history, the AI will have access to the complete conversation every time it executes which is pretty useful!
Extract Variables
Extract variables allow data to be shared between nodes. Extract variables are created when a node has a JSON Response type.

Here’s an example of a node with two extract variables. In this case, the node will execute with the prompt, ChatGPT will send a response back and the response will be mapped to these two variables.

This is what the response looked like from this node in a live example. You can see it outputs a JSON message that includes only the two extract variables specified.
Extract variables can be used in any downstream nodes in the pipeline.
An example of this is in an FAQ bot. Where the complete agent understands a user question, searches a knowledge base and returns the answer.
In this case, one bot would extract the user question in a JSON response.
This would create an extract variable user_question
.
This variable can then be passed to the bot that does a search for the answer. It can search for user_question
and return the answer.
Edges
This is where the real magic of the Agents section comes in.
Edges connect the nodes together. When a node outputs a message the pipeline runner use the node’s edges to determine which nodes should receive the message. Each edge has a ‘source’ and a ‘destination’.
Edges can do basic filtering.
Example: I have an agent that either talks to users about dogs, or cats. How do we decide if the user wants to discuss dogs or cats?
This is where edges come in.

I can use edges to choose the next node that is activated.
We use extract variables to filter on edge nodes.
In this case, the extract variable is next
In this case, if the start node outputs: next = dogs
Then the next node to be activated is the Dogs
node.
If the start node outputs: next = cats
Then the next node activated is the Cats
node.

This makes the agents section powerful as we can branch the AI bots and create more complex logic to solve a variety of tasks.
Conclusion
This is an overview of the Agents section.
Recommended reading:
Could not load article.