Skip to main content

Agent Dialogue Using KQML and KIF: A Warehouse Procurement Scenario

· 11 min read

Introduction

Agent-based computing is a branch of artificial intelligence in which autonomous software entities, known as agents, interact with one another to achieve goals, exchange information, and perform tasks. Unlike traditional software components, agents are typically designed to act with some degree of independence, respond to their environment, and cooperate with other agents when necessary.

This portfolio piece demonstrates a simple but realistic example of agent communication using KQML (Knowledge Query and Manipulation Language) and KIF (Knowledge Interchange Format). The dialogue is based on a warehouse procurement scenario involving two agents:

  • Alice – a procurement agent responsible for sourcing stock
  • Bob – a warehouse stock-control agent responsible for inventory information and reservations

The scenario shows Alice asking Bob about the availability of 50-inch televisions, querying how many HDMI slots those televisions have, and then requesting a stock reservation. Along the way, this article explains how KQML and KIF work, why they are useful in agent-based systems, and how the dialogue demonstrates key features of agent communication.


The Scenario

In this example, Alice is designed to support procurement decisions. Before ordering or allocating products, Alice needs to know whether the warehouse currently has stock available and whether the televisions meet a basic product requirement.

Bob is the warehouse agent that manages and exposes stock-related knowledge. Bob can:

  • report current stock levels,
  • provide product attribute information,
  • and carry out stock reservation actions.

The interaction between Alice and Bob is a useful illustration of agent-based computing because each agent has a distinct role, and both cooperate through a shared communication protocol rather than through direct hard-coded function calls.


What is KQML?

KQML stands for Knowledge Query and Manipulation Language. It is an agent communication language designed to allow software agents to exchange messages in a standard, structured way.

KQML is not primarily concerned with the internal logic of the knowledge itself. Instead, it focuses on the intention of the message. In other words, KQML helps define what one agent is trying to do when sending a message to another agent.

For example, an agent may want to:

  • ask a question,
  • provide information,
  • advertise its capabilities,
  • request that another agent perform an action,
  • or report that an action has been completed.

These communicative intentions are expressed through performatives.

Common KQML Performatives

Some of the performatives used in this example are:

  • advertise – used to declare what services or knowledge an agent can provide
  • ask-if – used to ask a yes/no question
  • ask-one – used to request a single answer
  • tell – used to provide information
  • achieve – used to request that another agent carry out an action

KQML messages also often include metadata fields such as:

  • :sender – the agent sending the message
  • :receiver – the intended recipient
  • :language – the content language used in the message
  • :ontology – the shared vocabulary or domain model
  • :reply-with – a token used to label a request
  • :in-reply-to – used to link a response to an earlier request
  • :reply-by – a deadline for a response

This structure makes agent communication more traceable, interpretable, and reusable across systems.


What is KIF?

KIF stands for Knowledge Interchange Format. It is a formal language used to represent knowledge in a structured, logical way so that different systems or agents can interpret the same information.

In this scenario, KIF is used inside the :content field of each KQML message. This means KQML defines the communicative act, while KIF expresses the actual knowledge being exchanged.

For example:

(available-stock (television (screen-size 50-inch)) 25)

This KIF expression states that the available stock of 50-inch televisions is 25.

Another example is:

(hdmi-slots (television (screen-size 50-inch)) 3)

This states that the 50-inch televisions have 3 HDMI slots.

KIF is useful because it allows agents to exchange machine-readable knowledge in a logical, structured form rather than relying on ambiguous natural language.

Note: in Lisp-style notation often used with KIF examples, a leading single quote is shorthand for quote. For example, '(available-stock ?item ?quantity) is equivalent to (quote (available-stock ?item ?quantity)).

Why Use KQML and KIF Together?

KQML and KIF complement one another:

  • KQML defines the purpose of the message
  • KIF defines the logical content of the message

This separation is useful in agent-based systems because it allows communication and knowledge representation to be handled independently.

For example, the message:

(ask-one
:sender Alice
:receiver Bob
:language KIF
:ontology warehouse-stock
:content "(available-stock (television (screen-size 50-inch)) ?quantity)")

shows that:

  • the KQML performative is ask-one, meaning Alice wants one answer,
  • the KIF content expresses what Alice wants to know,
  • and the ontology ensures both agents understand the warehouse domain in the same way.

Dialogue Walkthrough

