Build intelligent cognitive agents with AgentSpeak(L) programming and BDI reasoning architecture
SPADE BDI is a comprehensive plugin for SPADE 3+ that implements the Belief-Desire-Intention cognitive architecture, enabling agents to parse and execute AgentSpeak(L) programs with sophisticated reasoning capabilities.
Built on Bratman's BDI model, this framework creates hybrid agents that combine reactive behaviors with deliberative reasoning. Agents maintain a belief base (knowledge about the world), pursue goals (desired states), and execute plans through structured intention stacks.
from spade_bdi import BDIAgent
# Create BDI agent with AgentSpeak program
agent = BDIAgent("agent@server.com", "password", "agent_program.asl")
await agent.start()
# Dynamic belief management
agent.set_belief("location", "office")
agent.set_belief("temperature", 25)
current_location = agent.get_belief("location")
Dynamic knowledge base storing agent beliefs as predicates. Supports belief insertion, deletion, querying, and automatic updates from environmental perception and inter-agent communication.
temperature(25), location(office), weather(sunny)
Achievement goals (prefixed with !) trigger plan selection and execution. Goals represent desired states or conditions the agent commits to achieving through deliberative reasoning.
!find_shelter, !maintain_temperature(22)
Plans follow TriggeringEvent : Context <- Body syntax. Context conditions determine plan applicability through logical evaluation and variable unification.
+!cool_room : temperature(T) & T > 25 <- turn_on_ac.
Implements belief revision, goal generation, plan selection, and intention management. Processes events from message queue, selects applicable plans, and manages intention stacks for concurrent goal pursuit.
SPADE BDI implements AgentSpeak(L), a logic programming language based on the BDI model, enabling declarative specification of agent behaviors through beliefs, plans, and goals.
// Initial beliefs
temperature(22).
location(kitchen).
is_sunny(true).
// Plan structure
+!stay_cool : temperature(T) & T > 25 <-
!find_shade;
!drink_water.
Variables start with uppercase letters and support Prolog-like unification for dynamic information processing:
+temperature(Temp) : Temp > 30 <-
.print("Temperature is high: ", Temp);
!activate_cooling(Temp).
Built-in KQML performatives for inter-agent communication:
// Send beliefs and achieve goals
.send(robot1, tell, location(kitchen));
.send(coordinator, achieve, !patrol_area(zone_a));
SPADE BDI implements a complete BDI reasoning cycle with belief revision, goal generation, plan selection, and intention management for sophisticated cognitive agent behavior.
Messages from the SPADE mailbox are processed as triggering events. Events can be belief additions/deletions or goal achievements, initiating the reasoning cycle.
The agent searches the plan library for applicable plans whose trigger matches the event and whose context conditions are satisfied through belief base queries and unification.
Selected plans become intentions and are pushed onto the intention stack. Multiple intentions can be pursued concurrently through interleaved execution.
Plan bodies are executed step-by-step, performing actions, sending messages, adding/removing beliefs, and triggering new goals through recursive plan activation.
# Install and create BDI agent
pip install spade-bdi
# Agent script file (agent.asl)
!start.
+!start <- +location(home); !patrol.
+!patrol : location(home) <-
.print("Starting patrol");
!move_to(checkpoint1).
# Python integration
from spade_bdi import BDIAgent
import asyncio
async def main():
agent = BDIAgent("agent@server", "pass", "agent.asl")
await agent.start()
# Agent runs BDI reasoning cycle automatically
asyncio.run(main())