The following dialogue demonstrates a fuller use of KQML features than a minimal question-and-answer exchange. It includes capability advertisement, factual queries, a yes/no query, an action request, and an action-result response.

Step 1: Bob Advertises His Capabilities

Before Alice begins asking questions, Bob can advertise the kinds of services he provides. This is useful in multi-agent systems because it allows agents to discover each other's capabilities dynamically.

(advertise
:sender Bob
:receiver Alice
:language KIF
:ontology warehouse-stock
:content "(and
(can-answer (quote (available-stock ?item ?quantity)))
(can-answer (quote (hdmi-slots ?item ?slots)))
(can-do (quote (reserve-stock ?item ?quantity))))")

Here, Bob is saying that he can:

  • answer stock queries,
  • answer HDMI slot queries,
  • and perform stock reservation actions

Note on capability predicates: The capability expressions do not include the agent name (e.g., Bob) because the :sender field already identifies the agent. This is the standard KQML style. However, if you wanted to embed the agent name in the predicates for extra clarity or if the expressions might be used outside the message context, you could write (can-answer Bob (quote (available-stock ...))) instead. Both forms are acceptable depending on the design intent.

Step 2: Alice Checks Whether Any 50-Inch Televisions Are Available

Alice first asks a yes/no style question using ask-if. This is appropriate because she initially wants to know whether any stock exists at all.

This KIF content asks whether there exists a quantity ?q such that the stock level is greater than zero.

(ask-if
:sender Alice
:receiver Bob
:language KIF
:ontology warehouse-stock
:reply-with stock-check-1
:content "(exists (?q)
(and
(available-stock (television (screen-size 50-inch)) ?q)
(> ?q 0)))")

Bob then replies with a tell message to indicate that the proposition is true.

(tell
:sender Bob
:receiver Alice
:language KIF
:ontology warehouse-stock
:in-reply-to stock-check-1
:content "(exists (?q)
(and
(available-stock (television (screen-size 50-inch)) ?q)
(> ?q 0)))")

The :in-reply-to field links Bob’s response back to Alice’s earlier message.

Step 3: Alice Requests the Exact Stock Quantity

After learning that stock exists, Alice now needs the precise quantity. For this, she uses ask-one.

(ask-one
:sender Alice
:receiver Bob
:language KIF
:ontology warehouse-stock
:reply-with stock-qty-1
:reply-by "2026-03-10T17:00:00"
:content "(available-stock (television (screen-size 50-inch)) ?quantity)")

This message asks Bob to return one specific value for ?quantity. The :reply-by field also introduces a deadline, which is useful in realistic procurement or logistics environments.

Bob replies with the stock quantity.

(tell
:sender Bob
:receiver Alice
:language KIF
:ontology warehouse-stock
:in-reply-to stock-qty-1
:content "(available-stock (television (screen-size 50-inch)) 25)")

This tells Alice that 25 units of 50-inch televisions are currently available.

Step 4: Alice Asks About HDMI Slots

In addition to stock level, Alice wants to know a product specification: the number of HDMI slots. She again uses ask-one.

(ask-one
:sender Alice
:receiver Bob
:language KIF
:ontology warehouse-stock
:reply-with hdmi-query-1
:content "(hdmi-slots (television (screen-size 50-inch)) ?slots)")

Bob replies with the requested information.

(tell
:sender Bob
:receiver Alice
:language KIF
:ontology warehouse-stock
:in-reply-to hdmi-query-1
:content "(hdmi-slots (television (screen-size 50-inch)) 3)")

This means the televisions have 3 HDMI slots.

Step 5: Alice Requests a Reservation

Once Alice has enough information to proceed, she requests that Bob reserve part of the available stock. This is no longer a question, so ask-one is not appropriate. Instead, Alice uses the achieve performative, which is intended to request an action.

(achieve
:sender Alice
:receiver Bob
:language KIF
:ontology warehouse-stock
:reply-with reserve-1
:content "(reserve-stock (television (screen-size 50-inch)) 10)")

This tells Bob that Alice wants 10 units of the 50-inch televisions to be reserved.

Bob then replies with a tell message reporting that the reservation has been made.

(tell
:sender Bob
:receiver Alice
:language KIF
:ontology warehouse-stock
:in-reply-to reserve-1
:content "(reserved-stock (television (screen-size 50-inch)) 10)")

This confirms that 10 televisions have been reserved.

Bob may then follow up with an updated stock message.

(tell
:sender Bob
:receiver Alice
:language KIF
:ontology warehouse-stock
:content "(available-stock (television (screen-size 50-inch)) 15)")

This indicates that 15 units remain after the reservation.

Full Demonstration

The complete dialogue is shown below in one block.

(advertise
:sender Bob
:receiver Alice
:language KIF
:ontology warehouse-stock
:content "(and
(can-answer (quote (available-stock ?item ?quantity)))
(can-answer (quote (hdmi-slots ?item ?slots)))
(can-do (quote (reserve-stock ?item ?quantity))))")

(ask-if
:sender Alice
:receiver Bob
:language KIF
:ontology warehouse-stock
:reply-with stock-check-1
:content "(exists (?q)
(and
(available-stock (television (screen-size 50-inch)) ?q)
(> ?q 0)))")

(tell
:sender Bob
:receiver Alice
:language KIF
:ontology warehouse-stock
:in-reply-to stock-check-1
:content "(exists (?q)
(and
(available-stock (television (screen-size 50-inch)) ?q)
(> ?q 0)))")

(ask-one
:sender Alice
:receiver Bob
:language KIF
:ontology warehouse-stock
:reply-with stock-qty-1
:reply-by "2026-03-10T17:00:00"
:content "(available-stock (television (screen-size 50-inch)) ?quantity)")

(tell
:sender Bob
:receiver Alice
:language KIF
:ontology warehouse-stock
:in-reply-to stock-qty-1
:content "(available-stock (television (screen-size 50-inch)) 25)")

(ask-one
:sender Alice
:receiver Bob
:language KIF
:ontology warehouse-stock
:reply-with hdmi-query-1
:content "(hdmi-slots (television (screen-size 50-inch)) ?slots)")

(tell
:sender Bob
:receiver Alice
:language KIF
:ontology warehouse-stock
:in-reply-to hdmi-query-1
:content "(hdmi-slots (television (screen-size 50-inch)) 3)")

(achieve
:sender Alice
:receiver Bob
:language KIF
:ontology warehouse-stock
:reply-with reserve-1
:content "(reserve-stock (television (screen-size 50-inch)) 10)")

(tell
:sender Bob
:receiver Alice
:language KIF
:ontology warehouse-stock
:in-reply-to reserve-1
:content "(reserved-stock (television (screen-size 50-inch)) 10)")

(tell
:sender Bob
:receiver Alice
:language KIF
:ontology warehouse-stock
:content "(available-stock (television (screen-size 50-inch)) 15)")

Discussion

This scenario demonstrates several important ideas in agent-based computing.

First, it shows how agents can be designed with distinct responsibilities. Alice focuses on procurement decisions, while Bob is responsible for warehouse knowledge and stock operations. This division of labour reflects one of the main motivations for agent-based systems: complex tasks can be distributed among specialised autonomous components.

Second, it shows the value of structured communication. Rather than exchanging unstructured text, the agents use KQML performatives and KIF expressions to communicate clearly and formally. This helps reduce ambiguity and supports interoperability between agents.

Third, the example illustrates how agent systems are grounded in artificial intelligence concepts. The agents are not simply calling functions directly; instead, they communicate through declarative messages, shared ontologies, and logical representations of knowledge. This supports reasoning, coordination, and flexible interaction.

Finally, the example also shows that agent communication involves more than asking and answering questions. Real agent interaction may involve discovering services, checking truth conditions, retrieving exact values, requesting actions, and reporting task completion. The use of advertise, ask-if, ask-one, tell, and achieve helps demonstrate this broader communicative model.

Note on KQML Extensibility

KQML is often described as extensible. In practice, this means a community of agents can define additional performatives if they agree on the exact meaning, expected message fields, and interaction protocol.

So a performative such as confirm is not automatically illegal. However, it is not part of the commonly cited standard KQML performative set unless you explicitly document it as an extension and ensure participating agents interpret it consistently.

Conclusion

This portfolio piece has presented a warehouse procurement dialogue between two agents, Alice and Bob, using KQML and KIF. The example has shown how KQML can be used to structure communicative acts such as asking questions, providing answers, requesting actions, and reporting outcomes. It has also shown how KIF can represent the underlying domain knowledge in a formal, machine-readable way.

Overall, the scenario demonstrates the practical value of agent-based computing in a setting where autonomous entities need to cooperate, exchange information, and perform tasks in a structured and intelligent manner.